forked from raystack/guardian
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notifiers): support multiple slack workspaces
- changes to configure multiple slack workspaces and corresponding bot tokens - slack notifier will use email (other user attributes are difficult since for approvers we wouldn't have any additional details) for evaluating configured criteria and send notifications to corresponding slack workspace - additional test cases - maintains backward compatibility
- Loading branch information
Showing
6 changed files
with
308 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package notifiers | ||
|
||
import ( | ||
"github.com/goto/guardian/plugins/notifiers/slack" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestNewSlackConfig(t *testing.T) { | ||
type args struct { | ||
config *Config | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *slack.Config | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "should return error when no access token or workspaces are provided", | ||
args: args{ | ||
config: &Config{ | ||
Provider: ProviderTypeSlack, | ||
}, | ||
}, | ||
want: nil, | ||
wantErr: true, | ||
}, { | ||
name: "should return error when both access token and workspaces are provided", | ||
args: args{ | ||
config: &Config{ | ||
Provider: ProviderTypeSlack, | ||
AccessToken: "foo", | ||
Workspaces: []slack.SlackWorkspace{ | ||
{ | ||
WorkspaceName: "default", | ||
AccessToken: "bar", | ||
Criteria: "1==1", | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: nil, | ||
wantErr: true, | ||
}, { | ||
name: "should return slack config when access token is provided", | ||
args: args{ | ||
config: &Config{ | ||
Provider: ProviderTypeSlack, | ||
AccessToken: "foo", | ||
}, | ||
}, | ||
want: &slack.Config{ | ||
Workspaces: []slack.SlackWorkspace{ | ||
{ | ||
WorkspaceName: "default", | ||
AccessToken: "foo", | ||
Criteria: "1==1", | ||
}, | ||
}, | ||
}, | ||
wantErr: false, | ||
}, { | ||
name: "should return slack config when workspaces are provided", | ||
args: args{ | ||
config: &Config{ | ||
Provider: ProviderTypeSlack, | ||
Workspaces: []slack.SlackWorkspace{ | ||
{ | ||
WorkspaceName: "A", | ||
AccessToken: "foo", | ||
Criteria: "$email contains '@abc'", | ||
}, | ||
{ | ||
WorkspaceName: "B", | ||
AccessToken: "bar", | ||
Criteria: "$email contains '@xyz'", | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: &slack.Config{ | ||
Workspaces: []slack.SlackWorkspace{ | ||
{ | ||
WorkspaceName: "A", | ||
AccessToken: "foo", | ||
Criteria: "$email contains '@abc'", | ||
}, | ||
{ | ||
WorkspaceName: "B", | ||
AccessToken: "bar", | ||
Criteria: "$email contains '@xyz'", | ||
}, | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := NewSlackConfig(tt.args.config) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("NewSlackConfig() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("NewSlackConfig() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.