This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
notifications_test.go
71 lines (65 loc) · 1.72 KB
/
notifications_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package notifications
import (
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/weaveworks/flux"
"github.com/weaveworks/flux/instance"
)
// Generate an example release
func exampleRelease(t *testing.T) flux.Release {
now := time.Now().UTC()
img1a1, _ := flux.ParseImageID("img1:a1")
img1a2, _ := flux.ParseImageID("img1:a2")
return flux.Release{
ID: flux.NewReleaseID(),
CreatedAt: now.Add(-1 * time.Minute),
StartedAt: now.Add(-30 * time.Second),
EndedAt: now.Add(-1 * time.Second),
Done: true,
Priority: 100,
Status: flux.ReleaseStatusFailed,
Log: []string{string(flux.ReleaseStatusFailed)},
Spec: flux.ReleaseSpec{
ServiceSpecs: []flux.ServiceSpec{flux.ServiceSpec("default/helloworld")},
ImageSpec: flux.ImageSpecLatest,
Kind: flux.ReleaseKindExecute,
Excludes: nil,
},
Result: flux.ReleaseResult{
flux.ServiceID("default/helloworld"): {
Status: flux.ReleaseStatusFailed,
Error: "overall-release-error",
PerContainer: []flux.ContainerResult{
{
Error: "",
ContainerUpdate: flux.ContainerUpdate{
Container: "container1",
Current: img1a1,
Target: img1a2,
},
},
},
},
},
}
}
func TestRelease_DryRun(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
t.Error("Expected no http request to have been made")
}))
defer server.Close()
// It should send releases to slack
r := exampleRelease(t)
r.Spec.Kind = flux.ReleaseKindPlan
if err := Release(instance.Config{
Settings: flux.UnsafeInstanceConfig{
Slack: flux.NotifierConfig{
HookURL: server.URL,
},
},
}, r, nil); err != nil {
t.Fatal(err)
}
}