Skip to content

Commit be41446

Browse files
committed
Adding test for request parsing
1 parent 7787221 commit be41446

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/request_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package core_test
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
"github.com/merschformann/gotz/core"
8+
)
9+
10+
func TestParseRequest(t *testing.T) {
11+
defaultConfig := core.DefaultConfig()
12+
londonTZ, _ := time.LoadLocation("Europe/London")
13+
berlinTZ, _ := time.LoadLocation("Europe/Berlin")
14+
// Define test cases
15+
tests := []struct {
16+
name string
17+
input string
18+
expected time.Time
19+
}{
20+
{
21+
name: "London",
22+
input: "1100@Europe/London",
23+
expected: time.Date(2023, 10, 1, 11, 0, 0, 0, londonTZ),
24+
},
25+
{
26+
name: "Berlin",
27+
input: "7pm@Europe/Berlin",
28+
expected: time.Date(2023, 10, 1, 19, 0, 0, 0, berlinTZ),
29+
},
30+
{
31+
name: "BerlinIndexed",
32+
input: "7pm@2",
33+
expected: time.Date(2023, 10, 1, 19, 0, 0, 0, berlinTZ),
34+
},
35+
}
36+
37+
for _, test := range tests {
38+
t.Run(test.name, func(t *testing.T) {
39+
// Parse the request
40+
parsedTime, err := core.ParseRequestTime(defaultConfig, test.input)
41+
if err != nil {
42+
t.Fatalf("Error parsing request: %v", err)
43+
}
44+
// Check if the parsed time matches the expected time (ignore the
45+
// date)
46+
if parsedTime.Hour() != test.expected.Hour() || parsedTime.Minute() != test.expected.Minute() {
47+
t.Errorf("Expected %v, got %v", test.expected, t)
48+
}
49+
// Check if the timezone matches the expected timezone
50+
if parsedTime.Location().String() != test.expected.Location().String() {
51+
t.Errorf("Expected timezone %v, got %v", test.expected.Location(), parsedTime.Location())
52+
}
53+
})
54+
}
55+
}

0 commit comments

Comments
 (0)