Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
- Update upstream API endpoint

- Update golden files

- Compare list using string to ease debugging
  • Loading branch information
shihanng committed Jan 21, 2022
1 parent 87d44e9 commit 4f2ad4a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
18 changes: 9 additions & 9 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build integration
//go:build integration

package main

Expand All @@ -24,13 +24,13 @@ type MainTestSuite struct {
tempDir string
}

func (s *MainTestSuite) SetupSuite() {
func (s *MainTestSuite) SetupTest() {
dir, err := ioutil.TempDir("", "gig")
s.Require().NoError(err)
s.tempDir = dir
}

func (s *MainTestSuite) TearDownSuite() {
func (s *MainTestSuite) TearDownTest() {
s.Require().NoError(os.RemoveAll(s.tempDir))
}

Expand All @@ -55,7 +55,7 @@ func (s *MainTestSuite) TestGen() {
func (s *MainTestSuite) TestCheckGitIgnoreIO() {
// Testing against "reactnative", "mean" is avoided because the result for stack from
// gitignore.io seems not in order.
resp, err := http.Get(`https://www.gitignore.io/api/django,androidstudio,java,go,ada,zsh,c,gradle`)
resp, err := http.Get(`https://www.toptal.com/developers/gitignore/api/django,androidstudio,java,go,ada,zsh,c,gradle`)
s.Require().NoError(err)

defer resp.Body.Close()
Expand All @@ -70,7 +70,7 @@ func (s *MainTestSuite) TestCheckGitIgnoreIO() {

content := scanner.Text()

if strings.HasPrefix(content, `# End of https://www.gitignore.io/api/`) {
if strings.HasPrefix(content, `# End of https://www.toptal.com/developers/gitignore/api/django,androidstudio,java,go,ada,zsh,c,gradle`) {
break
}

Expand All @@ -92,23 +92,23 @@ func (s *MainTestSuite) TestCheckGitIgnoreIO() {
}

func (s *MainTestSuite) TestList() {
resp, err := http.Get(`https://www.gitignore.io/api/list`)
resp, err := http.Get(`https://www.toptal.com/developers/gitignore/api/list`)
s.Require().NoError(err)

defer resp.Body.Close()

expected, err := ioutil.ReadAll(resp.Body)
s.Require().NoError(err)

expectedS := bytes.Split(bytes.ReplaceAll(expected, []byte(","), []byte("\n")), []byte("\n"))
expectedS := strings.Split(strings.ReplaceAll(string(expected), ",", "\n"), "\n")

os.Args = []string{"gig", "--cache-path", s.tempDir, "-c", "640f03b1f9906c5dcb788d36ec5c1095264a10ae", "list"}
os.Args = []string{"gig", "--cache-path", s.tempDir, "list"}

actual := new(bytes.Buffer)

cmd.Execute(actual, "test")

actualS := bytes.Split(bytes.ToLower(actual.Bytes()), []byte("\n"))
actualS := strings.Split(strings.ToLower(actual.String()), "\n")
actualS = actualS[:len(actualS)-1]

s.Assert().Equal(expectedS, actualS)
Expand Down
6 changes: 6 additions & 0 deletions testdata/autogen.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

### Go ###
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
Expand All @@ -16,6 +19,9 @@
# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

### Go Patch ###
/vendor/
/Godeps/
Expand Down
6 changes: 6 additions & 0 deletions testdata/gen.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

### Go ###
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
Expand All @@ -16,6 +19,9 @@
# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

### Go Patch ###
/vendor/
/Godeps/

0 comments on commit 4f2ad4a

Please sign in to comment.