Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamRussak committed Jun 7, 2024
1 parent 5d3a0ae commit b0b07be
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions cmd/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,67 @@ func TestCheckAndTransformFilePath(t *testing.T) {
}
}
}
func TestCheckAndTransformDirPath(t *testing.T) {
type args struct {
path string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
// TODO: Add test cases.
{"test -~ home dir - should pass", args{path: "~/"}, homeDir(), false},
{"test -~ with auto create enabled", args{path: ""}, "", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := CheckAndTransformDirPath(tt.args.path)
if (err != nil) != tt.wantErr {
t.Errorf("CheckAndTransformDirPath() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("CheckAndTransformDirPath() got = %v, want %v", got, tt.want)
}
})
}
}

func TestIsFile(t *testing.T) {
type args struct {
path string
}
tests := []struct {
name string
args args
want bool
}{
// TODO: Add test cases.
{"test -~ not a file", args{path: "."}, false},
{"test - is a file", args{path: "./test.file"}, true},
{"test - is a config file", args{path: "./config"}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.want {
// Create a file at the path
_ = os.WriteFile(tt.args.path, []byte{}, 0666)
}
got := IsFile(tt.args.path)
if got != tt.want {
t.Errorf("IsFile() got = %v, want %v", got, tt.want)
}
})
if tt.want {
t.Cleanup(func() {
// Remove the file from wantPath after the test run is done
os.ReadFile(tt.args.path)

Check failure on line 290 in cmd/utils_test.go

View workflow job for this annotation

GitHub Actions / test

Error return value of `os.ReadFile` is not checked (errcheck)
})
}
}
}

func TestCheckValidContext(t *testing.T) {
clearWrongConfig := wrongFederalConfig.DeepCopy()
Expand Down

0 comments on commit b0b07be

Please sign in to comment.