forked from GoogleCloudPlatform/cloud-build-notifiers
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain_test.go
38 lines (31 loc) · 757 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"encoding/json"
"testing"
"github.com/google/go-cmp/cmp"
cbpb "google.golang.org/genproto/googleapis/devtools/cloudbuild/v1"
)
func TestBuildMessage(t *testing.T) {
n := new(discordNotifier)
b := &cbpb.Build{
ProjectId: "my-project-id",
Id: "some-build-id",
Status: cbpb.Build_SUCCESS,
LogUrl: "https://some.example.com/log/url?foo=bar",
}
got, err := n.buildMessage(b)
if err != nil {
t.Fatalf("writeMessage failed: %v", err)
}
want, _ := json.Marshal(discordMessage{
Embeds: []embed{
{Title: "✅ SUCCESS",
Color: 1127128,
},
},
})
gotJSON, _ := json.Marshal(got)
if diff := cmp.Diff(gotJSON, want); diff != "" {
t.Errorf("writeMessage got unexpected diff: %s", diff)
}
}