Skip to content

Commit

Permalink
Add test for refreshInterval of updateConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Achooo committed Aug 2, 2023
1 parent d3ff4fd commit 0fa2160
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions agent/hcp/telemetry_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ func TestNewTelemetryConfigProvider(t *testing.T) {

func TestTelemetryConfigProviderGetUpdate(t *testing.T) {
for name, tc := range map[string]struct {
mockExpect func(*client.MockClient)
metricKey string
optsInputs *testConfig
expected *testConfig
mockExpect func(*client.MockClient)
metricKey string
optsInputs *testConfig
expected *testConfig
expectedInterval time.Duration
}{
"noChanges": {
optsInputs: &testConfig{
Expand Down Expand Up @@ -131,7 +132,8 @@ func TestTelemetryConfigProviderGetUpdate(t *testing.T) {
filters: "test",
refreshInterval: testRefreshInterval,
},
metricKey: testMetricKeySuccess,
metricKey: testMetricKeySuccess,
expectedInterval: testRefreshInterval,
},
"newConfig": {
optsInputs: &testConfig{
Expand Down Expand Up @@ -161,7 +163,8 @@ func TestTelemetryConfigProviderGetUpdate(t *testing.T) {
},
refreshInterval: 2 * time.Second,
},
metricKey: testMetricKeySuccess,
expectedInterval: 2 * time.Second,
metricKey: testMetricKeySuccess,
},
"newConfigMetricsDisabled": {
optsInputs: &testConfig{
Expand Down Expand Up @@ -192,7 +195,8 @@ func TestTelemetryConfigProviderGetUpdate(t *testing.T) {
refreshInterval: 2 * time.Second,
disabled: true,
},
metricKey: testMetricKeySuccess,
metricKey: testMetricKeySuccess,
expectedInterval: 2 * time.Second,
},
"sameConfigInvalidRefreshInterval": {
optsInputs: &testConfig{
Expand All @@ -217,7 +221,8 @@ func TestTelemetryConfigProviderGetUpdate(t *testing.T) {
filters: "test",
refreshInterval: testRefreshInterval,
},
metricKey: testMetricKeyFailure,
metricKey: testMetricKeyFailure,
expectedInterval: 0,
},
"sameConfigHCPClientFailure": {
optsInputs: &testConfig{
Expand All @@ -239,7 +244,8 @@ func TestTelemetryConfigProviderGetUpdate(t *testing.T) {
},
refreshInterval: testRefreshInterval,
},
metricKey: testMetricKeyFailure,
metricKey: testMetricKeyFailure,
expectedInterval: 0,
},
} {
tc := tc
Expand All @@ -256,7 +262,8 @@ func TestTelemetryConfigProviderGetUpdate(t *testing.T) {
cfg: dynamicCfg,
}

provider.updateConfig(context.Background())
newInterval := provider.updateConfig(context.Background())
require.Equal(t, tc.expectedInterval, newInterval)

// Verify endpoint provider returns correct config values.
expectedCfg, err := testDynamicCfg(tc.expected)
Expand Down

0 comments on commit 0fa2160

Please sign in to comment.