From 6cd7aa2e67a4716168274cb4941cdc50fe3d9b08 Mon Sep 17 00:00:00 2001 From: Peter Csajtai Date: Thu, 7 Mar 2024 16:05:06 +0100 Subject: [PATCH] Update main_test.go --- main_test.go | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 53e7cb7..90ddeda 100644 --- a/main_test.go +++ b/main_test.go @@ -68,7 +68,7 @@ func TestAppMain_Invalid_Config_YAML(t *testing.T) { assert.Equal(t, 1, exitCode) } -func TestAppMain_ErrorChannel(t *testing.T) { +func TestAppMain_Invalid_TLS_Cert(t *testing.T) { resetFlags() t.Setenv("CONFIGCAT_SDKS", `{"sdk1":"XxPbCKmzIUGORk4vsufpzw/iC_KABprDEueeQs3yovVnQ"}`) t.Setenv("CONFIGCAT_TLS_ENABLED", "true") @@ -88,6 +88,44 @@ func TestAppMain_ErrorChannel(t *testing.T) { assert.Equal(t, 1, exitCode) } +func TestAppMain_ErrorChan_Diag_Conflicting_Ports(t *testing.T) { + resetFlags() + t.Setenv("CONFIGCAT_SDKS", `{"sdk1":"XxPbCKmzIUGORk4vsufpzw/iC_KABprDEueeQs3yovVnQ"}`) + t.Setenv("CONFIGCAT_DIAG_PORT", "8050") + var exitCode int + closeSignal := make(chan os.Signal, 1) + wg := sync.WaitGroup{} + wg.Add(1) + go func() { + exitCode = run(closeSignal) + wg.Done() + }() + time.Sleep(1 * time.Second) + closeSignal <- syscall.SIGTERM + wg.Wait() + + assert.Equal(t, 1, exitCode) +} + +func TestAppMain_ErrorChan_Grpc_Conflicting_Ports(t *testing.T) { + resetFlags() + t.Setenv("CONFIGCAT_SDKS", `{"sdk1":"XxPbCKmzIUGORk4vsufpzw/iC_KABprDEueeQs3yovVnQ"}`) + t.Setenv("CONFIGCAT_GRPC_PORT", "8051") + var exitCode int + closeSignal := make(chan os.Signal, 1) + wg := sync.WaitGroup{} + wg.Add(1) + go func() { + exitCode = run(closeSignal) + wg.Done() + }() + time.Sleep(1 * time.Second) + closeSignal <- syscall.SIGTERM + wg.Wait() + + assert.Equal(t, 1, exitCode) +} + func resetFlags() { flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError) flag.CommandLine.SetOutput(io.Discard)