Skip to content

Commit

Permalink
fixing unstable tests (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
roi-codefresh authored May 9, 2021
1 parent 5c06187 commit 9cb7129
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions cmd/commands/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,17 @@ func TestRunRepoCreate(t *testing.T) {

orgGetProvider := getGitProvider
for tname, tt := range tests {
defer func() { getGitProvider = orgGetProvider }()
mp := &gitmocks.Provider{}
if tt.preFn != nil {
tt.preFn(mp)
getGitProvider = func(opts *git.ProviderOptions) (git.Provider, error) {
return mp, nil
t.Run(tname, func(t *testing.T) {
mp := &gitmocks.Provider{}

if tt.preFn != nil {
tt.preFn(mp)
getGitProvider = func(opts *git.ProviderOptions) (git.Provider, error) {
return mp, nil
}
defer func() { getGitProvider = orgGetProvider }()
}
}

t.Run(tname, func(t *testing.T) {
tt.assertFn(t, mp, tt.opts, RunRepoCreate(context.Background(), tt.opts))
})
}
Expand Down Expand Up @@ -198,8 +199,11 @@ func Test_validateRepo(t *testing.T) {
},
},
}

for tname, tt := range tests {
t.Run(tname, func(t *testing.T) {
t.Parallel()

repofs := fs.Create(memfs.New())
if tt.preFn != nil {
tt.preFn(t, repofs)
Expand Down Expand Up @@ -293,12 +297,14 @@ func Test_buildBootstrapManifests(t *testing.T) {
}

orgRunKustomizeBuild := runKustomizeBuild
defer func() { runKustomizeBuild = orgRunKustomizeBuild }()

for tname, tt := range tests {
t.Run(tname, func(t *testing.T) {
t.Parallel()

if tt.preFn != nil {
tt.preFn()
defer func() { runKustomizeBuild = orgRunKustomizeBuild }()
}
b, ret := buildBootstrapManifests(
tt.args.namespace,
Expand Down
2 changes: 1 addition & 1 deletion hack/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e
echo "" > coverage.txt

for d in $(go list ./... | grep -v vendor); do
go test -race -coverprofile=profile.out -covermode=atomic $d
go test -v -race -coverprofile=profile.out -covermode=atomic $d
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
Expand Down

0 comments on commit 9cb7129

Please sign in to comment.