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": true, "uncollapsibleWidgetsCount": 2, "widgets": [ { "decoratedText": { "startIcon": { "materialIcon": { "name": "check_circle" } }, "text": "SUCCESS" } }, { "decoratedText": { "startIcon": { "knownIcon": "PERSON" }, "text": "gotest" } }, { "textParagraph": { "text": "no body", "maxLines": 2 } }, { "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) } }) } }