-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions_test.go
73 lines (54 loc) · 1.63 KB
/
options_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
61
62
63
64
65
66
67
68
69
70
71
72
73
package tomorrow
import (
"strings"
"testing"
"time"
)
func TestOptions(t *testing.T) {
t.Run("Fields with empty list", func(r *testing.T) {
err := Fields()(&Request{})
if err == nil {
t.Error("Expected error but saw none")
}
if !strings.Contains(err.Error(), ErrFieldsEmpty.Error()) {
t.Errorf("Expected error to contain %s but saw %s", ErrFieldsEmpty.Error(), err.Error())
}
})
t.Run("Fields with basic list", func(r *testing.T) {
req := &Request{}
err := Fields("temperature", "temperatureApparent")(req)
if err != nil {
t.Errorf("Unexpected error but saw %s", err.Error())
}
if len(req.Fields) != 2 {
t.Errorf("Expected fields count to be 2 but saw %d", len(req.Fields))
}
})
t.Run("Range with zero start", func(r *testing.T) {
req := &Request{}
err := Range(time.Time{}, time.Time{})(req)
if err == nil {
t.Error("Expected error but saw none")
}
if !strings.Contains(err.Error(), ErrRangeStartIsZero.Error()) {
t.Errorf("Expected error to contain %s but saw %s", ErrRangeStartIsZero.Error(), err.Error())
}
})
t.Run("Range with zero end", func(r *testing.T) {
req := &Request{}
err := Range(time.Now(), time.Time{})(req)
if err == nil {
t.Error("Expected error but saw none")
}
if !strings.Contains(err.Error(), ErrRangeEndIsZero.Error()) {
t.Errorf("Expected error to contain %s but saw %s", ErrRangeEndIsZero.Error(), err.Error())
}
})
t.Run("Range with valid start and end", func(r *testing.T) {
req := &Request{}
err := Range(time.Now(), time.Now().Add(time.Second*1))(req)
if err != nil {
t.Errorf("Unexpected error but saw %s", err.Error())
}
})
}