Skip to content

Commit

Permalink
feat: fixed harness UTs based on new API convention (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
hitesharinga committed Apr 17, 2024
1 parent 845e445 commit 1255b15
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 24 deletions.
30 changes: 25 additions & 5 deletions scm/driver/harness/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ func TestContentFind(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/content/README.md").
Get("/gateway/code/api/v1/repos/thomas/content/README.md").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("plain/text").
File("testdata/content.json")
Expand Down Expand Up @@ -68,7 +72,11 @@ func TestContentCreate(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Post("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/commits").
Post("/gateway/code/api/v1/repos/thomas/commits").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("plain/text").
BodyString("{\"commit_id\":\"20ecde1f8c277da0e91750bef9f3b88f228d86db\"}")
Expand Down Expand Up @@ -105,7 +113,11 @@ func TestContentUpdate(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Post("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/commits").
Post("/gateway/code/api/v1/repos/thomas/commits").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("plain/text").
BodyString("{\"commit_id\":\"20ecde1f8c277da0e91750bef9f3b88f228d86db\"}")
Expand Down Expand Up @@ -143,7 +155,11 @@ func TestContentDelete(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Post("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/commits").
Post("/gateway/code/api/v1/repos/thomas/commits").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("plain/text").
BodyString("{\"commit_id\":\"20ecde1f8c277da0e91750bef9f3b88f228d86db\"}")
Expand Down Expand Up @@ -178,7 +194,11 @@ func TestContentList(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/content/docker").
Get("/gateway/code/api/v1/repos/thomas/content/docker").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("application/json").
File("testdata/content_list.json")
Expand Down
36 changes: 30 additions & 6 deletions scm/driver/harness/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ func TestListCommits(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/commits").
Get("/gateway/code/api/v1/repos/thomas/commits").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("application/json").
File("testdata/commits.json")
Expand Down Expand Up @@ -66,7 +70,11 @@ func TestFindCommit(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/commits/1d640265d8bdd818175fa736f0fcbad2c9b716c9").
Get("/gateway/code/api/v1/repos/thomas/commits/1d640265d8bdd818175fa736f0fcbad2c9b716c9").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("application/json").
File("testdata/commit.json")
Expand Down Expand Up @@ -104,7 +112,11 @@ func TestFindBranch(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/branches/main").
Get("/gateway/code/api/v1/repos/thomas/branches/main").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("application/json").
File("testdata/branch.json")
Expand Down Expand Up @@ -142,7 +154,11 @@ func TestListBranches(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/branches").
Get("/gateway/code/api/v1/repos/thomas/branches").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("application/json").
File("testdata/branches.json")
Expand Down Expand Up @@ -180,7 +196,11 @@ func TestCreateBranch(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Post("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/branches").
Post("/gateway/code/api/v1/repos/thomas/branches").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("application/json").
File("testdata/branch.json")
Expand Down Expand Up @@ -215,7 +235,11 @@ func TestCompareChanges(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Get(fmt.Sprintf("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/diff/%s...%s", source, target)).
Get(fmt.Sprintf("/gateway/code/api/v1/repos/thomas/diff/%s...%s", source, target)).
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("application/json").
File("testdata/gitdiff.json")
Expand Down
21 changes: 17 additions & 4 deletions scm/driver/harness/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/google/go-cmp/cmp/cmpopts"
"io/ioutil"
"net/http"
"testing"

"github.com/google/go-cmp/cmp/cmpopts"

"github.com/drone/go-scm/scm"
"github.com/drone/go-scm/scm/transport"
"github.com/google/go-cmp/cmp"
Expand All @@ -24,7 +25,11 @@ func TestPRFind(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/pullreq/1").
Get("/gateway/code/api/v1/repos/thomas/pullreq/1").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("plain/text").
File("testdata/pr.json")
Expand Down Expand Up @@ -63,7 +68,11 @@ func TestPRCommits(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/pullreq/1/commits").
Get("/gateway/code/api/v1/repos/thomas/pullreq/1/commits").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("plain/text").
File("testdata/pr_commits.json")
Expand Down Expand Up @@ -100,7 +109,11 @@ func TestPRCommits(t *testing.T) {
func TestPullCreate(t *testing.T) {
defer gock.Off()
gock.New(gockOrigin).
Post("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/pullreq").
Post("/gateway/code/api/v1/repos/thomas/pullreq").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("plain/text").
File("testdata/pr.json")
Expand Down
4 changes: 1 addition & 3 deletions scm/driver/harness/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ func (s *repositoryService) CreateHook(ctx context.Context, repo string, input *
in.Secret = input.Secret
in.Insecure = input.SkipVerify
in.URL = input.Target
in.Triggers = append(
input.NativeEvents,
)
in.Triggers = input.NativeEvents
out := new(hook)
res, err := s.client.do(ctx, "POST", path, in, out)
return convertHook(out), res, err
Expand Down
36 changes: 30 additions & 6 deletions scm/driver/harness/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ func TestRepositoryFind(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/demo/+").
Get("/gateway/code/api/v1/repos/demo").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("application/json").
File("testdata/repo.json")
Expand Down Expand Up @@ -58,11 +62,15 @@ func TestRepositoryList(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Get("/gateway/code/api/v1/spaces/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/+/repos").
Get("/gateway/code/api/v1/repos").
MatchParam("page", "1").
MatchParam("limit", "20").
MatchParam("sort", "path").
MatchParam("order", "asc").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("application/json").
File("testdata/repos.json")
Expand Down Expand Up @@ -100,7 +108,11 @@ func TestRepositoryHookList(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/webhooks").
Get("/gateway/code/api/v1/repos/thomas/webhooks").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("page", "1").
MatchParam("limit", "30").
MatchParam("sort", "display_name").
Expand Down Expand Up @@ -138,7 +150,11 @@ func TestRepositoryFindHook(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/webhooks/6").
Get("/gateway/code/api/v1/repos/thomas/webhooks/6").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("application/json").
File("testdata/hook.json")
Expand Down Expand Up @@ -172,7 +188,11 @@ func TestRepositoryHookCreateDelete(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Post("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/webhooks").
Post("/gateway/code/api/v1/repos/thomas/webhooks").
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(200).
Type("application/json").
File("testdata/hook_create.json")
Expand Down Expand Up @@ -210,7 +230,11 @@ func TestRepositoryHookCreateDelete(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Delete(fmt.Sprintf("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/webhooks/%s", got.ID)).
Delete(fmt.Sprintf("/gateway/code/api/v1/repos/thomas/webhooks/%s", got.ID)).
MatchParam("accountIdentifier", "px7xd_BFRCi-pfWPYXVjvw").
MatchParam("orgIdentifier", "default").
MatchParam("projectIdentifier", "codeciintegration").
MatchParam("routingId", "px7xd_BFRCi-pfWPYXVjvw").
Reply(204)
}
client, _ = New(gockOrigin, harnessOrg, harnessAccount, harnessProject)
Expand Down

0 comments on commit 1255b15

Please sign in to comment.