-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocessor_test.go
More file actions
117 lines (110 loc) · 2.93 KB
/
processor_test.go
File metadata and controls
117 lines (110 loc) · 2.93 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package timewlib
import (
"testing"
"time"
)
func TestProcess(t *testing.T) {
testCase := []TimewarriorInterval{
{
Start: "20230101T000000Z",
End: "20230101T003000Z",
Tags: []string{"tag1", "tag2"},
Annotation: "This is an annotation",
},
}
processed, err := Process(testCase)
if err != nil {
t.Errorf("Error occurred while processing %v", err)
}
if len(processed) != 1 {
t.Errorf("Processor Failed to read all records")
}
interval := processed[0]
if len(interval.Tags) != 2 {
t.Errorf("Processor failed to process interval tags")
}
startTime, err := time.Parse("20060102T150405Z", "20230101T000000Z")
if err != nil {
t.Errorf("Unexpected error %v", err)
}
startTime = startTime.Local()
if interval.start != startTime {
t.Errorf("Expected start date to be [%v], found instead [%v]", startTime, interval.start)
}
endTime, err := time.Parse("20060102T150405Z", "20230101T003000Z")
if err != nil {
t.Errorf("Unexpected error %v", err)
}
endTime = endTime.Local()
if interval.end != endTime {
t.Errorf("Expected start date to be [%v], found instead [%v]", endTime, interval.end)
}
if interval.Annotation != "This is an annotation" {
t.Errorf("Expected annotation to be [This is an annotation], found instead [%v]", interval.Annotation)
}
}
func TestProcessStartDateError(t *testing.T) {
testCase := []TimewarriorInterval{
{
Start: "THISISNOTADATE",
End: "20230101T003000Z",
Tags: []string{"tag1", "tag2"},
},
}
_, err := Process(testCase)
if err == nil {
t.Errorf("Processor did not return error for invalid string date")
} else {
t.Logf("%v", err)
}
}
func TestProcessEndDateEmpty(t *testing.T) {
testCase := []TimewarriorInterval{
{
Start: "20230101T003000Z",
End: "",
Tags: []string{"tag1", "tag2"},
},
}
intervals, err := Process(testCase)
if err != nil {
t.Fatalf("Processor returned unexpected error")
}
interval := intervals[0]
if interval.end.After(time.Now()) {
t.Errorf("Expected end date to be before now, found instead [%v]", interval.end)
}
}
func TestProcessEndDateError(t *testing.T) {
testCase := []TimewarriorInterval{
{
Start: "20230101T003000Z",
End: "THISISNOTADATE",
Tags: []string{"tag1", "tag2"},
},
}
_, err := Process(testCase)
if err == nil {
t.Errorf("Processor did not return error for invalid string date")
} else {
t.Logf("%v", err)
}
}
func TestParseIsoLocal(t *testing.T) {
parsedDate, err := parseIsoLocal("20230101T003000Z")
if err != nil {
t.Errorf("Error while parsing date %v", err)
}
expectedDate := time.Date(2023, 01, 01, 00, 30, 0, 0, time.UTC).Local()
if parsedDate != expectedDate {
t.Errorf("Expected start date to be [%v], found instead [%v]", expectedDate, parsedDate)
}
}
func TestParseIsoLocalError(t *testing.T) {
_, err := parseIsoLocal("THISISNOTADATE")
if err == nil {
t.Errorf("parseIsoLocal did not return error for invalid string date")
} else {
t.Logf("%v", err)
}
}