-
Notifications
You must be signed in to change notification settings - Fork 8
/
get_views_test.go
51 lines (47 loc) · 1.41 KB
/
get_views_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
package telegraph_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"source.toby3d.me/toby3d/telegraph"
)
func TestGetViews(t *testing.T) {
t.Run("invalid", func(t *testing.T) {
t.Run("path", func(t *testing.T) {
_, err := telegraph.GetViews("wtf", time.Time{})
assert.Error(t, err)
})
t.Run("year", func(t *testing.T) {
dt := time.Date(1980, 0, 0, 0, 0, 0, 0, time.UTC)
_, err := telegraph.GetViews("Sample-Page-12-15", dt)
assert.Error(t, err)
})
t.Run("month", func(t *testing.T) {
dt := time.Date(2000, 22, 0, 0, 0, 0, 0, time.UTC)
result, err := telegraph.GetViews("Sample-Page-12-15", dt)
assert.NoError(t, err)
assert.NotNil(t, result)
})
t.Run("day", func(t *testing.T) {
dt := time.Date(2000, time.February, 42, 0, 0, 0, 0, time.UTC)
result, err := telegraph.GetViews("Sample-Page-12-15", dt)
assert.NoError(t, err)
assert.NotNil(t, result)
})
t.Run("hour", func(t *testing.T) {
dt := time.Date(2000, time.February, 12, 65, 0, 0, 0, time.UTC)
result, err := telegraph.GetViews("Sample-Page-12-15", dt)
assert.NoError(t, err)
assert.NotNil(t, result)
})
})
t.Run("valid", func(t *testing.T) {
dt := time.Date(2016, time.December, 31, 0, 0, 0, 0, time.UTC)
stats, err := telegraph.GetViews("Sample-Page-12-15", dt)
assert.NoError(t, err)
if !assert.NotNil(t, stats) {
t.FailNow()
}
assert.NotZero(t, stats.Views)
})
}