Skip to content

Commit

Permalink
Fix e2e job NATS Install step (kyma-project#379)
Browse files Browse the repository at this point in the history
* Fix e2e job NATS Install step

* Fix magic number linting errors
  • Loading branch information
muralov authored and friedrichwilken committed Jan 16, 2024
1 parent b784090 commit abc8df7
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
5 changes: 5 additions & 0 deletions hack/ci/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
87 changes: 87 additions & 0 deletions testing/eventmeshmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>`
// 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()
}
Expand Down

0 comments on commit abc8df7

Please sign in to comment.