Skip to content

Commit e2529dc

Browse files
Fix test failures: check cleaned path for '.' and update test expectations
- Changed getDest() to check cleaned path (v) instead of originalV for '.' comparison - Updated tests to expect current directory when './' or '.' is explicitly passed - Fixed TestCmdMainBranch_execute to not pass './' explicitly - Fixed TestCmd_fail to use non-existent destination directory Signed-off-by: Ciaran Johnston <ciaran.johnston@ericsson.com>
1 parent f94663f commit e2529dc

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

commands/pkg/get/cmdget_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestCmdMainBranch_execute(t *testing.T) {
111111
}
112112

113113
r := get.NewRunner(fake.CtxWithDefaultPrinter(), "kpt")
114-
r.Command.SetArgs([]string{"file://" + g.RepoDirectory + ".git/", "./"})
114+
r.Command.SetArgs([]string{"file://" + g.RepoDirectory + ".git/"})
115115
err = r.Command.Execute()
116116

117117
assert.NoError(t, err)
@@ -159,9 +159,9 @@ func TestCmd_fail(t *testing.T) {
159159
r := get.NewRunner(fake.CtxWithDefaultPrinter(), "kpt")
160160
r.Command.SilenceErrors = true
161161
r.Command.SilenceUsage = true
162-
r.Command.SetArgs([]string{"file://" + filepath.Join("not", "real", "dir") + ".git/@master", "./"})
162+
r.Command.SetArgs([]string{"file://" + filepath.Join("not", "real", "dir") + ".git/@master", "nonexistent"})
163163

164-
defer os.RemoveAll("dir")
164+
defer os.RemoveAll("nonexistent")
165165

166166
err := r.Command.Execute()
167167
if !assert.Error(t, err) {
@@ -234,7 +234,7 @@ func TestCmd_Execute_flagAndArgParsing(t *testing.T) {
234234
assert.NoError(t, err)
235235
assert.Equal(t, "master", r.Get.Git.Ref)
236236
assert.Equal(t, "something://foo", r.Get.Git.Repo)
237-
assert.Equal(t, filepath.Join(pathPrefix, w.WorkspaceDirectory, "foo"), r.Get.Destination)
237+
assert.Equal(t, filepath.Join(pathPrefix, w.WorkspaceDirectory), r.Get.Destination)
238238
},
239239
},
240240
"repo arg is split up correctly into ref, directory and repo": {
@@ -247,7 +247,7 @@ func TestCmd_Execute_flagAndArgParsing(t *testing.T) {
247247
assert.Equal(t, fmt.Sprintf("file://%s", repo), r.Get.Git.Repo)
248248
assert.Equal(t, "master", r.Get.Git.Ref)
249249
assert.Equal(t, "/blueprints/java", r.Get.Git.Directory)
250-
assert.Equal(t, filepath.Join(pathPrefix, w.WorkspaceDirectory, "java"), r.Get.Destination)
250+
assert.Equal(t, filepath.Join(pathPrefix, w.WorkspaceDirectory), r.Get.Destination)
251251
},
252252
},
253253
"current working dir -- should use current directory directly": {

internal/util/parse/parse.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ func getDest(v, repo, subdir string, explicitDest bool) (string, error) {
275275
}
276276

277277
// LOCATION EXISTS
278-
// Check if user explicitly specified current directory (. or empty string)
278+
// Check if user explicitly specified current directory (. or paths that resolve to .)
279279
// to match git clone behavior
280-
if explicitDest && (originalV == "." || originalV == "") {
280+
if explicitDest && (v == "." || originalV == "") {
281281
return v, nil
282282
}
283283

0 commit comments

Comments
 (0)