Skip to content

Commit 2d8659b

Browse files
authoredOct 1, 2024··
feat: basic e2e tests in order to verify notification service health (#20182)
* feat: basic e2e tests in order to verify notification service health Signed-off-by: pashakostohrys <pavel@codefresh.io> * feat: basic e2e tests in order to verify notification service health Signed-off-by: pashakostohrys <pavel@codefresh.io> --------- Signed-off-by: pashakostohrys <pavel@codefresh.io>
1 parent 5796a7c commit 2d8659b

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed
 

‎test/e2e/fixture/fixture.go

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ const (
4646
ArgoCDNamespace = "argocd-e2e"
4747
ArgoCDAppNamespace = "argocd-e2e-external"
4848

49+
// notifications controller, metrics server port
50+
defaultNotificationServer = "localhost:9001"
51+
4952
// ensure all repos are in one directory tree, so we can easily clean them up
5053
TmpDir = "/tmp/argo-e2e"
5154
repoDir = "testdata.git"
@@ -1020,6 +1023,10 @@ func GetApiServerAddress() string {
10201023
return apiServerAddress
10211024
}
10221025

1026+
func GetNotificationServerAddress() string {
1027+
return defaultNotificationServer
1028+
}
1029+
10231030
func GetToken() string {
10241031
return token
10251032
}

‎test/e2e/fixture/http.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ import (
1212
)
1313

1414
// DoHttpRequest executes a http request against the Argo CD API server
15-
func DoHttpRequest(method string, path string, data ...byte) (*http.Response, error) {
15+
func DoHttpRequest(method string, path string, host string, data ...byte) (*http.Response, error) {
1616
reqUrl, err := url.Parse(path)
1717
if err != nil {
1818
return nil, err
1919
}
2020
reqUrl.Scheme = "http"
21-
reqUrl.Host = apiServerAddress
21+
if host != "" {
22+
reqUrl.Host = host
23+
} else {
24+
reqUrl.Host = apiServerAddress
25+
}
2226
var body io.Reader
2327
if data != nil {
2428
body = bytes.NewReader(data)
@@ -41,7 +45,7 @@ func DoHttpRequest(method string, path string, data ...byte) (*http.Response, er
4145

4246
// DoHttpJsonRequest executes a http request against the Argo CD API server and unmarshals the response body as JSON
4347
func DoHttpJsonRequest(method string, path string, result interface{}, data ...byte) error {
44-
resp, err := DoHttpRequest(method, path, data...)
48+
resp, err := DoHttpRequest(method, path, "", data...)
4549
if err != nil {
4650
return err
4751
}

‎test/e2e/fixture/notification/actions.go

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
// using the Then()
1313
type Actions struct {
1414
context *Context
15+
16+
healthy bool
1517
}
1618

1719
func (a *Actions) SetParamInNotificationConfigMap(key, value string) *Actions {
@@ -25,3 +27,12 @@ func (a *Actions) Then() *Consequences {
2527
time.Sleep(1 * time.Second)
2628
return &Consequences{a.context, a}
2729
}
30+
31+
func (a *Actions) Healthcheck() *Actions {
32+
a.context.t.Helper()
33+
_, err := fixture.DoHttpRequest("GET",
34+
"/metrics",
35+
fixture.GetNotificationServerAddress())
36+
a.healthy = err == nil
37+
return a
38+
}

‎test/e2e/fixture/notification/consequences.go

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ func (c *Consequences) Services(block func(services *notification.ServiceList, e
1919
return c
2020
}
2121

22+
func (c *Consequences) Healthy(block func(healthy bool)) *Consequences {
23+
c.context.t.Helper()
24+
block(c.actions.healthy)
25+
return c
26+
}
27+
2228
func (c *Consequences) Triggers(block func(services *notification.TriggerList, err error)) *Consequences {
2329
c.context.t.Helper()
2430
block(c.listTriggers())

‎test/e2e/notification_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,13 @@ func TestNotificationsListTriggers(t *testing.T) {
4040
assert.Equal(t, []*notification.Trigger{{Name: ptr.To("on-created")}}, triggers.Items)
4141
})
4242
}
43+
44+
func TestNotificationsHealthcheck(t *testing.T) {
45+
ctx := notifFixture.Given(t)
46+
ctx.When().
47+
Healthcheck().
48+
Then().
49+
Healthy(func(healthy bool) {
50+
assert.True(t, healthy)
51+
})
52+
}

0 commit comments

Comments
 (0)
Please sign in to comment.