-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #306 from rusq/i288
Fix custom cache directory logic
- Loading branch information
Showing
7 changed files
with
185 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package workspace | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func Test_printBare(t *testing.T) { | ||
type args struct { | ||
_ manager | ||
current string | ||
workspaces []string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantW string | ||
wantErr bool | ||
}{ | ||
{ | ||
"Test 1", | ||
args{ | ||
current: "current", | ||
workspaces: []string{"workspace1", "workspace2", "current"}, | ||
}, | ||
"workspace1\nworkspace2\n*current\n", | ||
false, | ||
}, | ||
{ | ||
"Test 2", | ||
args{ | ||
current: "workspace1", | ||
workspaces: []string{"workspace1", "workspace2", "notcurrent"}, | ||
}, | ||
"*workspace1\nworkspace2\nnotcurrent\n", | ||
false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
w := &bytes.Buffer{} | ||
if err := printBare(w, nil, tt.args.current, tt.args.workspaces); (err != nil) != tt.wantErr { | ||
t.Errorf("printBare() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if gotW := w.String(); gotW != tt.wantW { | ||
t.Errorf("printBare() = %v, want %v", gotW, tt.wantW) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package osext | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestSame(t *testing.T) { | ||
baseDir := t.TempDir() | ||
|
||
file1 := filepath.Join(baseDir, "file1") | ||
file2 := filepath.Join(baseDir, "file2") | ||
|
||
wd, err := os.Getwd() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
// file1rel is the path relative to the current working directory (where | ||
// the test is running). | ||
file1rel, err := filepath.Rel(wd, file1) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
t.Logf("file1rel: %q", file1rel) | ||
|
||
type args struct { | ||
path1 string | ||
path2 string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
wantErr bool | ||
}{ | ||
{ | ||
"same file", | ||
args{file1, file1}, | ||
true, | ||
false, | ||
}, | ||
{ | ||
"same file relative", | ||
args{file1, file1rel}, | ||
true, | ||
false, | ||
}, | ||
{ | ||
"different files", | ||
args{file1, file2}, | ||
false, | ||
false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := Same(tt.args.path1, tt.args.path2) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("Same() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if got != tt.want { | ||
t.Errorf("Same() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |