-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1287caf
commit 74cc1c0
Showing
4 changed files
with
168 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,16 +288,77 @@ func TestNewRepoSpecFromUrl_Smoke(t *testing.T) { | |
}, | ||
{ | ||
name: "t15", | ||
input: "https://github.com/kubernetes-sigs/kustomize//examples/multibases/dev/?submodules=0&ref=v1.0.6&timeout=300", | ||
cloneSpec: "https://github.com/kubernetes-sigs/kustomize.git", | ||
absPath: notCloned.Join("/examples/multibases/dev"), | ||
repoSpec: RepoSpec{ | ||
Host: "https://github.com/", | ||
OrgRepo: "kubernetes-sigs/kustomize", | ||
Path: "/examples/multibases/dev/", | ||
Ref: "v1.0.6", | ||
GitSuffix: ".git", | ||
}, | ||
}, | ||
{ | ||
name: "t16", | ||
input: "file://a/b/c/someRepo.git/somepath?ref=someBranch", | ||
cloneSpec: "file://a/b/c/someRepo.git", | ||
absPath: notCloned.Join("somepath"), | ||
repoSpec: RepoSpec{ | ||
Host: "file://a/b/c/someRepo.git", | ||
OrgRepo: "", | ||
Host: "file://", | ||
OrgRepo: "a/b/c/someRepo", | ||
Path: "somepath", | ||
Ref: "someBranch", | ||
GitSuffix: ".git", | ||
}, | ||
}, | ||
{ | ||
name: "t17", | ||
input: "file://a/b/c/someRepo//somepath?ref=someBranch", | ||
cloneSpec: "file://a/b/c/someRepo", | ||
absPath: notCloned.Join("somepath"), | ||
repoSpec: RepoSpec{ | ||
Host: "file://", | ||
OrgRepo: "a/b/c/someRepo", | ||
Path: "somepath", | ||
Ref: "someBranch", | ||
}, | ||
}, | ||
{ | ||
name: "t18", | ||
input: "file://a/b/c/someRepo?ref=someBranch", | ||
cloneSpec: "file://a/b/c/someRepo", | ||
absPath: notCloned.String(), | ||
repoSpec: RepoSpec{ | ||
Host: "file://", | ||
OrgRepo: "a/b/c/someRepo", | ||
Ref: "someBranch", | ||
}, | ||
}, | ||
{ | ||
name: "t19", | ||
input: "file:///a/b/c/someRepo?ref=someBranch", | ||
cloneSpec: "file:///a/b/c/someRepo", | ||
absPath: notCloned.String(), | ||
repoSpec: RepoSpec{ | ||
Host: "file://", | ||
OrgRepo: "/a/b/c/someRepo", | ||
Ref: "someBranch", | ||
}, | ||
}, | ||
{ | ||
name: "t20", | ||
input: "ssh://[email protected]/kubernetes-sigs/kustomize//examples/multibases/dev?ref=v1.0.6", | ||
cloneSpec: "[email protected]:kubernetes-sigs/kustomize.git", | ||
absPath: notCloned.Join("examples/multibases/dev"), | ||
repoSpec: RepoSpec{ | ||
Host: "[email protected]:", | ||
OrgRepo: "kubernetes-sigs/kustomize", | ||
Path: "/examples/multibases/dev", | ||
Ref: "v1.0.6", | ||
GitSuffix: ".git", | ||
}, | ||
}, | ||
} | ||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import ( | |
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"sigs.k8s.io/kustomize/api/krusty" | ||
"sigs.k8s.io/kustomize/api/loader" | ||
"sigs.k8s.io/kustomize/api/resmap" | ||
"sigs.k8s.io/kustomize/kyaml/filesys" | ||
"sigs.k8s.io/kustomize/kyaml/yaml" | ||
|
@@ -107,6 +108,7 @@ spec: | |
- image: nginx:1.7.9 | ||
name: nginx | ||
` | ||
var simpleBuildWithNginx2 = strings.ReplaceAll(simpleBuild, "nginx:1.7.9", "nginx:2") | ||
var multibaseDevExampleBuild = strings.ReplaceAll(simpleBuild, "myapp-pod", "dev-myapp-pod") | ||
|
||
repos := createGitRepos(t) | ||
|
@@ -140,7 +142,7 @@ resources: | |
- "file://$ROOT/simple.git?ref=change-image" | ||
`, | ||
|
||
expected: strings.ReplaceAll(simpleBuild, "nginx:1.7.9", "nginx:2"), | ||
expected: simpleBuildWithNginx2, | ||
}, | ||
{ | ||
// Version is the same as ref | ||
|
@@ -149,13 +151,29 @@ resources: | |
resources: | ||
- file://$ROOT/simple.git?version=change-image | ||
`, | ||
expected: strings.ReplaceAll(simpleBuild, "nginx:1.7.9", "nginx:2"), | ||
expected: simpleBuildWithNginx2, | ||
}, | ||
{ | ||
name: "has submodule", | ||
kustomization: ` | ||
resources: | ||
- file://$ROOT/with-submodule.git/submodule | ||
`, | ||
expected: simpleBuild, | ||
}, | ||
{ | ||
name: "has timeout", | ||
kustomization: ` | ||
resources: | ||
- file://$ROOT/simple.git?timeout=500 | ||
`, | ||
expected: simpleBuild, | ||
}, | ||
{ | ||
name: "triple slash absolute path", | ||
kustomization: ` | ||
resources: | ||
- file:///$ROOT/simple.git | ||
`, | ||
expected: simpleBuild, | ||
}, | ||
|
@@ -165,7 +183,7 @@ resources: | |
resources: | ||
- file://$ROOT/with-submodule.git/submodule?submodules=0 | ||
`, | ||
err: "unable to find", | ||
err: "unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization' in directory", | ||
}, | ||
{ | ||
name: "has origin annotation", | ||
|
@@ -192,10 +210,10 @@ spec: | |
`, | ||
}, | ||
{ | ||
name: "has ref path and origin annotation", | ||
name: "has ref path timeout and origin annotation", | ||
kustomization: ` | ||
resources: | ||
- file://$ROOT/multibase.git/dev?version=main | ||
- file://$ROOT/multibase.git/dev?version=main&timeout=500 | ||
buildMetadata: [originAnnotations] | ||
`, | ||
expected: `apiVersion: v1 | ||
|
@@ -215,6 +233,14 @@ spec: | |
name: nginx | ||
`, | ||
}, | ||
{ | ||
name: "repo does not exist ", | ||
kustomization: ` | ||
resources: | ||
- file:///not/a/real/repo | ||
`, | ||
err: "fatal: '/not/a/real/repo' does not appear to be a git repository", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
|
@@ -248,17 +274,26 @@ spec: | |
|
||
func TestRemoteLoad_RemoteProtocols(t *testing.T) { | ||
// Slow remote tests with long timeouts. | ||
// TODO: Maybe they should retry too. | ||
// TODO: If these end up flaking, they should retry. If not, remove this TODO. | ||
tests := []struct { | ||
name string | ||
kustomization string | ||
err string | ||
errT error | ||
beforeTest func(t *testing.T, ) | ||
}{ | ||
{ | ||
name: "https", | ||
kustomization: ` | ||
resources: | ||
- https://github.com/kubernetes-sigs/kustomize//examples/multibases/dev/?submodules=0&ref=v1.0.6&timeout=300 | ||
- https://github.com/kubernetes-sigs/kustomize//examples/multibases/dev/?submodules=0&ref=kustomize%2Fv4.5.7&timeout=300 | ||
`, | ||
}, | ||
{ | ||
name: "git double-colon https", | ||
kustomization: ` | ||
resources: | ||
- git::https://github.com/kubernetes-sigs/kustomize//examples/multibases/dev/?submodules=0&ref=kustomize%2Fv4.5.7&timeout=300 | ||
`, | ||
}, | ||
{ | ||
|
@@ -270,17 +305,53 @@ namePrefix: dev- | |
`, | ||
}, | ||
{ | ||
name: "ssh", | ||
name: "ssh", | ||
beforeTest: configureGitSSHCommand, | ||
kustomization: ` | ||
resources: | ||
- ssh://[email protected]/kubernetes-sigs/kustomize/examples/multibases/dev?submodules=0&ref=v1.0.6&timeout=300 | ||
- [email protected]/kubernetes-sigs/kustomize/examples/multibases/dev?submodules=0&ref=kustomize%2Fv4.5.7&timeout=300 | ||
`, | ||
}, | ||
{ | ||
name: "ssh with colon", | ||
beforeTest: configureGitSSHCommand, | ||
kustomization: ` | ||
resources: | ||
- [email protected]:kubernetes-sigs/kustomize/examples/multibases/dev?submodules=0&ref=kustomize%2Fv4.5.7&timeout=300 | ||
`, | ||
}, | ||
{ | ||
name: "ssh without username", | ||
beforeTest: configureGitSSHCommand, | ||
kustomization: ` | ||
resources: | ||
- github.com/kubernetes-sigs/kustomize/examples/multibases/dev?submodules=0&ref=kustomize%2Fv4.5.7&timeout=300 | ||
`, | ||
}, | ||
{ | ||
name: "ssh scheme", | ||
beforeTest: configureGitSSHCommand, | ||
kustomization: ` | ||
resources: | ||
- ssh://[email protected]/kubernetes-sigs/kustomize/examples/multibases/dev?submodules=0&ref=kustomize%2Fv4.5.7&timeout=300 | ||
`, | ||
}, | ||
{ | ||
name: "http error", | ||
kustomization: ` | ||
resources: | ||
- https://github.com/thisisa404.yaml | ||
`, | ||
err: "accumulating resources: accumulating resources from 'https://github.com/thisisa404.yaml': HTTP Error: status code 404 (Not Found)", | ||
errT: loader.ErrHTTP, | ||
}, | ||
} | ||
|
||
configureGitSSHCommand(t) | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
if test.beforeTest != nil { | ||
test.beforeTest(t) | ||
} | ||
fSys, tmpDir := createKustDir(t, test.kustomization) | ||
|
||
b := krusty.MakeKustomizer(krusty.MakeDefaultOptions()) | ||
|
@@ -293,6 +364,9 @@ resources: | |
if err != nil { | ||
assert.Contains(t, err.Error(), test.err) | ||
} | ||
if test.errT != nil { | ||
assert.ErrorIs(t, err, test.errT) | ||
} | ||
} else { | ||
assert.NoError(t, err) | ||
if err == nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters