Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
Signed-off-by: WashingtonKK <[email protected]>
  • Loading branch information
WashingtonKK committed Dec 3, 2024
1 parent 5174755 commit b7512da
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions internal/server/grpc/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down

0 comments on commit b7512da

Please sign in to comment.