package server import ( "context" "sync" "testing" "time" "mstore/pkg/client" "github.com/stretchr/testify/require" ) func TestService(t *testing.T) { srv, err := NewServer() require.NoError(t, err) { err = srv.Configure() require.NoError(t, err) err = srv.Build() require.NoError(t, err) var svcWG sync.WaitGroup errPipe := make(chan error, 5) startFunc := func() { err := srv.svc.Run() errPipe <- err svcWG.Done() } stopFunc := func() { srv.svc.Stop() svcWG.Wait() err = <-errPipe require.NoError(t, err) } defer stopFunc() svcWG.Add(1) go startFunc() time.Sleep(1 * time.Second) } { cli := client.NewClient() ctx := context.Background() ctx, _ = context.WithTimeout(ctx, 1*time.Second) helloRes, err := cli.ServiceHello(ctx, "127.0.0.1:1025/hello") require.NoError(t, err) require.True(t, helloRes) } }