// Copyright 2022 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0 package krusty_test import ( "bytes" "encoding/base64" "fmt" "io" "os" "os/exec" "path/filepath" "strings" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "sigs.k8s.io/kustomize/api/internal/loader" "sigs.k8s.io/kustomize/api/krusty" "sigs.k8s.io/kustomize/api/resmap" kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" "sigs.k8s.io/kustomize/kyaml/yaml" ) func TestRemoteLoad_LocalProtocol(t *testing.T) { type testRepos struct { root string simple string noSuffix string hash 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 // hash-xx/ - same as simple.git/ with random hash at xx // multibase.git/ - base with a dev overlay // with-submodule.git/ - includes `simple` as a submodule // submodule/ - the submodule referencing `simple` createGitRepos := func(t *testing.T) testRepos { t.Helper() bash := func(script string) { cmd := exec.Command("sh", "-c", script) o, err := cmd.CombinedOutput() if err != nil { t.Fatalf("error running %v\nerr: %v\n%s", script, err, string(o)) } } root := t.TempDir() hashPath, err := os.MkdirTemp(root, "hash-") require.NoError(t, err) hashDir := filepath.Base(hashPath) bash(fmt.Sprintf(` set -eux export ROOT="%s" export HASH_DIR="%s" export GIT_AUTHOR_EMAIL=nobody@kustomize.io export GIT_AUTHOR_NAME=Nobody export GIT_COMMITTER_EMAIL=nobody@kustomize.io export GIT_COMMITTER_NAME=Nobody cp -r testdata/remoteload/simple $ROOT/simple.git ( cd $ROOT/simple.git git config --global protocol.file.allow always git init --initial-branch=main git add . git commit -m "import" git checkout -b change-image cat >>kustomization.yaml <