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 187e4b6 commit dc7be1d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"flag"
"github.com/stretchr/testify/assert"
"io"
"os"
"sync"
"syscall"
Expand All @@ -10,6 +12,7 @@ import (
)

func TestAppMain(t *testing.T) {
resetFlags()
t.Setenv("CONFIGCAT_SDKS", `{"sdk1":"XxPbCKmzIUGORk4vsufpzw/iC_KABprDEueeQs3yovVnQ"}`)

var exitCode int
Expand All @@ -28,6 +31,7 @@ func TestAppMain(t *testing.T) {
}

func TestAppMain_Invalid_Conf(t *testing.T) {
resetFlags()
var exitCode int
closeSignal := make(chan os.Signal, 1)
wg := sync.WaitGroup{}
Expand All @@ -44,6 +48,7 @@ func TestAppMain_Invalid_Conf(t *testing.T) {
}

func TestAppMain_Invalid_Config_YAML(t *testing.T) {
resetFlags()
oldArgs := os.Args
defer func() { os.Args = oldArgs }()
os.Args = []string{"app", "-c=/tmp/non-existing.yml"}
Expand All @@ -64,6 +69,7 @@ func TestAppMain_Invalid_Config_YAML(t *testing.T) {
}

func TestAppMain_ErrorChannel(t *testing.T) {
resetFlags()
t.Setenv("CONFIGCAT_SDKS", `{"sdk1":"XxPbCKmzIUGORk4vsufpzw/iC_KABprDEueeQs3yovVnQ"}`)
t.Setenv("CONFIGCAT_TLS_ENABLED", "true")
t.Setenv("CONFIGCAT_TLS_CERTIFICATES", `[{"key":"./key","cert":"./cert"}]`)
Expand All @@ -81,3 +87,8 @@ func TestAppMain_ErrorChannel(t *testing.T) {

assert.Equal(t, 1, exitCode)
}

func resetFlags() {
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
flag.CommandLine.SetOutput(io.Discard)
}

0 comments on commit dc7be1d

Please sign in to comment.