diff options
Diffstat (limited to 'awwan_sudo_test.go')
| -rw-r--r-- | awwan_sudo_test.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/awwan_sudo_test.go b/awwan_sudo_test.go index eb26202..8becc0b 100644 --- a/awwan_sudo_test.go +++ b/awwan_sudo_test.go @@ -42,6 +42,11 @@ func TestAwwan_Local_SudoGet(t *testing.T) { t.Fatal(err) } + err = os.Chmod(filepath.Join(baseDir, `tmp`), 0755) + if err != nil { + t.Fatal(err) + } + var ( mockTerm = mock.ReadWriter{} @@ -141,6 +146,7 @@ func TestAwwan_Local_SudoPut(t *testing.T) { expError string expContent string expMode fs.FileMode + expDirMode fs.FileMode } // Load the test data output. @@ -157,6 +163,11 @@ func TestAwwan_Local_SudoPut(t *testing.T) { t.Fatal(err) } + err = os.Chmod(filepath.Join(baseDir, `tmp`), 0755) + if err != nil { + t.Fatal(err) + } + var cases = []testCase{{ desc: `WithTextFile`, lineRange: `7-8`, @@ -164,6 +175,7 @@ func TestAwwan_Local_SudoPut(t *testing.T) { fileDest: `/etc/plain.txt`, expContent: string(tdata.Output[`tmp/plain.txt`]), expMode: 420, + expDirMode: 0755, }, { desc: `WithMode`, lineRange: `14`, @@ -171,6 +183,7 @@ func TestAwwan_Local_SudoPut(t *testing.T) { fileDest: `/etc/sudoput_with_mode.txt`, expContent: string(tdata.Output[`tmp/plain.txt`]), expMode: 0516, + expDirMode: 0755, }, { desc: `WithOwner`, lineRange: `16`, @@ -178,6 +191,15 @@ func TestAwwan_Local_SudoPut(t *testing.T) { fileDest: `/etc/sudoput_with_owner.txt`, expContent: string(tdata.Output[`tmp/plain.txt`]), expMode: 420, + expDirMode: 0755, + }, { + desc: `WithDestinationIsDirectory`, + lineRange: `20`, + sudoPass: "awwan\nawwan\n", + fileDest: filepath.Join(baseDir, `tmp`, `plain.txt`), + expContent: string(tdata.Output[`tmp/plain.txt`]), + expMode: 0644, + expDirMode: 0755, }} var ( @@ -238,7 +260,12 @@ func TestAwwan_Local_SudoPut(t *testing.T) { if err != nil { t.Fatal(err) } - test.Assert(t, `permission`, c.expMode, fi.Mode().Perm()) + + fi, err = os.Stat(filepath.Dir(c.fileDest)) + if err != nil { + t.Fatal(err) + } + test.Assert(t, `dirMode`, c.expDirMode, fi.Mode().Perm()) } } |
