added test for file attributes
@@ -59,3 +59,32 @@ func TestRenameFile(t *testing.T) {
// Check if the data in the file is the same after renaming.
compareFileContents(t, newFileName, string(content))
}
+
+func TestFileAttributes(t *testing.T) {
+ preCreateTime := time.Now()
+ // Sleep for 100ms else preCreateTime would be greater than modTime.
+ // time.Sleep(100 * time.Millisecond)
+
+ fileName := createTempFile()
+ postCreateTime := time.Now()
+
+ fStat, err := os.Stat(fileName)
+
+ if err != nil {
+ t.Errorf("os.Stat error: %s, %v", fileName, err)
+ }
+
+ statFileName := path.Join(tmpDir, fStat.Name())
+ if fileName != statFileName {
+ t.Errorf("File name not matched in os.Stat, found: %s, expected: %s", statFileName, fileName)
+ }
+
+ if (preCreateTime.After(fStat.ModTime())) || (postCreateTime.Before(fStat.ModTime())) {
+ t.Errorf("File modification time not in the required time-range")
+ }
+
+ // The file size in createTempFile() is 14 bytes
+ if fStat.Size() != 14 {
+ t.Errorf("File size is not 14 bytes, found size: %d bytes", fStat.Size())
+ }
+}
