Skip to content

Commit

Permalink
Merge pull request #118288 from HirazawaUi/automated-cherry-pick-of-#…
Browse files Browse the repository at this point in the history
…118177-upstream-release-1.25

Automated cherry pick of #118177: Fix the git-repo test error caused by the correct use of loop
  • Loading branch information
k8s-ci-robot committed Jul 6, 2023
2 parents bbb8f1f + 05c5e7d commit eef6893
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/volume/git_repo/git_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"reflect"
"strings"
Expand Down Expand Up @@ -390,10 +391,20 @@ func doTestSetUp(scenario struct {
var fakeOutputs []fakeexec.FakeAction
var fcmd fakeexec.FakeCmd
for _, expected := range expecteds {
expected := expected
if expected.cmd[1] == "clone" {
// Calculate the subdirectory clone would create (if any)
// git clone -- https://github.com/kubernetes/kubernetes.git target_dir --> target_dir
// git clone -- https://github.com/kubernetes/kubernetes.git --> kubernetes
// git clone -- https://github.com/kubernetes/kubernetes.git . --> .
// git clone -- https://github.com/kubernetes/kubernetes.git ./. --> .
cloneSubdir := path.Base(expected.cmd[len(expected.cmd)-1])
if cloneSubdir == "kubernetes.git" {
cloneSubdir = "kubernetes"
}
fakeOutputs = append(fakeOutputs, func() ([]byte, []byte, error) {
// git clone, it creates new dir/files
os.MkdirAll(filepath.Join(fcmd.Dirs[0], expected.dir), 0750)
os.MkdirAll(filepath.Join(fcmd.Dirs[0], expected.dir, cloneSubdir), 0750)
return []byte{}, nil, nil
})
} else {
Expand Down Expand Up @@ -422,7 +433,10 @@ func doTestSetUp(scenario struct {
g := mounter.(*gitRepoVolumeMounter)
g.exec = &fake

g.SetUp(volume.MounterArgs{})
err := g.SetUp(volume.MounterArgs{})
if err != nil {
allErrs = append(allErrs, err)
}

if fake.CommandCalls != len(expecteds) {
allErrs = append(allErrs,
Expand Down

0 comments on commit eef6893

Please sign in to comment.