Skip to content

Commit

Permalink
handle error case for refUpdated event translation
Browse files Browse the repository at this point in the history
Signed-off-by: Jalander Ramagiri <[email protected]>
  • Loading branch information
Jalander Ramagiri committed Aug 9, 2024
1 parent 790cd85 commit 8ca1fb5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 40 deletions.
80 changes: 40 additions & 40 deletions pkg/gerrit/event_test.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
package gerrit

import (
"net/http"
"os"
"testing"
)

func TestHandleTranslateProjectCreatedEvent(t *testing.T) {
event, err := os.ReadFile("testdata/project-created.json")
if err != nil {
t.Fatalf("Failed to read project-created.json file: %v", err)
}
headers := http.Header{}
headers.Set("X-Origin-Url", "http://gerrit.est.tech")

cdEvent, err := HandleTranslateGerritEvent(string(event), headers)
if err != nil {
t.Errorf("Expected RepositoryCreated CDEvent to be successful.")
return
}
Log().Info("Handle project-created gerrit event into dev.cdevents.repository.created is successful ", cdEvent)
}

func TestHandleTranslateProjectHeadUpdatedEvent(t *testing.T) {

event, err := os.ReadFile("testdata/project-head-updated.json")
if err != nil {
t.Fatalf("Failed to read project-head-updated.json file: %v", err)
}
headers := http.Header{}
headers.Set("X-Origin-Url", "http://gerrit.est.tech")

cdEvent, err := HandleTranslateGerritEvent(string(event), headers)
if err != nil {
t.Errorf("Expected RepositoryModified CDEvent to be successful.")
return
}
Log().Info("Handle project-head-updated gerrit event into dev.cdevents.repository.modified is successful ", cdEvent)
}
package gerrit

import (
"net/http"
"os"
"testing"
)

func TestHandleTranslateProjectCreatedEvent(t *testing.T) {
event, err := os.ReadFile("testdata/project-created.json")
if err != nil {
t.Fatalf("Failed to read project-created.json file: %v", err)
}
headers := http.Header{}
headers.Set("X-Origin-Url", "http://gerrit.est.tech")

cdEvent, err := HandleTranslateGerritEvent(string(event), headers)
if err != nil {
t.Errorf("Expected RepositoryCreated CDEvent to be successful.")
return
}
Log().Info("Handle project-created gerrit event into dev.cdevents.repository.created is successful ", cdEvent)
}

func TestHandleTranslateProjectHeadUpdatedEvent(t *testing.T) {

event, err := os.ReadFile("testdata/project-head-updated.json")
if err != nil {
t.Fatalf("Failed to read project-head-updated.json file: %v", err)
}
headers := http.Header{}
headers.Set("X-Origin-Url", "http://gerrit.est.tech")

cdEvent, err := HandleTranslateGerritEvent(string(event), headers)
if err != nil {
t.Errorf("Expected RepositoryModified CDEvent to be successful.")
return
}
Log().Info("Handle project-head-updated gerrit event into dev.cdevents.repository.modified is successful ", cdEvent)
}
3 changes: 3 additions & 0 deletions pkg/gerrit/translate_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func (pEvent *GerritEvent) HandleRefUpdatedEvent() (string, error) {
return "", err
}
Log().Info("Translated ref-updated gerrit event into dev.cdevents.branch.deleted CDEvent: ", cdEvent)
} else {
Log().Info("Ignoring handling ref-updated gerrit event for refName : ", refUpdated.RefUpdate.RefName)
return "", errors.New("ignoring translating ref-updated gerrit event")
}

return cdEvent, nil
Expand Down

0 comments on commit 8ca1fb5

Please sign in to comment.