Skip to content

Commit

Permalink
Merge pull request #25198 from chaodaiG/cloneutils-verbose
Browse files Browse the repository at this point in the history
Cloneref logs full command + env + dir
  • Loading branch information
k8s-ci-robot committed Feb 10, 2022
2 parents 9c94d06 + 1f24774 commit b271205
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions prow/pod-utils/clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ func (c cloneCommand) run() (string, string, error) {
cmd.Stdout = &output
cmd.Stderr = &output
err := cmd.Run()
return strings.Join(append([]string{c.command}, c.args...), " "), output.String(), err
return c.String(), output.String(), err
}

func (c cloneCommand) String() string {
return fmt.Sprintf("PWD=%s %s %s %s", c.dir, strings.Join(c.env, " "), c.command, strings.Join(c.env, " "))
return fmt.Sprintf("PWD=%s %s %s %s", c.dir, strings.Join(c.env, " "), c.command, strings.Join(c.args, " "))
}
34 changes: 34 additions & 0 deletions prow/pod-utils/clone/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,3 +933,37 @@ func TestGitFetch(t *testing.T) {
})
}
}

func TestCloneCommandString(t *testing.T) {
tests := []struct {
name string
cc cloneCommand
want string
}{
{
name: "empty",
cc: cloneCommand{},
want: "PWD= ",
},
{
name: "base",
cc: cloneCommand{
dir: "abc",
env: []string{"d=e", "f=g"},
command: "echo",
args: []string{"hij klm"},
},
want: "PWD=abc d=e f=g echo hij klm",
},
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
want, got := tc.want, tc.cc.String()
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("mismatch. want(-), got(+):\n%s", diff)
}
})
}
}

0 comments on commit b271205

Please sign in to comment.