-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_test.go
65 lines (56 loc) · 1.11 KB
/
service_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
package cicdTestRepo
import (
"context"
"testing"
"time"
)
func TestStatus(t *testing.T) {
srv, ctx := setup()
s, err := srv.Status(ctx)
if err != nil {
t.Errorf("Error: %s", err)
}
// testing status
ok := s == "ok"
if !ok {
t.Errorf("expected service to be ok")
}
}
func TestGet(t *testing.T) {
srv, ctx := setup()
d, err := srv.Get(ctx)
if err != nil {
t.Errorf("Error: %s", err)
}
time := time.Now()
today := time.Format("02/01/2006")
// testing today's date
ok := today == d
if !ok {
t.Errorf("expected dates to be equal")
}
}
func TestValidate(t *testing.T) {
srv, ctx := setup()
b, err := srv.Validate(ctx, "31/12/2019")
if err != nil {
t.Errorf("Error: %s", err)
}
// testing that the date is valid
if !b {
t.Errorf("date should be valid")
}
// testing an invalid date
b, err = srv.Validate(ctx, "31/31/2019")
if b {
t.Errorf("date should be invalid")
}
// testing a USA date date
b, err = srv.Validate(ctx, "12/31/2019")
if b {
t.Errorf("USA date should be invalid")
}
}
func setup() (srv Service, ctx context.Context) {
return NewService(), context.Background()
}