This commit is contained in:
parent
f2566ae21d
commit
0303b4b9aa
3 changed files with 232 additions and 90 deletions
138
main_test.go
Normal file
138
main_test.go
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func Test_card(t *testing.T) {
|
||||
type args struct {
|
||||
d templateData
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []byte
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test one",
|
||||
args: args{
|
||||
d: templateData{
|
||||
Title: "test",
|
||||
SubTitle: "first test",
|
||||
Author: "gotest",
|
||||
IconUrl: "https://github.githubassets.com/images/modules/logos_page/Octocat.png",
|
||||
Project: "proj",
|
||||
Commit: "12345",
|
||||
Branch: "main",
|
||||
Status: "success",
|
||||
ActionID: "123",
|
||||
GitURL: "https://test.url",
|
||||
Color: "c0c0c0",
|
||||
EventBody: "no body",
|
||||
},
|
||||
},
|
||||
want: []byte(`
|
||||
{
|
||||
"cardsV2": [
|
||||
{
|
||||
"cardId": "notify-123",
|
||||
"card": {
|
||||
"header": {
|
||||
"title": "test",
|
||||
"subtitle": "first test",
|
||||
"imageUrl": "https://github.githubassets.com/images/modules/logos_page/Octocat.png",
|
||||
"imageType": "SQUARE"
|
||||
},
|
||||
"sections": [
|
||||
{
|
||||
"header": "test",
|
||||
"collapsible": false,
|
||||
"widgets": [
|
||||
|
||||
{
|
||||
"decoratedText": {
|
||||
"startIcon": {
|
||||
"materialIcon": {
|
||||
"name": "check_circle"
|
||||
}
|
||||
},
|
||||
"text": "<b style=\"color: green;\">SUCCESS</b>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"decoratedText": {
|
||||
"startIcon": {
|
||||
"knownIcon": "PERSON"
|
||||
},
|
||||
"text": "<b>gotest</b>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"textParagraph": {
|
||||
"text": "no body",
|
||||
"maxLines": 2
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgets": [
|
||||
{
|
||||
"buttonList": {
|
||||
"buttons": [
|
||||
{
|
||||
"text": "View Source Event",
|
||||
"type": "FILLED",
|
||||
"onClick": {
|
||||
"openLink": {
|
||||
"url": "https://test.url/proj/actions/runs/123"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
`),
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := card(tt.args.d)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("card() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
|
||||
var gotJson any
|
||||
err = json.Unmarshal(got, &gotJson)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var wantJson any
|
||||
err = json.Unmarshal(tt.want, &wantJson)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
//if !reflect.DeepEqual(wantJson, gotJson) {
|
||||
// t.Errorf("card() got = %v, want %v", gotJson, wantJson)
|
||||
//}
|
||||
if diff := cmp.Diff(wantJson, gotJson); diff != "" {
|
||||
t.Errorf("MakeGatewayInfo() mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue