-
Notifications
You must be signed in to change notification settings - Fork 434
/
player_cache_test.go
64 lines (61 loc) · 1.38 KB
/
player_cache_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
package youtube
import (
"testing"
"time"
)
func TestPlayerCache(t *testing.T) {
type args struct {
setVideoID string
getVideoID string
expiredAt string
getCacheAt string
}
tests := []struct {
name string
args args
want []byte
}{
{
name: "Get cache data with video id",
args: args{
setVideoID: "test",
getVideoID: "test",
expiredAt: "2021-01-01 00:01:00",
getCacheAt: "2021-01-01 00:00:00",
},
want: []byte("playerdata"),
},
{
name: "Get nil when cache is expired",
args: args{
setVideoID: "test",
getVideoID: "test",
expiredAt: "2021-01-01 00:00:00",
getCacheAt: "2021-01-01 00:00:00",
},
want: nil,
},
{
name: "Get nil when video id is not cached",
args: args{
setVideoID: "test",
getVideoID: "not test",
expiredAt: "2021-01-01 00:00:01",
getCacheAt: "2021-01-01 00:00:00",
},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := playerCache{}
timeFormat := "2006-01-02 15:04:05"
expiredAt, _ := time.Parse(timeFormat, tt.args.expiredAt)
s.setWithExpiredTime(tt.args.setVideoID, []byte("playerdata"), expiredAt)
getCacheAt, _ := time.Parse(timeFormat, tt.args.getCacheAt)
if got := s.GetCacheBefore(tt.args.getVideoID, getCacheAt); len(got) != len(tt.want) {
t.Errorf("GetCacheBefore() = %v, want %v", got, tt.want)
}
})
}
}