-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and mock slack.go, fix reviewed changes
- Loading branch information
1 parent
ed1d8cd
commit 4e57157
Showing
7 changed files
with
355 additions
and
80 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,151 @@ | ||
// Automatically generated by pegomock. DO NOT EDIT! | ||
// Source: slack.go | ||
|
||
package mocks | ||
|
||
import ( | ||
"reflect" | ||
|
||
pegomock "github.com/petergtz/pegomock" | ||
) | ||
|
||
type MockSlackClient struct { | ||
fail func(message string, callerSkip ...int) | ||
} | ||
|
||
func NewMockSlackClient() *MockSlackClient { | ||
return &MockSlackClient{fail: pegomock.GlobalFailHandler} | ||
} | ||
|
||
func (mock *MockSlackClient) AuthTest() error { | ||
params := []pegomock.Param{} | ||
result := pegomock.GetGenericMockFrom(mock).Invoke("AuthTest", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) | ||
var ret0 error | ||
if len(result) != 0 { | ||
if result[0] != nil { | ||
ret0 = result[0].(error) | ||
} | ||
} | ||
return ret0 | ||
} | ||
|
||
func (mock *MockSlackClient) ChannelExist(channelName string) (bool, error) { | ||
params := []pegomock.Param{channelName} | ||
result := pegomock.GetGenericMockFrom(mock).Invoke("ChannelExist", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) | ||
var ret0 bool | ||
var ret1 error | ||
if len(result) != 0 { | ||
if result[0] != nil { | ||
ret0 = result[0].(bool) | ||
} | ||
if result[1] != nil { | ||
ret1 = result[1].(error) | ||
} | ||
} | ||
return ret0, ret1 | ||
} | ||
|
||
func (mock *MockSlackClient) PostMessage(channel string, result ApplyResult) error { | ||
params := []pegomock.Param{channel, result} | ||
result := pegomock.GetGenericMockFrom(mock).Invoke("PostMessage", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) | ||
var ret0 error | ||
if len(result) != 0 { | ||
if result[0] != nil { | ||
ret0 = result[0].(error) | ||
} | ||
} | ||
return ret0 | ||
} | ||
|
||
func (mock *MockSlackClient) VerifyWasCalledOnce() *VerifierSlackClient { | ||
return &VerifierSlackClient{mock, pegomock.Times(1), nil} | ||
} | ||
|
||
func (mock *MockSlackClient) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierSlackClient { | ||
return &VerifierSlackClient{mock, invocationCountMatcher, nil} | ||
} | ||
|
||
func (mock *MockSlackClient) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierSlackClient { | ||
return &VerifierSlackClient{mock, invocationCountMatcher, inOrderContext} | ||
} | ||
|
||
type VerifierSlackClient struct { | ||
mock *MockSlackClient | ||
invocationCountMatcher pegomock.Matcher | ||
inOrderContext *pegomock.InOrderContext | ||
} | ||
|
||
func (verifier *VerifierSlackClient) AuthTest() *SlackClient_AuthTest_OngoingVerification { | ||
params := []pegomock.Param{} | ||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "AuthTest", params) | ||
return &SlackClient_AuthTest_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} | ||
} | ||
|
||
type SlackClient_AuthTest_OngoingVerification struct { | ||
mock *MockSlackClient | ||
methodInvocations []pegomock.MethodInvocation | ||
} | ||
|
||
func (c *SlackClient_AuthTest_OngoingVerification) GetCapturedArguments() { | ||
} | ||
|
||
func (c *SlackClient_AuthTest_OngoingVerification) GetAllCapturedArguments() { | ||
} | ||
|
||
func (verifier *VerifierSlackClient) ChannelExist(channelName string) *SlackClient_ChannelExist_OngoingVerification { | ||
params := []pegomock.Param{channelName} | ||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ChannelExist", params) | ||
return &SlackClient_ChannelExist_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} | ||
} | ||
|
||
type SlackClient_ChannelExist_OngoingVerification struct { | ||
mock *MockSlackClient | ||
methodInvocations []pegomock.MethodInvocation | ||
} | ||
|
||
func (c *SlackClient_ChannelExist_OngoingVerification) GetCapturedArguments() string { | ||
channelName := c.GetAllCapturedArguments() | ||
return channelName[len(channelName)-1] | ||
} | ||
|
||
func (c *SlackClient_ChannelExist_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { | ||
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) | ||
if len(params) > 0 { | ||
_param0 = make([]string, len(params[0])) | ||
for u, param := range params[0] { | ||
_param0[u] = param.(string) | ||
} | ||
} | ||
return | ||
} | ||
|
||
func (verifier *VerifierSlackClient) PostMessage(channel string, result ApplyResult) *SlackClient_PostMessage_OngoingVerification { | ||
params := []pegomock.Param{channel, result} | ||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "PostMessage", params) | ||
return &SlackClient_PostMessage_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} | ||
} | ||
|
||
type SlackClient_PostMessage_OngoingVerification struct { | ||
mock *MockSlackClient | ||
methodInvocations []pegomock.MethodInvocation | ||
} | ||
|
||
func (c *SlackClient_PostMessage_OngoingVerification) GetCapturedArguments() (string, ApplyResult) { | ||
channel, result := c.GetAllCapturedArguments() | ||
return channel[len(channel)-1], result[len(result)-1] | ||
} | ||
|
||
func (c *SlackClient_PostMessage_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []ApplyResult) { | ||
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) | ||
if len(params) > 0 { | ||
_param0 = make([]string, len(params[0])) | ||
for u, param := range params[0] { | ||
_param0[u] = param.(string) | ||
} | ||
_param1 = make([]ApplyResult, len(params[1])) | ||
for u, param := range params[1] { | ||
_param1[u] = param.(ApplyResult) | ||
} | ||
} | ||
return | ||
} |
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 |
---|---|---|
@@ -1,4 +1,39 @@ | ||
package webhooks_test | ||
|
||
// todo: actually test | ||
// purposefully empty to trigger coverage report | ||
import ( | ||
"regexp" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hootsuite/atlantis/server/events/webhooks" | ||
"github.com/hootsuite/atlantis/server/events/webhooks/mocks" | ||
) | ||
|
||
func TestNewWebhooksManager_InvalidToken(t *testing.T) { | ||
t.Log("When given an empty slack token and there is a slack webhook config, an error is returned") | ||
emptyToken := "" | ||
_, err := webhooks.NewWebhooksManager(validConfigs(), webhooks.NewClient(emptyToken)) | ||
Assert(t, err != nil, "expected error") | ||
// Equals(t, "for slack webhooks, slack-token must be set", err.Error()) | ||
Assert(t, strings.Contains(err.Error(), "testing slack authentication"), "expected auth error") | ||
} | ||
|
||
func TestSend_Success(t *testing.T) { | ||
RegisterMockTestingT(t) | ||
client := mocks.MockSlackClient() | ||
regex, err := regexp.Compile(".*") | ||
Ok(t, err) | ||
hook := SlackWebhook{ | ||
Client: client, | ||
EnvRegex: regex, | ||
Channel: "somechannel", | ||
} | ||
result := webhooks.ApplyResult{ | ||
Environment: "production" | ||
} | ||
hook.Send(result) | ||
} | ||
|
||
func TestSend_Error(t *testing.T) { | ||
|
||
} |
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
Oops, something went wrong.