From c3629b72d944a49dc65ed4668995e5e5d6e71dc8 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Tue, 1 Oct 2024 16:09:21 +0300 Subject: [PATCH 1/2] feat: basic e2e tests in order to verify notification service health Signed-off-by: pashakostohrys --- test/e2e/fixture/fixture.go | 7 +++++++ test/e2e/fixture/http.go | 10 +++++++--- test/e2e/fixture/notification/actions.go | 11 +++++++++++ test/e2e/fixture/notification/consequences.go | 8 +++++++- test/e2e/notification_test.go | 10 ++++++++++ 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/test/e2e/fixture/fixture.go b/test/e2e/fixture/fixture.go index 24d0e4ce74d71..b48dbaa10d65d 100644 --- a/test/e2e/fixture/fixture.go +++ b/test/e2e/fixture/fixture.go @@ -45,6 +45,9 @@ const ( TestingLabel = "e2e.argoproj.io" ArgoCDNamespace = "argocd-e2e" ArgoCDAppNamespace = "argocd-e2e-external" + + // notifications controller, metrics server port + defaultNotificationServer = "localhost:9001" // ensure all repos are in one directory tree, so we can easily clean them up TmpDir = "/tmp/argo-e2e" @@ -1020,6 +1023,10 @@ func GetApiServerAddress() string { return apiServerAddress } +func GetNotificationServerAddress() string { + return defaultNotificationServer +} + func GetToken() string { return token } diff --git a/test/e2e/fixture/http.go b/test/e2e/fixture/http.go index 00c123ab5d893..28d5c0bc3db65 100644 --- a/test/e2e/fixture/http.go +++ b/test/e2e/fixture/http.go @@ -12,13 +12,17 @@ import ( ) // DoHttpRequest executes a http request against the Argo CD API server -func DoHttpRequest(method string, path string, data ...byte) (*http.Response, error) { +func DoHttpRequest(method string, path string, host string, data ...byte) (*http.Response, error) { reqUrl, err := url.Parse(path) if err != nil { return nil, err } reqUrl.Scheme = "http" - reqUrl.Host = apiServerAddress + if host != "" { + reqUrl.Host = host + } else { + reqUrl.Host = apiServerAddress + } var body io.Reader if data != nil { body = bytes.NewReader(data) @@ -41,7 +45,7 @@ func DoHttpRequest(method string, path string, data ...byte) (*http.Response, er // DoHttpJsonRequest executes a http request against the Argo CD API server and unmarshals the response body as JSON func DoHttpJsonRequest(method string, path string, result interface{}, data ...byte) error { - resp, err := DoHttpRequest(method, path, data...) + resp, err := DoHttpRequest(method, path, "", data...) if err != nil { return err } diff --git a/test/e2e/fixture/notification/actions.go b/test/e2e/fixture/notification/actions.go index 4b3c328f7ed29..1790620375c70 100644 --- a/test/e2e/fixture/notification/actions.go +++ b/test/e2e/fixture/notification/actions.go @@ -12,6 +12,8 @@ import ( // using the Then() type Actions struct { context *Context + + healthy bool } func (a *Actions) SetParamInNotificationConfigMap(key, value string) *Actions { @@ -25,3 +27,12 @@ func (a *Actions) Then() *Consequences { time.Sleep(1 * time.Second) return &Consequences{a.context, a} } + +func (a *Actions) Healthcheck() *Actions { + a.context.t.Helper() + _, err := fixture.DoHttpRequest("GET", + "/metrics", + fixture.GetNotificationServerAddress()) + a.healthy = err == nil + return a +} \ No newline at end of file diff --git a/test/e2e/fixture/notification/consequences.go b/test/e2e/fixture/notification/consequences.go index bfc4b4b0e0988..e2afa095d7862 100644 --- a/test/e2e/fixture/notification/consequences.go +++ b/test/e2e/fixture/notification/consequences.go @@ -19,6 +19,12 @@ func (c *Consequences) Services(block func(services *notification.ServiceList, e return c } +func (c *Consequences) Healthy(block func(healthy bool)) *Consequences { + c.context.t.Helper() + block(c.actions.healthy) + return c +} + func (c *Consequences) Triggers(block func(services *notification.TriggerList, err error)) *Consequences { c.context.t.Helper() block(c.listTriggers()) @@ -52,4 +58,4 @@ func (c *Consequences) When() *Actions { func (c *Consequences) Given() *Context { return c.context -} +} \ No newline at end of file diff --git a/test/e2e/notification_test.go b/test/e2e/notification_test.go index e4dd855a107e3..6396075fe6ba3 100644 --- a/test/e2e/notification_test.go +++ b/test/e2e/notification_test.go @@ -40,3 +40,13 @@ func TestNotificationsListTriggers(t *testing.T) { assert.Equal(t, []*notification.Trigger{{Name: ptr.To("on-created")}}, triggers.Items) }) } + +func TestNotificationsHealthcheck(t *testing.T) { + ctx := notifFixture.Given(t) + ctx.When(). + Healthcheck(). + Then(). + Healthy(func(healthy bool) { + assert.True(t, healthy) + }) +} \ No newline at end of file From 85d73be2fba499c2035f25d0b0ed52e1ddbc2b03 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Tue, 1 Oct 2024 16:24:36 +0300 Subject: [PATCH 2/2] feat: basic e2e tests in order to verify notification service health Signed-off-by: pashakostohrys --- test/e2e/fixture/fixture.go | 2 +- test/e2e/fixture/http.go | 2 +- test/e2e/fixture/notification/actions.go | 4 ++-- test/e2e/fixture/notification/consequences.go | 2 +- test/e2e/notification_test.go | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/e2e/fixture/fixture.go b/test/e2e/fixture/fixture.go index b48dbaa10d65d..c02cc233e5d20 100644 --- a/test/e2e/fixture/fixture.go +++ b/test/e2e/fixture/fixture.go @@ -45,7 +45,7 @@ const ( TestingLabel = "e2e.argoproj.io" ArgoCDNamespace = "argocd-e2e" ArgoCDAppNamespace = "argocd-e2e-external" - + // notifications controller, metrics server port defaultNotificationServer = "localhost:9001" diff --git a/test/e2e/fixture/http.go b/test/e2e/fixture/http.go index 28d5c0bc3db65..68e674f9f8b36 100644 --- a/test/e2e/fixture/http.go +++ b/test/e2e/fixture/http.go @@ -19,7 +19,7 @@ func DoHttpRequest(method string, path string, host string, data ...byte) (*http } reqUrl.Scheme = "http" if host != "" { - reqUrl.Host = host + reqUrl.Host = host } else { reqUrl.Host = apiServerAddress } diff --git a/test/e2e/fixture/notification/actions.go b/test/e2e/fixture/notification/actions.go index 1790620375c70..622032441ee75 100644 --- a/test/e2e/fixture/notification/actions.go +++ b/test/e2e/fixture/notification/actions.go @@ -12,7 +12,7 @@ import ( // using the Then() type Actions struct { context *Context - + healthy bool } @@ -35,4 +35,4 @@ func (a *Actions) Healthcheck() *Actions { fixture.GetNotificationServerAddress()) a.healthy = err == nil return a -} \ No newline at end of file +} diff --git a/test/e2e/fixture/notification/consequences.go b/test/e2e/fixture/notification/consequences.go index e2afa095d7862..46e09a4249327 100644 --- a/test/e2e/fixture/notification/consequences.go +++ b/test/e2e/fixture/notification/consequences.go @@ -58,4 +58,4 @@ func (c *Consequences) When() *Actions { func (c *Consequences) Given() *Context { return c.context -} \ No newline at end of file +} diff --git a/test/e2e/notification_test.go b/test/e2e/notification_test.go index 6396075fe6ba3..11ed412a39dca 100644 --- a/test/e2e/notification_test.go +++ b/test/e2e/notification_test.go @@ -49,4 +49,4 @@ func TestNotificationsHealthcheck(t *testing.T) { Healthy(func(healthy bool) { assert.True(t, healthy) }) -} \ No newline at end of file +}