config: delegate Sigv4 validation to the inner type
This change also adds unit tests for SNS configuration. Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
parent
ef25f81f1b
commit
cd57dee6cd
|
@ -623,8 +623,5 @@ func (c *SNSConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||
if (c.TargetARN == "") != (c.TopicARN == "") != (c.PhoneNumber == "") {
|
||||
return fmt.Errorf("must provide either a Target ARN, Topic ARN, or Phone Number for SNS config")
|
||||
}
|
||||
if (c.Sigv4.AccessKey == "") != (c.Sigv4.SecretKey == "") {
|
||||
return fmt.Errorf("must provide a AWS SigV4 Access key and Secret Key if credentials are specified in the SNS config")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -590,6 +590,92 @@ func TestOpsgenieTypeMatcher(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSNS(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
in string
|
||||
err bool
|
||||
}{
|
||||
{
|
||||
// Valid configuration without sigv4.
|
||||
in: `target_arn: target`,
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
// Valid configuration without sigv4.
|
||||
in: `topic_arn: topic`,
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
// Valid configuration with sigv4.
|
||||
in: `phone_number: phone
|
||||
sigv4:
|
||||
access_key: abc
|
||||
secret_key: abc
|
||||
`,
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
// at most one of 'target_arn', 'topic_arn' or 'phone_number' must be provided without sigv4.
|
||||
in: `topic_arn: topic
|
||||
target_arn: target
|
||||
`,
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
// at most one of 'target_arn', 'topic_arn' or 'phone_number' must be provided without sigv4.
|
||||
in: `topic_arn: topic
|
||||
phone_number: phone
|
||||
`,
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
// one of 'target_arn', 'topic_arn' or 'phone_number' must be provided without sigv4.
|
||||
in: "{}",
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
// one of 'target_arn', 'topic_arn' or 'phone_number' must be provided with sigv4.
|
||||
in: `sigv4:
|
||||
access_key: abc
|
||||
secret_key: abc
|
||||
`,
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
// 'secret_key' must be provided with 'access_key'.
|
||||
in: `topic_arn: topic
|
||||
sigv4:
|
||||
access_key: abc
|
||||
`,
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
// 'access_key' must be provided with 'secret_key'.
|
||||
in: `topic_arn: topic
|
||||
sigv4:
|
||||
secret_key: abc
|
||||
`,
|
||||
err: true,
|
||||
},
|
||||
} {
|
||||
t.Run("", func(t *testing.T) {
|
||||
var cfg SNSConfig
|
||||
err := yaml.UnmarshalStrict([]byte(tc.in), &cfg)
|
||||
if err != nil {
|
||||
if !tc.err {
|
||||
t.Errorf("expecting no error, got %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if tc.err {
|
||||
t.Logf("%#v", cfg)
|
||||
t.Error("expecting error, got none")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWeChatTypeMatcher(t *testing.T) {
|
||||
good := []string{"text", "markdown"}
|
||||
for _, g := range good {
|
||||
|
|
Loading…
Reference in New Issue