-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from rusenask/develop
Develop
- Loading branch information
Showing
1,532 changed files
with
31,953 additions
and
239,810 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,129 @@ | ||
package notification | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/rusenask/keel/types" | ||
) | ||
|
||
type fakeSender struct { | ||
sent *types.EventNotification | ||
|
||
shouldConfigure bool | ||
shouldError error | ||
} | ||
|
||
func (s *fakeSender) Configure(*Config) (bool, error) { | ||
return s.shouldConfigure, nil | ||
} | ||
|
||
func (s *fakeSender) Send(event types.EventNotification) error { | ||
s.sent = &event | ||
fmt.Println("sending event") | ||
return s.shouldError | ||
} | ||
|
||
func TestSend(t *testing.T) { | ||
sndr := New(context.Background()) | ||
|
||
sndr.Configure(&Config{ | ||
Level: types.LevelDebug, | ||
Attempts: 1, | ||
}) | ||
|
||
fs := &fakeSender{ | ||
shouldConfigure: true, | ||
shouldError: nil, | ||
} | ||
|
||
RegisterSender("fakeSender", fs) | ||
defer sndr.UnregisterSender("fakeSender") | ||
|
||
err := sndr.Send(types.EventNotification{ | ||
Level: types.LevelInfo, | ||
Type: types.NotificationPreDeploymentUpdate, | ||
Message: "foo", | ||
}) | ||
|
||
if err != nil { | ||
t.Errorf("unexpected error: %s", err) | ||
} | ||
|
||
if fs.sent.Message != "foo" { | ||
t.Errorf("unexpected notification message: %s", fs.sent.Message) | ||
} | ||
|
||
if fs.sent.Level != types.LevelInfo { | ||
t.Errorf("unexpected level: %s", fs.sent.Level) | ||
} | ||
} | ||
|
||
// test when configured level is higher than the event | ||
func TestSendLevelNotificationA(t *testing.T) { | ||
sndr := New(context.Background()) | ||
|
||
sndr.Configure(&Config{ | ||
Level: types.LevelInfo, | ||
Attempts: 1, | ||
}) | ||
|
||
fs := &fakeSender{ | ||
shouldConfigure: true, | ||
shouldError: nil, | ||
} | ||
|
||
RegisterSender("fakeSender", fs) | ||
defer sndr.UnregisterSender("fakeSender") | ||
|
||
err := sndr.Send(types.EventNotification{ | ||
Level: types.LevelDebug, | ||
Type: types.NotificationPreDeploymentUpdate, | ||
Message: "foo", | ||
}) | ||
|
||
if err != nil { | ||
t.Errorf("unexpected error: %s", err) | ||
} | ||
|
||
if fs.sent != nil { | ||
t.Errorf("didn't expect to find sent even for this level") | ||
} | ||
} | ||
|
||
// event level is higher than the configured | ||
func TestSendLevelNotificationB(t *testing.T) { | ||
sndr := New(context.Background()) | ||
|
||
sndr.Configure(&Config{ | ||
Level: types.LevelInfo, | ||
Attempts: 1, | ||
}) | ||
|
||
fs := &fakeSender{ | ||
shouldConfigure: true, | ||
shouldError: nil, | ||
} | ||
|
||
RegisterSender("fakeSender", fs) | ||
defer sndr.UnregisterSender("fakeSender") | ||
|
||
err := sndr.Send(types.EventNotification{ | ||
Level: types.LevelSuccess, | ||
Type: types.NotificationPreDeploymentUpdate, | ||
Message: "foo", | ||
}) | ||
|
||
if err != nil { | ||
t.Errorf("unexpected error: %s", err) | ||
} | ||
|
||
if fs.sent.Message != "foo" { | ||
t.Errorf("unexpected notification message: %s", fs.sent.Message) | ||
} | ||
|
||
if fs.sent.Level != types.LevelSuccess { | ||
t.Errorf("unexpected level: %s", fs.sent.Level) | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.