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): add backward compatibility for slack notifier changes
- Loading branch information
Showing
3 changed files
with
152 additions
and
5 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
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) | ||
} | ||
}) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -60,7 +60,6 @@ func (s *ClientTestSuite) TestNotify() { | |
s.mockHttpClient.On("Do", mock.Anything).Return(resp, nil) | ||
expectedErrs := []error{ | ||
fmt.Errorf("[appeal_id=test-appeal-id] | %w", errors.New("error finding slack id for email [email protected] in workspace: ws-1 - users_not_found")), | ||
fmt.Errorf("[appeal_id=test-appeal-id] | error sending message to user:[email protected] in workspace: | %w", errors.New("EOF")), | ||
} | ||
|
||
notifications := []domain.Notification{ | ||
|