Skip to content

Commit

Permalink
test: add tests to exercise search function
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestelfer committed Oct 25, 2023
1 parent 5f92bbb commit a704080
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion internal/scm/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,38 @@ func Test_GetRepositories(t *testing.T) {
"created_at": "2020-01-03T16:49:16Z"
}
]`,
"/search/repositories": `{
"total_count": 1,
"incomplete_results": false,
"items": [
{
"id": 3,
"name": "search-repo1",
"full_name": "lindell/search-repo1",
"private": false,
"topics": [
"backend",
"go"
],
"owner": {
"login": "lindell",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/lindell/search-repo1",
"fork": true,
"archived": false,
"disabled": false,
"default_branch": "main",
"permissions": {
"admin": true,
"push": true,
"pull": true
},
"created_at": "2020-01-03T16:49:16Z"
}
]
}`,
},
}

Expand Down Expand Up @@ -205,6 +237,25 @@ func Test_GetRepositories(t *testing.T) {
}
}

// Repo search
{
gh, err := github.New(github.Config{
TransportMiddleware: transport.Wrapper,
RepoListing: github.RepositoryListing{
RepositorySearch: "search-string",
},
MergeTypes: []scm.MergeType{scm.MergeTypeMerge},
})
require.NoError(t, err)

repos, err := gh.GetRepositories(context.Background())
assert.NoError(t, err)
if assert.Len(t, repos, 1) {
assert.Equal(t, "main", repos[0].DefaultBranch())
assert.Equal(t, "lindell/search-repo1", repos[0].FullName())
}
}

// Multiple
{
gh, err := github.New(github.Config{
Expand All @@ -218,18 +269,20 @@ func Test_GetRepositories(t *testing.T) {
Name: "test1",
},
},
RepositorySearch: "test-search",
},
MergeTypes: []scm.MergeType{scm.MergeTypeMerge},
})
require.NoError(t, err)

repos, err := gh.GetRepositories(context.Background())
assert.NoError(t, err)
if assert.Len(t, repos, 2) {
if assert.Len(t, repos, 3) {
assert.Equal(t, "master", repos[0].DefaultBranch())
assert.Equal(t, "test-org/test1", repos[0].FullName())
assert.Equal(t, "main", repos[1].DefaultBranch())
assert.Equal(t, "lindell/test2", repos[1].FullName())
assert.Equal(t, "lindell/search-repo1", repos[2].FullName())
}
}

Expand Down

0 comments on commit a704080

Please sign in to comment.