MCPcopy Create free account
hub / github.com/cli/cli / TestGitIgnoreTemplateReturnsGitIgnoreTemplate

Function TestGitIgnoreTemplateReturnsGitIgnoreTemplate

api/queries_repo_test.go:1207–1236  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1205}
1206
1207func TestGitIgnoreTemplateReturnsGitIgnoreTemplate(t *testing.T) {
1208 gitIgnoreTemplateName := "Go"
1209 httpStubs := func(reg *httpmock.Registry) {
1210 reg.Register(
1211 httpmock.REST("GET", fmt.Sprintf("gitignore/templates/%v", gitIgnoreTemplateName)),
1212 httpmock.StringResponse(`{
1213 "name": "Go",
1214 "source": "# If you prefer the allow list template instead of the deny list, see community template:\n# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore\n#\n# Binaries for programs and plugins\n*.exe\n*.exe~\n*.dll\n*.so\n*.dylib\n\n# Test binary, built with go test -c\n*.test\n\n# Output of the go coverage tool, specifically when used with LiteIDE\n*.out\n\n# Dependency directories (remove the comment below to include it)\n# vendor/\n\n# Go workspace file\ngo.work\ngo.work.sum\n\n# env file\n.env\n"
1215 }`,
1216 ))
1217 }
1218 wantGitIgnoreTemplate := &GitIgnore{
1219 Name: "Go",
1220 Source: "# If you prefer the allow list template instead of the deny list, see community template:\n# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore\n#\n# Binaries for programs and plugins\n*.exe\n*.exe~\n*.dll\n*.so\n*.dylib\n\n# Test binary, built with go test -c\n*.test\n\n# Output of the go coverage tool, specifically when used with LiteIDE\n*.out\n\n# Dependency directories (remove the comment below to include it)\n# vendor/\n\n# Go workspace file\ngo.work\ngo.work.sum\n\n# env file\n.env\n",
1221 }
1222
1223 reg := &httpmock.Registry{}
1224 httpStubs(reg)
1225
1226 httpClient := func() (*http.Client, error) {
1227 return &http.Client{Transport: reg}, nil
1228 }
1229 client, _ := httpClient()
1230 defer reg.Verify(t)
1231
1232 gotGitIgnoreTemplate, err := RepoGitIgnoreTemplate(client, "api.github.com", gitIgnoreTemplateName)
1233
1234 assert.NoError(t, err, fmt.Sprintf("Expected no error while fetching /gitignore/templates/%v", gitIgnoreTemplateName))
1235 assert.Equal(t, wantGitIgnoreTemplate, gotGitIgnoreTemplate, fmt.Sprintf("GitIgnore template \"%v\" fetched is not as expected", gitIgnoreTemplateName))
1236}
1237
1238func TestGitIgnoreTemplateReturnsErrorWhenGitIgnoreTemplateNotFound(t *testing.T) {
1239 gitIgnoreTemplateName := "invalid-gitignore"

Callers

nothing calls this directly

Calls 7

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
StringResponseFunction · 0.92
RepoGitIgnoreTemplateFunction · 0.85
EqualMethod · 0.80
httpClientInterface · 0.50

Tested by

no test coverage detected