Skip to content

Commit

Permalink
add support test
Browse files Browse the repository at this point in the history
  • Loading branch information
sasamuku committed Feb 26, 2022
1 parent 9628d2f commit dda9cec
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
4 changes: 2 additions & 2 deletions aws/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type Case struct {
Subject string `json:"subject"`
Status string `json:"status"`
SubmitteBy string `json:"submitteBy"`
SubmittedBy string `json:"SubmittedBy"`
TimeCreated string `json:"timeCreated"`
Url string `json:"url"`
}
Expand Down Expand Up @@ -64,7 +64,7 @@ func makeCaseList(cd []types.CaseDetails) []*Case {
eachCase := Case{
Subject: *c.Subject,
Status: *c.Status,
SubmitteBy: *c.SubmittedBy,
SubmittedBy: *c.SubmittedBy,
TimeCreated: *c.TimeCreated,
Url: "https://console.aws.amazon.com/support/home#/case/?displayId=" + *c.DisplayId + "%26language=" + *c.Language,
}
Expand Down
50 changes: 50 additions & 0 deletions aws/support_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package aws

import (
"testing"

"github.com/aws/aws-sdk-go-v2/service/support/types"
)

func Test_Support(t *testing.T) {
caseId := "case-12345678910-2013-c4c1d2bf33c5cf47"
ccEmailAddresses := []string{"[email protected]"}
displayId := "1234567890"
language := "ja"
status := "opened"
subject := "Test Subject"
submittedBy := "[email protected]"
timeCreated := "2021-12-01T12:00:00.000Z"
url := "https://console.aws.amazon.com/support/home#/case/?displayId=1234567890%26language=ja"

caseDetails := []types.CaseDetails{
{
CaseId: &caseId,
CcEmailAddresses: ccEmailAddresses,
DisplayId: &displayId,
Language: &language,
Status: &status,
Subject: &subject,
SubmittedBy: &submittedBy,
TimeCreated: &timeCreated,
},
}
caseList := makeCaseList(caseDetails)
for _, c := range caseList {
if c.Subject != subject {
t.Fatalf("Fail: got = %v, want = %v", c.Subject, subject)
}
if c.Status != status {
t.Fatalf("Fail: got = %v, want = %v", c.Status, status)
}
if c.SubmittedBy != submittedBy {
t.Fatalf("Fail: got = %v, want = %v", c.SubmittedBy, submittedBy)
}
if c.TimeCreated != timeCreated {
t.Fatalf("Fail: got = %v, want = %v", c.TimeCreated, timeCreated)
}
if c.Url != url {
t.Fatalf("Fail: got = %v, want = %v", c.Url, url)
}
}
}
2 changes: 1 addition & 1 deletion slack/notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Payload struct {
func ConvertToNoticeFormat(cases []*aws.Case) string {
text := `Subject: {{ .Subject }}
Status: {{ .Status }}
SubmitteBy: {{ .SubmitteBy }}
SubmittedBy: {{ .SubmittedBy }}
TimeCreated: {{ .TimeCreated }}
Url: {{ .Url }}
`
Expand Down
4 changes: 2 additions & 2 deletions slack/notice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Test_Notice(t *testing.T) {
{
Subject: "Test",
Status: "opened",
SubmitteBy: "[email protected]",
SubmittedBy: "[email protected]",
TimeCreated: "2021-03-01T01:43:57.974Z",
Url: "https://console.aws.amazon.com/support/home#/case/?displayId=12345%26language=ja",
},
Expand All @@ -53,7 +53,7 @@ func Test_Notice(t *testing.T) {
payload := NewPayload("AWS Support Case Notice", ConvertToNoticeFormat(tt.cases))
notice := NewSlackNotice(tt.webhookUrl, payload)
if statusCode := notice.Run(); statusCode != tt.wants.statusCode {
t.Fatalf("run() status: got = %v, want = %v", statusCode, tt.wants.statusCode)
t.Fatalf("Fail: got = %v, want = %v", statusCode, tt.wants.statusCode)
}
})
}
Expand Down

0 comments on commit dda9cec

Please sign in to comment.