diff --git a/client/cmd/login_test.go b/client/cmd/login_test.go index 8e945f00a..046a7c531 100644 --- a/client/cmd/login_test.go +++ b/client/cmd/login_test.go @@ -2,35 +2,17 @@ package cmd import ( "fmt" - "path/filepath" "strings" "testing" "github.com/wiretrustee/wiretrustee/client/internal" "github.com/wiretrustee/wiretrustee/iface" - mgmt "github.com/wiretrustee/wiretrustee/management/server" "github.com/wiretrustee/wiretrustee/util" ) -var mgmAddr string - -func TestLogin_Start(t *testing.T) { - config := &mgmt.Config{} - _, err := util.ReadJson("../testdata/management.json", config) - if err != nil { - t.Fatal(err) - } - testDir := t.TempDir() - config.Datadir = testDir - err = util.CopyFileContents("../testdata/store.json", filepath.Join(testDir, "store.json")) - if err != nil { - t.Fatal(err) - } - _, listener := startManagement(t, config) - mgmAddr = listener.Addr().String() -} - func TestLogin(t *testing.T) { + mgmAddr := startTestingServices(t) + tempDir := t.TempDir() confPath := tempDir + "/config.json" mgmtURL := fmt.Sprintf("http://%s", mgmAddr) diff --git a/client/cmd/testutil.go b/client/cmd/testutil.go index 03db8fec5..22df9f789 100644 --- a/client/cmd/testutil.go +++ b/client/cmd/testutil.go @@ -2,7 +2,9 @@ package cmd import ( "context" + "github.com/wiretrustee/wiretrustee/util" "net" + "path/filepath" "testing" "time" @@ -15,6 +17,28 @@ import ( "google.golang.org/grpc" ) +func startTestingServices(t *testing.T) string { + config := &mgmt.Config{} + _, err := util.ReadJson("../testdata/management.json", config) + if err != nil { + t.Fatal(err) + } + testDir := t.TempDir() + config.Datadir = testDir + err = util.CopyFileContents("../testdata/store.json", filepath.Join(testDir, "store.json")) + if err != nil { + t.Fatal(err) + } + + _, signalLis := startSignal(t) + signalAddr := signalLis.Addr().String() + config.Signal.URI = signalAddr + + _, mgmLis := startManagement(t, config) + mgmAddr := mgmLis.Addr().String() + return mgmAddr +} + func startSignal(t *testing.T) (*grpc.Server, net.Listener) { lis, err := net.Listen("tcp", ":0") if err != nil { diff --git a/client/cmd/up_daemon_test.go b/client/cmd/up_daemon_test.go index f597660ed..8c79d44d8 100644 --- a/client/cmd/up_daemon_test.go +++ b/client/cmd/up_daemon_test.go @@ -2,37 +2,15 @@ package cmd import ( "context" - "path/filepath" "testing" "time" "github.com/wiretrustee/wiretrustee/client/internal" - mgmt "github.com/wiretrustee/wiretrustee/management/server" - "github.com/wiretrustee/wiretrustee/util" ) -func TestUpDaemon_Start(t *testing.T) { - config := &mgmt.Config{} - _, err := util.ReadJson("../testdata/management.json", config) - if err != nil { - t.Fatal(err) - } - testDir := t.TempDir() - config.Datadir = testDir - err = util.CopyFileContents("../testdata/store.json", filepath.Join(testDir, "store.json")) - if err != nil { - t.Fatal(err) - } - - _, signalLis := startSignal(t) - signalAddr = signalLis.Addr().String() - config.Signal.URI = signalAddr - - _, mgmLis := startManagement(t, config) - mgmAddr = mgmLis.Addr().String() -} - func TestUpDaemon(t *testing.T) { + mgmAddr := startTestingServices(t) + tempDir := t.TempDir() confPath := tempDir + "/config.json" diff --git a/client/cmd/up_test.go b/client/cmd/up_test.go index 9148b7996..292013751 100644 --- a/client/cmd/up_test.go +++ b/client/cmd/up_test.go @@ -2,42 +2,20 @@ package cmd import ( "net/url" - "path/filepath" "testing" "time" "github.com/wiretrustee/wiretrustee/iface" - mgmt "github.com/wiretrustee/wiretrustee/management/server" - "github.com/wiretrustee/wiretrustee/util" ) var ( - signalAddr string - cliAddr string + //signalAddr string + cliAddr string ) -func TestUp_Start(t *testing.T) { - config := &mgmt.Config{} - _, err := util.ReadJson("../testdata/management.json", config) - if err != nil { - t.Fatal(err) - } - testDir := t.TempDir() - config.Datadir = testDir - err = util.CopyFileContents("../testdata/store.json", filepath.Join(testDir, "store.json")) - if err != nil { - t.Fatal(err) - } - - _, signalLis := startSignal(t) - signalAddr = signalLis.Addr().String() - config.Signal.URI = signalAddr - - _, mgmLis := startManagement(t, config) - mgmAddr = mgmLis.Addr().String() -} - func TestUp(t *testing.T) { + mgmAddr := startTestingServices(t) + tempDir := t.TempDir() confPath := tempDir + "/config.json" mgmtURL, err := url.Parse("http://" + mgmAddr) @@ -66,7 +44,7 @@ func TestUp(t *testing.T) { }() time.Sleep(time.Second * 2) - timeout := 15 * time.Second + timeout := 30 * time.Second timeoutChannel := time.After(timeout) for { select {