Skip to content

Commit

Permalink
test(file): updated dir tests to handle more error cases and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanholz committed Oct 17, 2023
1 parent 4398fe6 commit aecf830
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions ingredients/file/fileDirectory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestDirectory(t *testing.T) {
os.Mkdir(sampleDir, 0o755)
file := filepath.Join(sampleDir, "there-is-a-file-here")
os.Create(file)
fileModeDNE := filepath.Join(sampleDir, "file-mode-does-not-exist")
tests := []struct {
name string
params map[string]interface{}
Expand Down Expand Up @@ -73,34 +74,64 @@ func TestDirectory(t *testing.T) {
error: nil,
},
{
name: "DirectoryTestChangeMode",
name: "DirectoryTestChangeDirMode",
params: map[string]interface{}{
"name": sampleDir,
"dir_mode": "755",
"makeDirs": true,
"makedirs": true,
},
expected: types.Result{
Succeeded: true,
Failed: false,
Notes: []fmt.Stringer{types.Snprintf("would create directory %s", sampleDir), types.Snprintf("would chmod %s to 755", sampleDir), types.SimpleNote("")},
Notes: []fmt.Stringer{types.Snprintf("would create directory %s", sampleDir), types.Snprintf("would chmod %s to 755", sampleDir)},
},
test: true,
error: nil,
},
{
name: "DirectoryChangeModeNotExist",
params: map[string]interface{}{
"name": sampleDir,
"name": fileModeDNE,
"dir_mode": "755",
"makedirs": false,
},
expected: types.Result{
Succeeded: false,
Failed: true,
Notes: []fmt.Stringer{},
},
error: fmt.Errorf("chmod %s: no such file or directory", fileModeDNE),
},
{
name: "DirectoryTestChageFileMode",
params: map[string]interface{}{
"name": sampleDir,
"file_mode": "755",
"makedirs": true,
},
expected: types.Result{
Succeeded: true,
Failed: false,
Notes: []fmt.Stringer{types.Snprintf("would create directory %s", sampleDir), types.Snprintf("would chmod %s to 755", sampleDir), types.SimpleNote("")},
Notes: []fmt.Stringer{types.Snprintf("would create directory %s", sampleDir), types.Snprintf("would chmod %s to 755", sampleDir)},
},
test: true,
error: nil,
},
{
// TODO: Update to match error for a directory that doesn't exist
name: "DirectoryChangeFileModeNotExist",
params: map[string]interface{}{
"name": fileModeDNE,
"file_mode": "755",
"makedirs": false,
},
expected: types.Result{
Succeeded: false,
Failed: true,
Notes: []fmt.Stringer{},
},
error: fmt.Errorf("chmod %s: no such file or directory", fileModeDNE),
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down

0 comments on commit aecf830

Please sign in to comment.