Files
mstore/app/server/server_test.go
T
2026-01-30 13:40:42 +02:00

57 lines
891 B
Go

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)
}
}