Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from May 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions pkg/volume/git_repo/git_repo_test.go
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