Fix the git-repo test error caused by the correct use of loop variables

This commit is contained in:
HirazawaUi 2023-05-26 21:32:36 +08:00
parent da0a1a05b9
commit 510287d344

View File

@ -20,6 +20,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"path/filepath" "path/filepath"
"reflect" "reflect"
"strings" "strings"
@ -390,10 +391,20 @@ func doTestSetUp(scenario struct {
var fakeOutputs []fakeexec.FakeAction var fakeOutputs []fakeexec.FakeAction
var fcmd fakeexec.FakeCmd var fcmd fakeexec.FakeCmd
for _, expected := range expecteds { for _, expected := range expecteds {
expected := expected
if expected.cmd[1] == "clone" { 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) { fakeOutputs = append(fakeOutputs, func() ([]byte, []byte, error) {
// git clone, it creates new dir/files // 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 return []byte{}, nil, nil
}) })
} else { } else {
@ -422,7 +433,10 @@ func doTestSetUp(scenario struct {
g := mounter.(*gitRepoVolumeMounter) g := mounter.(*gitRepoVolumeMounter)
g.exec = fake g.exec = fake
g.SetUp(volume.MounterArgs{}) err := g.SetUp(volume.MounterArgs{})
if err != nil {
allErrs = append(allErrs, err)
}
if fake.CommandCalls != len(expecteds) { if fake.CommandCalls != len(expecteds) {
allErrs = append(allErrs, allErrs = append(allErrs,