Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions linux/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ func configAppend(line string) {
}

func configMatches(spec *RepoSpec, nameOrPath string) bool {
return spec.Path == expandTilde(nameOrPath) || spec.Name() == nameOrPath || spec.Path == nameOrPath
return spec.Name() == nameOrPath || spec.Path == nameOrPath || spec.Path == normalizePath(nameOrPath)
}

func configRemove(nameOrPath string) int {
Expand All @@ -673,10 +673,9 @@ func configRemove(nameOrPath string) int {
return removed
}

// Flip the --paused token on config lines matching `nameOrPath` (by full
// path or repo name, like remove). Pause lives in the config, not daemon
// state, so it survives daemon and machine restarts. Returns the number
// of lines changed.
// Flip the --paused token on config lines matching `nameOrPath` (as remove
// matches). Pause lives in the config, not daemon state, so it survives
// daemon and machine restarts. Returns the number of lines changed.
func configSetPaused(nameOrPath string, paused bool) int {
raw, err := os.ReadFile(configPath())
if err != nil {
Expand Down
58 changes: 58 additions & 0 deletions linux/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,45 @@ func TestRmMatchesByFullPath(t *testing.T) {
}
}

func TestRmMatchesTheRepoItRunsIn(t *testing.T) {
withTemporaryConfig(t)
repo := newTestRepo(t)
cliRun([]string{repo.path})
t.Chdir(repo.path)
if cliRun([]string{"rm", "."}) != 0 {
t.Error("rm . failed")
}
if len(configSpecs()) != 0 {
t.Error("the entry should be gone")
}
}

func TestRmMatchesARelativePath(t *testing.T) {
withTemporaryConfig(t)
repo := newTestRepo(t)
cliRun([]string{repo.path})
t.Chdir(filepath.Dir(repo.path))
if cliRun([]string{"rm", "./" + repo.spec().Name()}) != 0 {
t.Error("rm by relative path failed")
}
if len(configSpecs()) != 0 {
t.Error("the entry should be gone")
}
}

func TestRmMatchesByNameFromAnUnrelatedDirectory(t *testing.T) {
withTemporaryConfig(t)
repo := newTestRepo(t)
cliRun([]string{repo.path})
t.Chdir(t.TempDir())
if cliRun([]string{"rm", repo.spec().Name()}) != 0 {
t.Error("rm by name failed")
}
if len(configSpecs()) != 0 {
t.Error("the entry should be gone")
}
}

func TestRmUnknownFailsAndLeavesConfigAlone(t *testing.T) {
withTemporaryConfig(t)
repo := newTestRepo(t)
Expand Down Expand Up @@ -171,6 +210,25 @@ func TestPauseByFullPath(t *testing.T) {
}
}

func TestPauseAndResumeTakeARelativeTarget(t *testing.T) {
withTemporaryConfig(t)
repo := newTestRepo(t)
cliRun([]string{repo.path})
t.Chdir(repo.path)
if cliRun([]string{"pause", "."}) != 0 {
t.Fatal("pause . failed")
}
if !configSpecs()[0].Paused {
t.Error("spec should be paused")
}
if cliRun([]string{"resume", "."}) != 0 {
t.Fatal("resume . failed")
}
if configSpecs()[0].Paused {
t.Error("spec should be resumed")
}
}

func TestPausingTwiceFailsPolitely(t *testing.T) {
withTemporaryConfig(t)
repo := newTestRepo(t)
Expand Down
Loading