-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
101 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 |
---|---|---|
@@ -1,7 +1,35 @@ | ||
package cli | ||
|
||
import "github.com/urfave/cli/v2" | ||
import ( | ||
"github.com/urfave/cli/v2" | ||
"github.com/wesleimp/unleash-checkr/internal/flag" | ||
"github.com/wesleimp/unleash-checkr/internal/notification/slack" | ||
"github.com/wesleimp/unleash-checkr/pkg/config" | ||
"github.com/wesleimp/unleash-checkr/pkg/context" | ||
) | ||
|
||
func runNotify(c *cli.Context) error { | ||
token := c.String("slack-token") | ||
channel := c.String("channel") | ||
url := c.String("url") | ||
expires := c.Int("expires") | ||
|
||
ctx := context.New(&config.Config{ | ||
SlackChannel: channel, | ||
SlackToken: token, | ||
URL: url, | ||
Expires: expires, | ||
}) | ||
|
||
ff, err := flag.Get(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = slack.Notify(ctx, ff) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
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,55 +1 @@ | ||
package slack | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/wesleimp/unleash-checkr/internal/flag" | ||
"github.com/wesleimp/unleash-checkr/pkg/config" | ||
"github.com/wesleimp/unleash-checkr/pkg/context" | ||
) | ||
|
||
func TestWithEmptyFlags(t *testing.T) { | ||
ctx := context.New(&config.Config{}) | ||
var flags []flag.Flag | ||
text, err := describeMessageBody(ctx, flags) | ||
assert.NoError(t, err) | ||
assert.Equal(t, text, "Here are some flags that have passed their expiration and can now be removed.") | ||
} | ||
|
||
func TestWithOneFlag(t *testing.T) { | ||
ctx := context.New(&config.Config{ | ||
URL: "http://test.com", | ||
}) | ||
|
||
date, err := time.Parse(time.RFC3339, "2020-01-01T15:04:05+07:00") | ||
assert.NoError(t, err) | ||
|
||
var flags = []flag.Flag{ | ||
{ | ||
Name: "First", | ||
Description: "", | ||
CreatedAt: date, | ||
}, | ||
{ | ||
Name: "Second", | ||
Description: "Second flag", | ||
CreatedAt: date, | ||
}, | ||
} | ||
text, err := describeMessageBody(ctx, flags) | ||
assert.NoError(t, err) | ||
assert.Equal(t, text, `Here are some flags that have passed their expiration and can now be removed. | ||
*Flags* | ||
*First* | ||
Created at: 01/01/2020 3:04 PM | ||
http://test.com/#/features/strategies/First | ||
*Second* - Second flag | ||
Created at: 01/01/2020 3:04 PM | ||
http://test.com/#/features/strategies/Second | ||
`) | ||
} |