| OLD | NEW |
| 1 package util | 1 package util |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "fmt" | 4 "fmt" |
| 5 "io/ioutil" | 5 "io/ioutil" |
| 6 "os" | 6 "os" |
| 7 "path/filepath" | 7 "path/filepath" |
| 8 "strconv" | 8 "strconv" |
| 9 "testing" | 9 "testing" |
| 10 ) | 10 ) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 t.Error("Unexpected lack of error") | 48 t.Error("Unexpected lack of error") |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 func TestCreateTimestampFile(t *testing.T) { | 52 func TestCreateTimestampFile(t *testing.T) { |
| 53 realDir := filepath.Join(os.TempDir(), "util_test") | 53 realDir := filepath.Join(os.TempDir(), "util_test") |
| 54 os.Mkdir(realDir, 0755) | 54 os.Mkdir(realDir, 0755) |
| 55 defer os.RemoveAll(realDir) | 55 defer os.RemoveAll(realDir) |
| 56 timestampFilePath := filepath.Join(realDir, TIMESTAMP_FILE_NAME) | 56 timestampFilePath := filepath.Join(realDir, TIMESTAMP_FILE_NAME) |
| 57 if err := CreateTimestampFile(realDir); err != nil { | 57 if err := CreateTimestampFile(realDir); err != nil { |
| 58 » » t.Error("Unexpected error: %s", err) | 58 » » t.Errorf("Unexpected error: %s", err) |
| 59 } | 59 } |
| 60 // Assert timestamp file exists. | 60 // Assert timestamp file exists. |
| 61 if _, err := os.Stat(timestampFilePath); err != nil { | 61 if _, err := os.Stat(timestampFilePath); err != nil { |
| 62 t.Errorf("Timestamp file %s was not created!", timestampFilePath
) | 62 t.Errorf("Timestamp file %s was not created!", timestampFilePath
) |
| 63 } | 63 } |
| 64 // Assert timestamp file contains int64. | 64 // Assert timestamp file contains int64. |
| 65 fileContent, err := ioutil.ReadFile(timestampFilePath) | 65 fileContent, err := ioutil.ReadFile(timestampFilePath) |
| 66 if err != nil { | 66 if err != nil { |
| 67 t.Errorf("Unexpected error: %s", err) | 67 t.Errorf("Unexpected error: %s", err) |
| 68 } | 68 } |
| 69 if _, err := strconv.ParseInt(string(fileContent), 10, 64); err != nil { | 69 if _, err := strconv.ParseInt(string(fileContent), 10, 64); err != nil { |
| 70 » » t.Error("Unexpected value in %s: %s", timestampFilePath, err) | 70 » » t.Errorf("Unexpected value in %s: %s", timestampFilePath, err) |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Assert error returned when specified dir does not exist. | 73 // Assert error returned when specified dir does not exist. |
| 74 nonexistantDir := filepath.Join(os.TempDir(), "util_test_nonexistant") | 74 nonexistantDir := filepath.Join(os.TempDir(), "util_test_nonexistant") |
| 75 os.RemoveAll(nonexistantDir) | 75 os.RemoveAll(nonexistantDir) |
| 76 if err := CreateTimestampFile(nonexistantDir); err != nil { | 76 if err := CreateTimestampFile(nonexistantDir); err != nil { |
| 77 // Expected error | 77 // Expected error |
| 78 } else { | 78 } else { |
| 79 t.Error("Unexpected lack of error") | 79 t.Error("Unexpected lack of error") |
| 80 } | 80 } |
| 81 } | 81 } |
| OLD | NEW |