diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index c9d3343d..8b74ea03 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -57,7 +57,7 @@ jobs: - name: Setup NATS run: | - make -C hack/ci/ get-nats-via-lifecycle-manager + make -C hack/ci/ install-nats-module - name: Setup and test the eventing-manager run: | diff --git a/hack/ci/Makefile b/hack/ci/Makefile index 5b2ed831..e4385d70 100644 --- a/hack/ci/Makefile +++ b/hack/ci/Makefile @@ -72,6 +72,11 @@ enable-nats-module: get-nats-via-lifecycle-manager: install-lifecycle-manager install-latest-nats-module-template-fast enable-nats-module ./check-k8s-resource-is-ready.sh 180 nats kyma-system +.PHONY: install-nats-module +install-nats-module: + kubectl apply -f https://github.com/kyma-project/nats-manager/releases/latest/download/nats-manager.yaml + kubectl apply -f https://github.com/kyma-project/nats-manager/releases/latest/download/nats-default-cr.yaml + .PHONY: verify-kyma verify-kyma: ## Wait for Kyma CR to be in Ready state. ../verify_kyma_status.sh diff --git a/testing/eventmeshmock.go b/testing/eventmeshmock.go index 937e72a3..134805c9 100644 --- a/testing/eventmeshmock.go +++ b/testing/eventmeshmock.go @@ -209,6 +209,93 @@ func (m *EventMeshMock) Start() string { return uri } +func (m *EventMeshMock) handleToken() func(w http.ResponseWriter, r *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost { + m.AuthResponse(w) + } + } +} + +func (m *EventMeshMock) handleList() func(w http.ResponseWriter, r *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodGet { + m.ListResponse(w) + } + } +} + +func (m *EventMeshMock) handleMessaging() func(w http.ResponseWriter, r *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case http.MethodDelete: + key := r.URL.Path + m.Subscriptions.DeleteSubscription(key) + m.DeleteResponse(w) + case http.MethodPost: + var subscription emstypes.Subscription + _ = json.NewDecoder(r.Body).Decode(&subscription) + key := r.URL.Path + "/" + subscription.Name + // check if any response override defined for this subscription + if overrideFunc, ok := m.ResponseOverrides.CreateResponse[key]; ok { + overrideFunc(w, subscription) + return + } + + // otherwise, use default flow + m.Requests.PutSubscription(r, subscription) + m.Subscriptions.PutSubscription(key, &subscription) + m.CreateResponse(w) + case http.MethodPatch: // mock update WebhookAuth config + var subscription emstypes.Subscription + err := json.NewDecoder(r.Body).Decode(&subscription) + if err != nil { + w.WriteHeader(http.StatusBadRequest) + return + } + + key := r.URL.Path // i.e. Path will be `/messaging/events/subscriptions/` + // save request. + m.Requests.PutSubscription(r, subscription) + m.UpdateResponse(w, key, subscription.WebhookAuth) + case http.MethodPut: // mock pause/resume EventMesh subscription + var state emstypes.State + if err := json.NewDecoder(r.Body).Decode(&state); err != nil { + w.WriteHeader(http.StatusBadRequest) + return + } + + // extract get request key from /messaging/events/subscriptions/%s/state + key := strings.TrimSuffix(r.URL.Path, "/state") + for i := 0; i < 3; i++ { + err := m.UpdateStateResponse(w, key, state) + if err == nil { + break + } + two := 2 + three := 3 + if i < two { // Don't sleep after the last attempt + time.Sleep(time.Duration(three) * time.Second) + } else { + panic(err) + } + } + case http.MethodGet: + key := r.URL.Path + // check if any response override defined for this subscription + if overrideFunc, ok := m.ResponseOverrides.GetResponse[key]; ok { + overrideFunc(w, key) + return + } + + // otherwise, use default flow + m.GetResponse(w, key) + default: + w.WriteHeader(http.StatusNotImplemented) + } + } +} + func (m *EventMeshMock) Stop() { m.server.Close() }