Skip to content

Commit fdaacda

Browse files
committed
Review comments
Signed-off-by: Danny Kopping <danny@coder.com>
1 parent a6ae71a commit fdaacda

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

cli/templatepull.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,10 @@ func (r *RootCmd) templatePull() *clibase.Cmd {
133133

134134
clean, err := filepath.Abs(filepath.Clean(dest))
135135
if err != nil {
136-
cliui.Error(inv.Stderr, fmt.Sprintf("cleaning destination path %s failed: %q", dest, err))
137-
return err
136+
return xerrors.Errorf("cleaning destination path %s failed: %w", dest, err)
138137
}
139138

140139
if dest != clean {
141-
cliui.Warn(inv.Stderr, fmt.Sprintf("cleaning destination path from %s to %s", dest, clean))
142140
dest = clean
143141
}
144142

cli/templatepull_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,9 @@ func TestTemplatePull_LatestStdout(t *testing.T) {
230230

231231
// ToDir tests that 'templates pull' pulls down the active template
232232
// and writes it to the correct directory.
233-
// nolint: paralleltest
234233
func TestTemplatePull_ToDir(t *testing.T) {
234+
t.Parallel()
235+
235236
// Prevents the tests from running in parallel.
236237
tmp := t.TempDir()
237238
expectedDest := filepath.Join(tmp, "expected")
@@ -245,9 +246,13 @@ func TestTemplatePull_ToDir(t *testing.T) {
245246
givenPath: filepath.Join(tmp, "actual"),
246247
},
247248
{
248-
name: "relative path is cleaned up",
249+
name: "relative path to specific dir is sanitized",
249250
givenPath: "./pulltmp",
250251
},
252+
{
253+
name: "relative path to current dir is sanitized",
254+
givenPath: ".",
255+
},
251256
{
252257
name: "directory traversal is acceptable",
253258
givenPath: "../../../mytmpl",
@@ -261,7 +266,12 @@ func TestTemplatePull_ToDir(t *testing.T) {
261266
for _, tc := range tests {
262267
tc := tc
263268

269+
// nolint: paralleltest // These tests all share expectedDest
264270
t.Run(tc.name, func(t *testing.T) {
271+
// Use a different working directory to not interfere with actual directory when using relative paths.
272+
newWD := t.TempDir()
273+
require.NoError(t, os.Chdir(newWD))
274+
265275
t.Cleanup(func() {
266276
_ = os.RemoveAll(tc.givenPath)
267277
_ = os.RemoveAll(expectedDest)

0 commit comments

Comments
 (0)