(t *testing.T)
| 1313 | } |
| 1314 | |
| 1315 | func TestGitIgnoreTemplateReturnsGitIgnoreTemplate(t *testing.T) { |
| 1316 | gitIgnoreTemplateName := "Go" |
| 1317 | httpStubs := func(reg *httpmock.Registry) { |
| 1318 | reg.Register( |
| 1319 | httpmock.REST("GET", fmt.Sprintf("gitignore/templates/%v", gitIgnoreTemplateName)), |
| 1320 | httpmock.StringResponse(`{ |
| 1321 | "name": "Go", |
| 1322 | "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" |
| 1323 | }`, |
| 1324 | )) |
| 1325 | } |
| 1326 | wantGitIgnoreTemplate := &GitIgnore{ |
| 1327 | Name: "Go", |
| 1328 | 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", |
| 1329 | } |
| 1330 | |
| 1331 | reg := &httpmock.Registry{} |
| 1332 | httpStubs(reg) |
| 1333 | |
| 1334 | httpClient := func() (*http.Client, error) { |
| 1335 | return &http.Client{Transport: reg}, nil |
| 1336 | } |
| 1337 | client, _ := httpClient() |
| 1338 | defer reg.Verify(t) |
| 1339 | |
| 1340 | gotGitIgnoreTemplate, err := RepoGitIgnoreTemplate(client, "api.github.com", gitIgnoreTemplateName) |
| 1341 | |
| 1342 | assert.NoError(t, err, fmt.Sprintf("Expected no error while fetching /gitignore/templates/%v", gitIgnoreTemplateName)) |
| 1343 | assert.Equal(t, wantGitIgnoreTemplate, gotGitIgnoreTemplate, fmt.Sprintf("GitIgnore template \"%v\" fetched is not as expected", gitIgnoreTemplateName)) |
| 1344 | } |
| 1345 | |
| 1346 | func TestGitIgnoreTemplateReturnsErrorWhenGitIgnoreTemplateNotFound(t *testing.T) { |
| 1347 | gitIgnoreTemplateName := "invalid-gitignore" |
nothing calls this directly
no test coverage detected