mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 10:30:59 +00:00
Merge pull request #5189 from annasong20/test-relative-submodules
Add test for issue #5131
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ func TestRemoteLoad_LocalProtocol(t *testing.T) {
|
|||||||
root string
|
root string
|
||||||
simple string
|
simple string
|
||||||
noSuffix string
|
noSuffix string
|
||||||
|
hash string
|
||||||
multiBaseDev string
|
multiBaseDev string
|
||||||
withSubmodule string
|
withSubmodule string
|
||||||
}
|
}
|
||||||
@@ -35,9 +37,10 @@ func TestRemoteLoad_LocalProtocol(t *testing.T) {
|
|||||||
// root/
|
// root/
|
||||||
// simple.git/ - base with just a pod
|
// simple.git/ - base with just a pod
|
||||||
// nosuffix/ - same as simple.git/ without the .git suffix
|
// nosuffix/ - same as simple.git/ without the .git suffix
|
||||||
|
// hash-xx/ - same as simple.git/ with random hash at xx
|
||||||
// multibase.git/ - base with a dev overlay
|
// multibase.git/ - base with a dev overlay
|
||||||
// with-submodule.git/ - includes `simple` as a submodule
|
// with-submodule.git/ - includes `simple` as a submodule
|
||||||
// submodule/ - the submodule referencing `simple
|
// submodule/ - the submodule referencing `simple`
|
||||||
createGitRepos := func(t *testing.T) testRepos {
|
createGitRepos := func(t *testing.T) testRepos {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
@@ -49,10 +52,16 @@ func TestRemoteLoad_LocalProtocol(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
root := t.TempDir()
|
root := t.TempDir()
|
||||||
|
|
||||||
|
hashPath, err := os.MkdirTemp(root, "hash-")
|
||||||
|
require.NoError(t, err)
|
||||||
|
hashDir := filepath.Base(hashPath)
|
||||||
|
|
||||||
bash(fmt.Sprintf(`
|
bash(fmt.Sprintf(`
|
||||||
set -eux
|
set -eux
|
||||||
|
|
||||||
export ROOT="%s"
|
export ROOT="%s"
|
||||||
|
export HASH_DIR="%s"
|
||||||
export GIT_AUTHOR_EMAIL=nobody@kustomize.io
|
export GIT_AUTHOR_EMAIL=nobody@kustomize.io
|
||||||
export GIT_AUTHOR_NAME=Nobody
|
export GIT_AUTHOR_NAME=Nobody
|
||||||
export GIT_COMMITTER_EMAIL=nobody@kustomize.io
|
export GIT_COMMITTER_EMAIL=nobody@kustomize.io
|
||||||
@@ -84,19 +93,27 @@ cp -r testdata/remoteload/multibase $ROOT/multibase.git
|
|||||||
git add .
|
git add .
|
||||||
git commit -m "import"
|
git commit -m "import"
|
||||||
)
|
)
|
||||||
|
cp -r testdata/remoteload/with-submodule $ROOT/with-submodule.git # see README
|
||||||
|
cp -r $ROOT/simple.git/. $ROOT/$HASH_DIR
|
||||||
(
|
(
|
||||||
mkdir $ROOT/with-submodule.git
|
|
||||||
cd $ROOT/with-submodule.git
|
cd $ROOT/with-submodule.git
|
||||||
git init --initial-branch=main
|
git init --initial-branch=main
|
||||||
git submodule add $ROOT/simple.git submodule
|
git add .
|
||||||
git commit -m "import"
|
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))
|
`, root, hashDir))
|
||||||
return testRepos{
|
return testRepos{
|
||||||
root: root,
|
root: root,
|
||||||
// The strings below aren't currently used, and more serve as documentation.
|
// The strings below aren't currently used, and more serve as documentation.
|
||||||
simple: "simple.git",
|
simple: "simple.git",
|
||||||
noSuffix: "nosuffix",
|
noSuffix: "nosuffix",
|
||||||
|
hash: hashDir,
|
||||||
multiBaseDev: "multibase.git",
|
multiBaseDev: "multibase.git",
|
||||||
withSubmodule: "with-submodule.git",
|
withSubmodule: "with-submodule.git",
|
||||||
}
|
}
|
||||||
@@ -182,6 +199,15 @@ resources:
|
|||||||
`,
|
`,
|
||||||
expected: simpleBuild,
|
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'`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "has timeout",
|
name: "has timeout",
|
||||||
kustomization: `
|
kustomization: `
|
||||||
@@ -272,7 +298,7 @@ resources:
|
|||||||
|
|
||||||
if test.err != "" {
|
if test.err != "" {
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Contains(t, err.Error(), test.err)
|
require.Regexp(t, test.err, err.Error())
|
||||||
} else {
|
} else {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
checkYaml(t, m, strings.ReplaceAll(test.expected, "$ROOT", repos.root))
|
checkYaml(t, m, strings.ReplaceAll(test.expected, "$ROOT", repos.root))
|
||||||
|
|||||||
10
api/krusty/testdata/remoteload/with-submodule/README.md
vendored
Normal file
10
api/krusty/testdata/remoteload/with-submodule/README.md
vendored
Normal file
@@ -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).
|
||||||
Reference in New Issue
Block a user