-
Notifications
You must be signed in to change notification settings - Fork 283
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 #35 from rusenask/develop
Develop
- Loading branch information
Showing
8 changed files
with
270 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package webhook | ||
|
||
import ( | ||
"io/ioutil" | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/rusenask/keel/types" | ||
) | ||
|
||
func TestWebhookRequest(t *testing.T) { | ||
currentTime := time.Now() | ||
handler := func(resp http.ResponseWriter, req *http.Request) { | ||
body, err := ioutil.ReadAll(req.Body) | ||
if err != nil { | ||
t.Errorf("failed to parse body: %s", err) | ||
} | ||
|
||
bodyStr := string(body) | ||
|
||
if !strings.Contains(bodyStr, types.NotificationPreDeploymentUpdate.String()) { | ||
t.Errorf("missing deployment type") | ||
} | ||
|
||
if !strings.Contains(bodyStr, "LevelDebug") { | ||
t.Errorf("missing level") | ||
} | ||
|
||
if !strings.Contains(bodyStr, "update deployment") { | ||
t.Errorf("missing name") | ||
} | ||
if !strings.Contains(bodyStr, "message here") { | ||
t.Errorf("missing message") | ||
} | ||
|
||
t.Log(bodyStr) | ||
|
||
} | ||
|
||
// create test server with handler | ||
ts := httptest.NewServer(http.HandlerFunc(handler)) | ||
defer ts.Close() | ||
|
||
s := &sender{ | ||
endpoint: ts.URL, | ||
client: &http.Client{}, | ||
} | ||
|
||
s.Send(types.EventNotification{ | ||
Name: "update deployment", | ||
Message: "message here", | ||
CreatedAt: currentTime, | ||
Type: types.NotificationPreDeploymentUpdate, | ||
Level: types.LevelDebug, | ||
}) | ||
} |
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
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,68 @@ | ||
// generated by jsonenums -type=Level; DO NOT EDIT | ||
|
||
package types | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
var ( | ||
_LevelNameToValue = map[string]Level{ | ||
"LevelDebug": LevelDebug, | ||
"LevelInfo": LevelInfo, | ||
"LevelSuccess": LevelSuccess, | ||
"LevelWarn": LevelWarn, | ||
"LevelError": LevelError, | ||
"LevelFatal": LevelFatal, | ||
} | ||
|
||
_LevelValueToName = map[Level]string{ | ||
LevelDebug: "LevelDebug", | ||
LevelInfo: "LevelInfo", | ||
LevelSuccess: "LevelSuccess", | ||
LevelWarn: "LevelWarn", | ||
LevelError: "LevelError", | ||
LevelFatal: "LevelFatal", | ||
} | ||
) | ||
|
||
func init() { | ||
var v Level | ||
if _, ok := interface{}(v).(fmt.Stringer); ok { | ||
_LevelNameToValue = map[string]Level{ | ||
interface{}(LevelDebug).(fmt.Stringer).String(): LevelDebug, | ||
interface{}(LevelInfo).(fmt.Stringer).String(): LevelInfo, | ||
interface{}(LevelSuccess).(fmt.Stringer).String(): LevelSuccess, | ||
interface{}(LevelWarn).(fmt.Stringer).String(): LevelWarn, | ||
interface{}(LevelError).(fmt.Stringer).String(): LevelError, | ||
interface{}(LevelFatal).(fmt.Stringer).String(): LevelFatal, | ||
} | ||
} | ||
} | ||
|
||
// MarshalJSON is generated so Level satisfies json.Marshaler. | ||
func (r Level) MarshalJSON() ([]byte, error) { | ||
if s, ok := interface{}(r).(fmt.Stringer); ok { | ||
return json.Marshal(s.String()) | ||
} | ||
s, ok := _LevelValueToName[r] | ||
if !ok { | ||
return nil, fmt.Errorf("invalid Level: %d", r) | ||
} | ||
return json.Marshal(s) | ||
} | ||
|
||
// UnmarshalJSON is generated so Level satisfies json.Unmarshaler. | ||
func (r *Level) UnmarshalJSON(data []byte) error { | ||
var s string | ||
if err := json.Unmarshal(data, &s); err != nil { | ||
return fmt.Errorf("Level should be a string, got %s", data) | ||
} | ||
v, ok := _LevelNameToValue[s] | ||
if !ok { | ||
return fmt.Errorf("invalid Level %q", s) | ||
} | ||
*r = v | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// generated by jsonenums -type=Notification; DO NOT EDIT | ||
|
||
package types | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
var ( | ||
_NotificationNameToValue = map[string]Notification{ | ||
"PreProviderSubmitNotification": PreProviderSubmitNotification, | ||
"PostProviderSubmitNotification": PostProviderSubmitNotification, | ||
"NotificationPreDeploymentUpdate": NotificationPreDeploymentUpdate, | ||
"NotificationDeploymentUpdate": NotificationDeploymentUpdate, | ||
} | ||
|
||
_NotificationValueToName = map[Notification]string{ | ||
PreProviderSubmitNotification: "PreProviderSubmitNotification", | ||
PostProviderSubmitNotification: "PostProviderSubmitNotification", | ||
NotificationPreDeploymentUpdate: "NotificationPreDeploymentUpdate", | ||
NotificationDeploymentUpdate: "NotificationDeploymentUpdate", | ||
} | ||
) | ||
|
||
func init() { | ||
var v Notification | ||
if _, ok := interface{}(v).(fmt.Stringer); ok { | ||
_NotificationNameToValue = map[string]Notification{ | ||
interface{}(PreProviderSubmitNotification).(fmt.Stringer).String(): PreProviderSubmitNotification, | ||
interface{}(PostProviderSubmitNotification).(fmt.Stringer).String(): PostProviderSubmitNotification, | ||
interface{}(NotificationPreDeploymentUpdate).(fmt.Stringer).String(): NotificationPreDeploymentUpdate, | ||
interface{}(NotificationDeploymentUpdate).(fmt.Stringer).String(): NotificationDeploymentUpdate, | ||
} | ||
} | ||
} | ||
|
||
// MarshalJSON is generated so Notification satisfies json.Marshaler. | ||
func (r Notification) MarshalJSON() ([]byte, error) { | ||
if s, ok := interface{}(r).(fmt.Stringer); ok { | ||
return json.Marshal(s.String()) | ||
} | ||
s, ok := _NotificationValueToName[r] | ||
if !ok { | ||
return nil, fmt.Errorf("invalid Notification: %d", r) | ||
} | ||
return json.Marshal(s) | ||
} | ||
|
||
// UnmarshalJSON is generated so Notification satisfies json.Unmarshaler. | ||
func (r *Notification) UnmarshalJSON(data []byte) error { | ||
var s string | ||
if err := json.Unmarshal(data, &s); err != nil { | ||
return fmt.Errorf("Notification should be a string, got %s", data) | ||
} | ||
v, ok := _NotificationNameToValue[s] | ||
if !ok { | ||
return fmt.Errorf("invalid Notification %q", s) | ||
} | ||
*r = v | ||
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