Skip to content

Commit

Permalink
finish all tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
taigrr committed Oct 18, 2023
1 parent 039cf0d commit d2ef00b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
26 changes: 16 additions & 10 deletions ingredients/file/fileDirectory.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,25 @@ func (f File) directory(ctx context.Context, test bool) (types.Result, error) {
// create the dir if "makeDirs" is true or not defined
if val, ok := f.params["makedirs"].(bool); ok && val || !ok {
d.makeDirs = true
st, _ := os.Stat(name)
if test {
notes = append(notes, types.Snprintf("would create directory %s", name))
if st.IsDir() {
notes = append(notes, types.Snprintf("directory %s already exists", name))
} else {
notes = append(notes, types.Snprintf("would create directory %s", name))
}
} else {
// TODO: Bug, this should check if the directory exists to correctly return that a directory altready exists and it is being skipped for creation
errCreate := os.MkdirAll(name, 0o755)
notes = append(notes, types.Snprintf("creating directory %s", name))
if errCreate != nil {
return types.Result{
Succeeded: false, Failed: true, Notes: notes,
}, errCreate
if st.IsDir() {
notes = append(notes, types.Snprintf("directory %s already exists", name))
} else {
errCreate := os.MkdirAll(name, 0o755)
notes = append(notes, types.Snprintf("creating directory %s", name))
if errCreate != nil {
return types.Result{
Succeeded: false, Failed: true, Notes: notes,
}, errCreate
}
}

}

}
Expand Down Expand Up @@ -159,7 +166,6 @@ func (f File) directory(ctx context.Context, test bool) (types.Result, error) {
}
// chmod the directory to the named dirmode if it is defined
{
// TODO: Bug, this should at least be able to return a successful result
if val, ok := f.params["dir_mode"].(string); ok {
d.dirMode = val
modeVal, _ := strconv.ParseUint(d.dirMode, 8, 32)
Expand Down
8 changes: 4 additions & 4 deletions ingredients/file/fileDirectory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestDirectory(t *testing.T) {
expected: types.Result{
Succeeded: true,
Failed: false,
Notes: []fmt.Stringer{types.Snprintf("creating directory %s", sampleDir), types.Snprintf("chmod %s to 755", sampleDir)},
Notes: []fmt.Stringer{types.Snprintf("directory %s already exists", sampleDir), types.Snprintf("chmod %s to 755", sampleDir)},
},
error: nil,
},
Expand All @@ -83,7 +83,7 @@ func TestDirectory(t *testing.T) {
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)},
Notes: []fmt.Stringer{types.Snprintf("directory %s already exists", sampleDir), types.Snprintf("would chmod %s to 755", sampleDir)},
},
test: true,
error: nil,
Expand All @@ -103,7 +103,7 @@ func TestDirectory(t *testing.T) {
error: fmt.Errorf("chmod %s: no such file or directory", fileModeDNE),
},
{
name: "DirectoryTestChageFileMode",
name: "DirectoryTestChangeFileMode",
params: map[string]interface{}{
"name": sampleDir,
"file_mode": "755",
Expand All @@ -112,7 +112,7 @@ func TestDirectory(t *testing.T) {
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)},
Notes: []fmt.Stringer{types.Snprintf("directory %s already exists", sampleDir), types.Snprintf("would chmod %s to 755", sampleDir)},
},
test: true,
error: nil,
Expand Down

0 comments on commit d2ef00b

Please sign in to comment.