-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpersist_test.go
60 lines (49 loc) · 1.21 KB
/
persist_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"os"
"testing"
"time"
)
func getTimeFromString(t *testing.T, timeStr string) time.Time {
atTime, err := time.Parse(time.RFC3339, timeStr)
if err != nil {
t.Error(err)
}
return atTime
}
func Test_missing_parent_dirs_is_false(t *testing.T) {
fileName := "someconfig/mparmpoutsala"
result := lastReadFileExists(fileName)
if result {
t.Errorf("file %v should not exist!", fileName)
}
}
func Test_file_missing_is_false(t *testing.T) {
fileName := "mparmpoutsala"
result := lastReadFileExists(fileName)
if result {
t.Errorf("file %v should not exist!", fileName)
}
}
func Test_existing_file_is_true(t *testing.T) {
fileName := "test-resources/emptyFile"
result := lastReadFileExists(fileName)
if !result {
t.Errorf("file %v should not exist!", fileName)
}
}
func Test_write_time_and_then_read_from_file(t *testing.T) {
//arrange
fileName := "test-resources/dateFile"
previousTime := getTimeFromString(t, "2020-06-24T01:04:05+03:00")
if err := os.Remove(fileName); err != nil {
t.Fatal(err)
}
//act
writeTimeToFile(previousTime, fileName)
result := readTimeFromFile(fileName)
//assert
if !result.Equal(previousTime) {
t.Error("Unable to write and then read time to file")
}
}