Skip to content

Commit

Permalink
🐛 Fix flaky tests in cron/data/add (#1185)
Browse files Browse the repository at this point in the history
* fix

* naming
  • Loading branch information
laurentsimon authored Oct 28, 2021
1 parent 0ba864e commit d9e35cd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cron/data/add/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ import (
"github.com/ossf/scorecard/v3/repos"
)

func isLessThanRepoURL(x, y *repos.RepoURI) bool {
return x.URL() < y.URL()
}

type fields struct {
host string
owner string
repo string
metadata []string
}

//nolint: gocritic
func lessThanURI(x, y repos.RepoURI) bool {
return fmt.Sprintf("%+v", x) < fmt.Sprintf("%+v", y)
}

func TestGetRepoURLs(t *testing.T) {
t.Parallel()
testcases := []struct {
Expand Down Expand Up @@ -135,6 +136,7 @@ func TestGetRepoURLs(t *testing.T) {
}
for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.name, func(t *testing.T) {
t.Parallel()
testFile, err := os.OpenFile(testcase.filename, os.O_RDONLY, 0o644)
Expand Down Expand Up @@ -172,8 +174,8 @@ func TestGetRepoURLs(t *testing.T) {
return true
})

if !cmp.Equal(rs, repoURLs, exp, cmpopts.EquateEmpty(), cmpopts.SortSlices(isLessThanRepoURL)) {
t.Errorf("testcase failed. expected %+v, got %+v", testcase.outcome, repoURLs)
if !cmp.Equal(rs, repoURLs, exp, cmpopts.EquateEmpty(), cmpopts.SortSlices(lessThanURI)) {
t.Errorf("testcase failed. expected %+v, got %+v", rs, repoURLs)
}
})
}
Expand Down

0 comments on commit d9e35cd

Please sign in to comment.