Skip to content

Commit

Permalink
adding test cases for project related events
Browse files Browse the repository at this point in the history
Signed-off-by: Jalander Ramagiri <[email protected]>
  • Loading branch information
Jalander Ramagiri committed Jul 5, 2024
1 parent f783f4c commit 790cd85
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
40 changes: 40 additions & 0 deletions pkg/gerrit/event_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +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)
}
6 changes: 6 additions & 0 deletions pkg/gerrit/testdata/project-created.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projectName": "TestRepo3",
"headName": "refs/heads/master",
"type": "project-created",
"eventCreatedOn": 1700131789
}
7 changes: 7 additions & 0 deletions pkg/gerrit/testdata/project-head-updated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"projectName": "TestRepo3",
"oldHead": "refs/heads/master",
"newHead": "refs/heads/main",
"type": "project-head-updated",
"eventCreatedOn": 1700148011
}

0 comments on commit 790cd85

Please sign in to comment.