diff --git a/app/server/server_test.go b/app/server/server_test.go index dd738cc..4aa920e 100644 --- a/app/server/server_test.go +++ b/app/server/server_test.go @@ -2,6 +2,9 @@ package server import ( "context" + "fmt" + "os" + "path/filepath" "sync" "testing" "time" @@ -12,12 +15,21 @@ import ( ) func TestService(t *testing.T) { + var srvport int64 = 10250 + srvdir := t.TempDir() + srvaddr := fmt.Sprintf("127.0.0.1:%d", srvport) + srv, err := NewServer() require.NoError(t, err) { err = srv.Configure() require.NoError(t, err) + srv.SetDatadir(srvdir) + srv.SetLogdir(srvdir) + srv.SetRundir(srvdir) + srv.SetPort(srvport) + err = srv.Build() require.NoError(t, err) @@ -42,15 +54,31 @@ func TestService(t *testing.T) { go startFunc() time.Sleep(1 * time.Second) } - { + fmt.Printf("=== ServiceHello ===\n") cli := client.NewClient() - ctx := context.Background() ctx, _ = context.WithTimeout(ctx, 1*time.Second) - helloRes, err := cli.ServiceHello(ctx, "127.0.0.1:1025/hello") + helloRes, err := cli.ServiceHello(ctx, srvaddr+"/hello") require.NoError(t, err) require.True(t, helloRes) } + { + tmpdir := t.TempDir() + tmpfile := filepath.Join(tmpdir, "foo.bin") + + filedata := make([]byte, 16) + err := os.WriteFile(tmpfile, filedata, 0666) + require.NoError(t, err) + + fmt.Printf("=== PutFile ===\n") + cli := client.NewClient() + ctx := context.Background() + ctx, _ = context.WithTimeout(ctx, 1*time.Second) + + err = cli.PutFile(ctx, tmpfile, srvaddr+"/foo.bin") + require.NoError(t, err) + + } }