Skip to content

Commit

Permalink
Add test for issue #5131
Browse files Browse the repository at this point in the history
  • Loading branch information
annasong20 committed Jun 4, 2023
1 parent 0add0f9 commit 077c2b4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
29 changes: 25 additions & 4 deletions api/krusty/remoteloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestRemoteLoad_LocalProtocol(t *testing.T) {
// 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
// submodule/ - the submodule referencing `simple`
createGitRepos := func(t *testing.T) testRepos {
t.Helper()

Expand Down Expand Up @@ -85,12 +85,20 @@ cp -r testdata/remoteload/multibase $ROOT/multibase.git
git add .
git commit -m "import"
)
cp -r testdata/remoteload/with-submodule $ROOT/with-submodule.git # see README
export HASH_DIR=unique-$RANDOM
cp -r $ROOT/simple.git $ROOT/$HASH_DIR
(
mkdir $ROOT/with-submodule.git
cd $ROOT/with-submodule.git
git init --initial-branch=main
git submodule add $ROOT/simple.git submodule
git add .
git commit -m "import"
git checkout -b relative-submodule
git submodule add ../$HASH_DIR submodule
git commit -m "relative submodule"
git checkout main
git submodule add $ROOT/simple.git submodule
git commit -m "submodule"
)
`, root))
return testRepos{
Expand Down Expand Up @@ -183,6 +191,15 @@ resources:
`,
expected: simpleBuild,
},
{
name: "has relative submodule",
kustomization: `
resources:
- file://$ROOT/with-submodule.git/submodule?ref=relative-submodule
`,
// TODO(annasong): Replace with simpleBuild once #5131 is fixed.
err: `failed to run '\S+/git submodule update --init --recursive': warning: could not look up configuration 'remote.origin.url'. Assuming this repository is its own authoritative upstream`,
},
{
name: "has timeout",
kustomization: `
Expand Down Expand Up @@ -273,7 +290,7 @@ resources:

if test.err != "" {
require.Error(t, err)
require.Contains(t, err.Error(), test.err)
require.Regexp(t, test.err, err.Error())
} else {
require.NoError(t, err)
checkYaml(t, m, strings.ReplaceAll(test.expected, "$ROOT", repos.root))
Expand Down Expand Up @@ -430,6 +447,10 @@ func createKustDir(t *testing.T, content string) (filesys.FileSystem, filesys.Co
fSys := filesys.MakeFsOnDisk()
tmpDir, err := filesys.NewTmpConfirmedDir()
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
})

require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(content)))
return fSys, tmpDir
}
Expand Down
10 changes: 10 additions & 0 deletions api/krusty/testdata/remoteload/with-submodule/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# submodule

This repo demonstrates kustomize's ability to download git repos
with submodules. The following branches contain
* main: submodule via absolute path
* relative-submodule: submodule via relative path

For the submodule accessed via a relative path, we include a random hash in the
submodule name to avoid accessing an unintended directory in the case kustomize
contains loader bugs (issue #5131).

0 comments on commit 077c2b4

Please sign in to comment.