Settings: Add tests for handleAWSConfig (#71486)

This commit is contained in:
Ida Štambuk 2023-07-14 13:04:12 +02:00 committed by GitHub
parent 1caf3298ea
commit 391f574069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -809,3 +809,78 @@ func TestRedactedValue(t *testing.T) {
})
}
}
func TestHandleAWSSettings(t *testing.T) {
t.Run("Should set default auth providers if not defined", func(t *testing.T) {
cfg := NewCfg()
awsSection, err := cfg.Raw.NewSection("aws")
require.NoError(t, err)
_, err = awsSection.NewKey("allowed_auth_providers", "")
require.NoError(t, err)
cfg.handleAWSConfig()
assert.Equal(t, []string{"default", "keys", "credentials"}, cfg.AWSAllowedAuthProviders)
})
t.Run("Should pass on auth providers defined in config", func(t *testing.T) {
cfg := NewCfg()
awsSection, err := cfg.Raw.NewSection("aws")
require.NoError(t, err)
_, err = awsSection.NewKey("allowed_auth_providers", "keys, credentials")
require.NoError(t, err)
cfg.handleAWSConfig()
assert.Equal(t, []string{"keys", "credentials"}, cfg.AWSAllowedAuthProviders)
})
t.Run("Should set assume role to true if not defined", func(t *testing.T) {
cfg := NewCfg()
awsSection, err := cfg.Raw.NewSection("aws")
require.NoError(t, err)
_, err = awsSection.NewKey("assume_role_enabled", "")
require.NoError(t, err)
cfg.handleAWSConfig()
assert.Equal(t, true, cfg.AWSAssumeRoleEnabled)
})
t.Run("Should set assume role to true if defined as true in the config", func(t *testing.T) {
cfg := NewCfg()
awsSection, err := cfg.Raw.NewSection("aws")
require.NoError(t, err)
_, err = awsSection.NewKey("assume_role_enabled", "true")
require.NoError(t, err)
cfg.handleAWSConfig()
assert.Equal(t, true, cfg.AWSAssumeRoleEnabled)
})
t.Run("Should set assume role to false if defined as false in the config", func(t *testing.T) {
cfg := NewCfg()
awsSection, err := cfg.Raw.NewSection("aws")
require.NoError(t, err)
_, err = awsSection.NewKey("assume_role_enabled", "false")
require.NoError(t, err)
cfg.handleAWSConfig()
assert.Equal(t, false, cfg.AWSAssumeRoleEnabled)
})
t.Run("Should set default page limit if not defined", func(t *testing.T) {
cfg := NewCfg()
awsSection, err := cfg.Raw.NewSection("aws")
require.NoError(t, err)
_, err = awsSection.NewKey("list_metrics_page_limit", "")
require.NoError(t, err)
cfg.handleAWSConfig()
assert.Equal(t, 500, cfg.AWSListMetricsPageLimit)
})
t.Run("Should pass on the limit if it is defined in the config", func(t *testing.T) {
cfg := NewCfg()
awsSection, err := cfg.Raw.NewSection("aws")
require.NoError(t, err)
_, err = awsSection.NewKey("list_metrics_page_limit", "400")
require.NoError(t, err)
cfg.handleAWSConfig()
assert.Equal(t, 400, cfg.AWSListMetricsPageLimit)
})
}