-
Notifications
You must be signed in to change notification settings - Fork 62
/
files_get_file_url_test.go
75 lines (58 loc) · 1.43 KB
/
files_get_file_url_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
package pubnub
import (
"fmt"
"testing"
h "github.com/pubnub/go/v7/tests/helpers"
"github.com/stretchr/testify/assert"
)
func AssertGetFileURL(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 := newGetFileURLBuilder(pn)
if testContext {
o = newGetFileURLBuilderWithContext(pn, backgroundContext)
}
channel := "chan"
id := "fileid"
name := "filename"
o.Channel(channel)
o.QueryParam(queryParam)
o.ID(id)
o.Name(name)
path, err := o.opts.buildPath()
assert.Nil(err)
h.AssertPathsEqual(t,
fmt.Sprintf(getFileURLPath, pn.Config.SubscribeKey, channel, id, name),
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 TestGetFileURL(t *testing.T) {
AssertGetFileURL(t, true, false)
}
func TestGetFileURLContext(t *testing.T) {
AssertGetFileURL(t, true, true)
}
func TestGetFileURLResponseValuePass(t *testing.T) {
assert := assert.New(t)
pn := NewPubNub(NewDemoConfig())
channel := "chan"
id := "fileid"
name := "filename"
r, _, err := pn.GetFileURL().ID(id).Name(name).Channel(channel).Execute()
assert.Contains(r.URL, fmt.Sprintf("%s/files/%s/%s", channel, id, name))
assert.Nil(err)
}