sso/tests/suite/suite.go

55 lines
1010 B
Go
Raw Normal View History

2023-12-17 12:17:55 +02:00
package suite
import (
"context"
"net"
"sso/internal/config"
"strconv"
"testing"
2023-12-17 12:37:57 +02:00
ssov1 "gitea.computernetthings.ru/yash/protos/gen/sso"
2023-12-17 12:17:55 +02:00
"google.golang.org/grpc"
)
type Suite struct {
*testing.T
Cfg *config.Config
AuthClient ssov1.AuthClient
}
const (
grpcHost = "localhost"
)
func New(t *testing.T) (context.Context, *Suite) {
t.Helper()
t.Parallel()
cfg := config.MustLoadByPath("../config/local.yaml")
ctx, cancelCtx := context.WithTimeout(context.Background(), cfg.GRPC.Timeout)
t.Cleanup(func() {
t.Helper()
cancelCtx()
})
cc, err := grpc.DialContext(context.Background(), grpcAddress(cfg),
// grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithInsecure(),
)
if err != nil {
t.Fatalf("grpc server connection failed: %v", err)
}
return ctx, &Suite{
T: t,
Cfg: cfg,
AuthClient: ssov1.NewAuthClient(cc),
}
}
func grpcAddress(cfg *config.Config) string {
return net.JoinHostPort(grpcHost, strconv.Itoa(cfg.GRPC.Port))
}