Skip to content

Commit

Permalink
Add test cases for repo git edge mutators
Browse files Browse the repository at this point in the history
  • Loading branch information
migueleliasweb committed Apr 6, 2022
1 parent f568ce7 commit 1cba4e2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/gen/gen_mutations.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
var enabledMutators = map[string]func(ScrapeResult) ScrapeResult{
"/repos/{owner}/{repo}/contents/{path}": allowExtendedLastParamMutatorHelper(),
"/repos/{owner}/{repo}/git/ref/{ref}": allowExtendedLastParamMutatorHelper(),
"/repos/{owner}/{repo}/git/refs/{ref}": allowExtendedLastParamMutatorHelper(), //thanks for the consistency, GitHub
"/repos/{owner}/{repo}/git/refs/{ref}": allowExtendedLastParamMutatorHelper(), // thanks for the consistency, GitHub
}

// allowExtendedLastParamMutatorHelper mutates the last param of the endpoint pattern
Expand Down
66 changes: 65 additions & 1 deletion src/mock/endpointpattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/google/go-github/v41/github"
)

func TestRepoGetContents2(t *testing.T) {
func TestRepoGetContents(t *testing.T) {
cases := []struct {
name string
repositoryContent github.RepositoryContent
Expand Down Expand Up @@ -70,3 +70,67 @@ func TestRepoGetContents2(t *testing.T) {
}(c.repositoryContent))
}
}

func TestPatchGitReference(t *testing.T) {
mockedHTTPClient := NewMockedHTTPClient(
WithRequestMatch(
PatchReposGitRefsByOwnerByRepoByRef,
github.Reference{
Ref: github.String("refs/heads/new-branch"),
},
),
)

c := github.NewClient(mockedHTTPClient)

ctx := context.Background()

ref, _, _ := c.Git.UpdateRef(
ctx,
"owner",
"repo-name",
&github.Reference{
Ref: github.String("refs/heads/new-branch"),
Object: &github.GitObject{SHA: github.String("fake-sha")},
},
false,
)

if *(ref.Ref) != "refs/heads/new-branch" {
t.Errorf(
"ref.Ref is %s, want %s",
*ref.Ref,
"refs/heads/new-branch",
)
}
}

func TestGetGitReference(t *testing.T) {
mockedHTTPClient := NewMockedHTTPClient(
WithRequestMatch(
GetReposGitRefByOwnerByRepoByRef,
github.Reference{
Ref: github.String("refs/heads/new-branch"),
},
),
)

c := github.NewClient(mockedHTTPClient)

ctx := context.Background()

ref, _, _ := c.Git.GetRef(
ctx,
"owner",
"repo-name",
"refs/heads/new-branch",
)

if *(ref.Ref) != "refs/heads/new-branch" {
t.Errorf(
"ref.Ref is %s, want %s",
*ref.Ref,
"refs/heads/new-branch",
)
}
}

0 comments on commit 1cba4e2

Please sign in to comment.