Skip to content

Commit

Permalink
refactor: make slackIDCache private to slack client
Browse files Browse the repository at this point in the history
  • Loading branch information
bsushmith committed Mar 7, 2023
1 parent 8907769 commit c997dba
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
3 changes: 1 addition & 2 deletions plugins/notifiers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ func NewClient(config *Config) (Client, error) {
Messages: config.Messages,
}
httpClient := &http.Client{Timeout: 10 * time.Second}
slackIDCache := map[string]string{}
return slack.NewNotifier(slackConfig, slackIDCache, httpClient), nil
return slack.NewNotifier(slackConfig, httpClient), nil
}

return nil, errors.New("invalid notifier provider type")
Expand Down
4 changes: 2 additions & 2 deletions plugins/notifiers/slack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ type Config struct {
//go:embed templates/*
var defaultTemplates embed.FS

func NewNotifier(config *Config, slackIDCache map[string]string, httpClient utils.HTTPClient) *Notifier {
func NewNotifier(config *Config, httpClient utils.HTTPClient) *Notifier {
return &Notifier{
accessToken: config.AccessToken,
slackIDCache: slackIDCache,
slackIDCache: map[string]string{},
Messages: config.Messages,
httpClient: httpClient,
defaultMessageFiles: defaultTemplates,
Expand Down
4 changes: 1 addition & 3 deletions plugins/notifiers/slack/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type ClientTestSuite struct {
mockHttpClient *mocks.HTTPClient
accessToken string
messages domain.NotificationMessages
slackIDCache map[string]string
notifier *slack.Notifier
}

Expand All @@ -29,14 +28,13 @@ func (s *ClientTestSuite) setup() {
s.messages = domain.NotificationMessages{
AppealRejected: "[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"Your appeal to {{.resource_name}} with role {{.role}} has been rejected\"}}]",
}
s.slackIDCache = map[string]string{}

conf := &slack.Config{
AccessToken: s.accessToken,
Messages: s.messages,
}

s.notifier = slack.NewNotifier(conf, s.slackIDCache, s.mockHttpClient)
s.notifier = slack.NewNotifier(conf, s.mockHttpClient)
}

func (s *ClientTestSuite) TestNotify() {
Expand Down

0 comments on commit c997dba

Please sign in to comment.