mirror of
https://github.com/grafana/grafana.git
synced 2025-01-17 12:03:26 -06:00
Settings: Add tests for handleAWSConfig (#71486)
This commit is contained in:
parent
1caf3298ea
commit
391f574069
@ -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)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user