test updates to address feedback

This commit is contained in:
Laura Bennett 2016-10-10 12:58:30 -04:00
parent 962a383bfb
commit 0da9d1ac0c

View file

@ -17,7 +17,7 @@ func TestAuditFile_fileModeNew(t *testing.T) {
modeStr := "0777" modeStr := "0777"
mode, err := strconv.ParseUint(modeStr, 8, 32) mode, err := strconv.ParseUint(modeStr, 8, 32)
path, err := ioutil.TempDir("", "test") path, err := ioutil.TempDir("", "vault-test_audit_file-file_mode_new")
defer os.RemoveAll(path) defer os.RemoveAll(path)
file := filepath.Join(path, "auditTest.txt") file := filepath.Join(path, "auditTest.txt")
@ -34,11 +34,12 @@ func TestAuditFile_fileModeNew(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer os.Remove(file)
info, _ := os.Stat(file) info, err := os.Stat(file)
createdMode := info.Mode() if err != nil {
if createdMode != os.FileMode(mode) { t.Fatalf("Cannot retrieve file mode from `Stat`")
}
if info.Mode() != os.FileMode(mode) {
t.Fatalf("File mode does not match.") t.Fatalf("File mode does not match.")
} }
} }
@ -51,9 +52,15 @@ func TestAuditFile_fileModeExisting(t *testing.T) {
t.Fatalf("Failure to create test file.") t.Fatalf("Failure to create test file.")
} }
defer os.Remove(f.Name()) defer os.Remove(f.Name())
err = os.Chmod(f.Name(), 0777)
if err != nil {
t.Fatalf("Failure to chmod temp file for testing.")
}
err = f.Close() err = f.Close()
if err != nil { if err != nil {
t.Fatalf("Failure to close the file.") t.Fatalf("Failure to close temp file for test.")
} }
config := map[string]string{ config := map[string]string{
@ -72,8 +79,7 @@ func TestAuditFile_fileModeExisting(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("cannot retrieve file mode from `Stat`") t.Fatalf("cannot retrieve file mode from `Stat`")
} }
createdMode := info.Mode() if info.Mode() != os.FileMode(0600) {
if createdMode != os.FileMode(0600) {
t.Fatalf("File mode does not match.") t.Fatalf("File mode does not match.")
} }
} }