Skip to content

Commit

Permalink
refactor: test empty config scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
lvlcn-t committed Mar 12, 2024
1 parent acd769a commit a39f6b9
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions pkg/config/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,10 @@ func TestHttpLoader_Run_config_sent_to_channel(t *testing.T) {
hl.Shutdown(ctx)
}

// TestHttpLoader_Run_config_not_sent_to_channel_500 tests if the config is not sent to the channel
// TestHttpLoader_Run_empty_config_sent_to_channel_500 tests if the config is not sent to the channel
// when the Run method is called
// and the remote endpoint returns a non-200 response
func TestHttpLoader_Run_config_not_sent_to_channel_500(t *testing.T) {
func TestHttpLoader_Run_empty_config_sent_to_channel_500(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()

Expand Down Expand Up @@ -384,22 +384,18 @@ func TestHttpLoader_Run_config_not_sent_to_channel_500(t *testing.T) {
}
}()

// check if the config is sent to the channel
select {
// make sure you wait for at least an interval
case <-time.After(time.Second):
t.Log("Config not sent to channel")
case c := <-cRuntime:
t.Errorf("Config sent to channel: %v", c)
cfg := <-cRuntime
if cfg != (runtime.Config{}) {
t.Errorf("Config sent to channel: %v", cfg)
}

hl.Shutdown(ctx)
}

// TestHttpLoader_Run_config_not_sent_to_channel_client_error tests if the config is not sent to the channel
// TestHttpLoader_Run_empty_config_sent_to_channel_client_error tests if the config is not sent to the channel
// when the Run method is called
// and the client can't execute the requests
func TestHttpLoader_Run_config_not_sent_to_channel_client_error(t *testing.T) {
func TestHttpLoader_Run_empty_config_sent_to_channel_client_error(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()

Expand Down Expand Up @@ -435,13 +431,9 @@ func TestHttpLoader_Run_config_not_sent_to_channel_client_error(t *testing.T) {
}
}()

// check if the config is sent to the channel
select {
// make sure you wait for at least an interval
case <-time.After(time.Second):
t.Log("Config not sent to channel")
case c := <-cRuntime:
t.Errorf("Config sent to channel: %v", c)
cfg := <-cRuntime
if cfg != (runtime.Config{}) {
t.Errorf("Config sent to channel: %v", cfg)
}

hl.Shutdown(ctx)
Expand Down

0 comments on commit a39f6b9

Please sign in to comment.