-
Notifications
You must be signed in to change notification settings - Fork 63
/
files_list_files_test.go
84 lines (65 loc) · 2.03 KB
/
files_list_files_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
74
75
76
77
78
79
80
81
82
83
84
package pubnub
import (
"fmt"
"testing"
h "github.com/pubnub/go/v7/tests/helpers"
"github.com/stretchr/testify/assert"
)
func AssertListFiles(t *testing.T, checkQueryParam, testContext bool) {
assert := assert.New(t)
pn := NewPubNub(NewDemoConfig())
queryParam := map[string]string{
"q1": "v1",
"q2": "v2",
}
if !checkQueryParam {
queryParam = nil
}
o := newListFilesBuilder(pn)
if testContext {
o = newListFilesBuilderWithContext(pn, backgroundContext)
}
channel := "chan"
o.Channel(channel)
o.QueryParam(queryParam)
path, err := o.opts.buildPath()
assert.Nil(err)
h.AssertPathsEqual(t,
fmt.Sprintf(listFilesPath, pn.Config.SubscribeKey, channel),
path, []int{})
body, err := o.opts.buildBody()
assert.Nil(err)
assert.Empty(body)
if checkQueryParam {
u, _ := o.opts.buildQuery()
assert.Equal("v1", u.Get("q1"))
assert.Equal("v2", u.Get("q2"))
}
}
func TestListFiles(t *testing.T) {
AssertListFiles(t, true, false)
}
func TestListFilesContext(t *testing.T) {
AssertListFiles(t, true, true)
}
func TestListFilesResponseValueError(t *testing.T) {
assert := assert.New(t)
pn := NewPubNub(NewDemoConfig())
opts := newListFilesOpts(pn, pn.ctx)
jsonBytes := []byte(`s`)
_, _, err := newPNListFilesResponse(jsonBytes, opts, StatusResponse{})
assert.Equal("pubnub/parsing: Error unmarshalling response: {s}", err.Error())
}
func TestListFilesResponseValuePass(t *testing.T) {
assert := assert.New(t)
pn := NewPubNub(NewDemoConfig())
opts := newListFilesOpts(pn, pn.ctx)
jsonBytes := []byte(`{"status":200,"data":[{"name":"test_file_upload_name_42893.txt","id":"9ef0e123-1e4a-40b9-89d5-f4be0e8b1f2c","size":21904,"created":"2020-07-21T09:10:55Z"}],"next":null,"count":1}`)
r, _, err := newPNListFilesResponse(jsonBytes, opts, StatusResponse{})
assert.Equal(r.Count, 1)
assert.Equal(r.Data[0].ID, "9ef0e123-1e4a-40b9-89d5-f4be0e8b1f2c")
assert.Equal(r.Data[0].Name, "test_file_upload_name_42893.txt")
assert.Equal(r.Data[0].Size, 21904)
assert.Equal(r.Data[0].Created, "2020-07-21T09:10:55Z")
assert.Nil(err)
}