Skip to content

Commit

Permalink
add tests for file:// without git suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
mightyguava committed Sep 11, 2022
1 parent 0963a2a commit 92d3031
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
9 changes: 4 additions & 5 deletions api/internal/git/repospec.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,12 @@ func parseGitURL(n string) (
if idx := strings.Index(n, "//"); idx > 0 {
orgRepo = n[:idx]
n = n[idx+2:]
} else if q := strings.Index(n, "?"); q != -1 {
orgRepo = n[:q]
n = n[q:]
} else {
orgRepo = n
path, gitRef, gitTimeout, gitSubmodules = peelQuery(n)
return
}
path, gitRef, gitTimeout, gitSubmodules = peelQuery(n)
orgRepo = path
path = ""
return
}

Expand Down
10 changes: 10 additions & 0 deletions api/internal/git/repospec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,16 @@ func TestNewRepoSpecFromUrl_Smoke(t *testing.T) {
GitSuffix: ".git",
},
},
{
name: "t21",
input: "file:///a/b/c/someRepo",
cloneSpec: "file:///a/b/c/someRepo",
absPath: notCloned.String(),
repoSpec: RepoSpec{
Host: "file://",
OrgRepo: "/a/b/c/someRepo",
},
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
23 changes: 22 additions & 1 deletion api/krusty/remoteloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ func TestRemoteLoad_LocalProtocol(t *testing.T) {
type testRepos struct {
root string
simple string
noSuffix string
multiBaseDev string
withSubmodule string
}

// creates git repos under a root temporary directory with the following structure
// root/
// simple.git/ - base with just a pod
// nosuffix/ - same as simple.git/ without the .git suffix
// multibase.git/ - base with a dev overlay
// with-submodule.git/ - includes `simple` as a submodule
// submodule/ - the submodule referencing `simple
Expand Down Expand Up @@ -74,6 +76,7 @@ EOF
git commit -am "image change"
git checkout main
)
cp -r $ROOT/simple.git $ROOT/nosuffix
cp -r testdata/remoteload/multibase $ROOT/multibase.git
(
cd $ROOT/multibase.git
Expand All @@ -90,8 +93,10 @@ cp -r testdata/remoteload/multibase $ROOT/multibase.git
)
`, root))
return testRepos{
root: root,
root: root,
// The strings below aren't currently used, and more serve as documentation.
simple: "simple.git",
noSuffix: "nosuffix",
multiBaseDev: "multibase.git",
withSubmodule: "with-submodule.git",
}
Expand Down Expand Up @@ -124,6 +129,14 @@ spec:
kustomization: `
resources:
- file://$ROOT/simple.git
`,
expected: simpleBuild,
},
{
name: "without git suffix",
kustomization: `
resources:
- file://$ROOT/nosuffix
`,
expected: simpleBuild,
},
Expand All @@ -132,6 +145,14 @@ resources:
kustomization: `
resources:
- file://$ROOT/multibase.git/dev
`,
expected: multibaseDevExampleBuild,
},
{
name: "has path without git suffix",
kustomization: `
resources:
- file://$ROOT/multibase//dev
`,
expected: multibaseDevExampleBuild,
},
Expand Down

0 comments on commit 92d3031

Please sign in to comment.