Skip to content

Commit

Permalink
Update main_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein committed Mar 7, 2024
1 parent c514b98 commit 6cd7aa2
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down

0 comments on commit 6cd7aa2

Please sign in to comment.