From b7512dae08625f3c7bc4bcb13f177d668c9e441c Mon Sep 17 00:00:00 2001 From: WashingtonKK Date: Tue, 3 Dec 2024 14:07:19 +0300 Subject: [PATCH] add test case Signed-off-by: WashingtonKK --- internal/server/grpc/grpc_test.go | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/internal/server/grpc/grpc_test.go b/internal/server/grpc/grpc_test.go index 85e91685..d4f2ee26 100644 --- a/internal/server/grpc/grpc_test.go +++ b/internal/server/grpc/grpc_test.go @@ -135,6 +135,47 @@ func TestServerStartWithTLS(t *testing.T) { assert.Contains(t, logContent, "TestServer service gRPC server listening at localhost:0 with TLS") } +func TestFailedServerStartWithTLS(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + + cert, key, err := generateSelfSignedCert() + assert.NoError(t, err) + + config := server.AgentConfig{ + ServerConfig: server.ServerConfig{ + BaseConfig: server.BaseConfig{ + Host: "localhost", + Port: "0", + CertFile: string(cert), + KeyFile: string(key), + ServerCAFile: string(cert), + }, + }, + } + + logBuffer := &ThreadSafeBuffer{} + logger := slog.New(slog.NewTextHandler(logBuffer, &slog.HandlerOptions{Level: slog.LevelDebug})) + qp := new(mocks.QuoteProvider) + authSvc := new(authmocks.Authenticator) + + srv := New(ctx, cancel, "TestServer", config, func(srv *grpc.Server) {}, logger, qp, authSvc) + + var wg sync.WaitGroup + wg.Add(1) + + go func() { + wg.Done() + err := srv.Start() + assert.Error(t, err) + }() + + wg.Wait() + + time.Sleep(200 * time.Millisecond) + + cancel() +} + func TestServerStartWithAttestedTLS(t *testing.T) { ctx, cancel := context.WithCancel(context.Background())