Skip to content

Commit 425273c

Browse files
committed
Fix up the remaining tests.
1 parent 3dc82fd commit 425273c

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

pkg/gitfs/gitfs_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"io/ioutil"
55
"testing"
66

7-
"github.com/go-git/go-git/v5"
87
"github.com/google/go-cmp/cmp"
98
"sigs.k8s.io/kustomize/pkg/fs"
9+
10+
"github.com/rhd-gitops-example/gitops-backend/test"
1011
)
1112

1213
var _ fs.FileSystem = gitFS{}
@@ -105,9 +106,7 @@ func TestNewInMemoryFromOptions(t *testing.T) {
105106
func makeClonedGFS(t *testing.T) fs.FileSystem {
106107
t.Helper()
107108
gfs, err := NewInMemoryFromOptions(
108-
&git.CloneOptions{
109-
URL: "../../",
110-
})
109+
test.MakeCloneOptions())
111110
assertNoError(t, err)
112111
return gfs
113112
}

pkg/parser/parser_test.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package parser
22

33
import (
4-
"os"
54
"sort"
65
"strings"
76
"testing"
87

98
"github.com/go-git/go-git/v5"
10-
"github.com/go-git/go-git/v5/plumbing"
119
"github.com/google/go-cmp/cmp"
10+
11+
"github.com/rhd-gitops-example/gitops-backend/test"
1212
)
1313

1414
const (
@@ -39,7 +39,7 @@ func resKey(r *Resource) string {
3939
func TestParseFromGit(t *testing.T) {
4040
res, err := ParseFromGit(
4141
"pkg/parser/testdata/go-demo",
42-
makeCloneOptions())
42+
test.MakeCloneOptions())
4343
if err != nil {
4444
t.Fatal(err)
4545
}
@@ -135,16 +135,3 @@ func assertCmp(t *testing.T, want, got interface{}, msg string) {
135135
t.Fatalf(msg+":\n%s", diff)
136136
}
137137
}
138-
139-
// If running in Travis, ensure that it's using the correct branch.
140-
func makeCloneOptions() *git.CloneOptions {
141-
o := &git.CloneOptions{
142-
URL: "../..",
143-
Depth: 1,
144-
}
145-
if b := os.Getenv("TRAVIS_PULL_REQUEST_BRANCH"); b != "" {
146-
o.ReferenceName = plumbing.NewBranchReferenceName(b)
147-
o.URL = "https://github.com/rhd-gitops-example/gitops-backend.git"
148-
}
149-
return o
150-
}

test/clone_options.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package test
2+
3+
import (
4+
"os"
5+
6+
"github.com/go-git/go-git/v5"
7+
"github.com/go-git/go-git/v5/plumbing"
8+
)
9+
10+
// MakeCloneOptions determines if we are running in Travis,
11+
// and ensures that it's using the correct branch.
12+
func MakeCloneOptions() *git.CloneOptions {
13+
o := &git.CloneOptions{
14+
URL: "../..",
15+
Depth: 1,
16+
}
17+
if b := os.Getenv("TRAVIS_PULL_REQUEST_BRANCH"); b != "" {
18+
o.ReferenceName = plumbing.NewBranchReferenceName(b)
19+
o.URL = "https://github.com/rhd-gitops-example/gitops-backend.git"
20+
}
21+
return o
22+
}

0 commit comments

Comments
 (0)