-
Notifications
You must be signed in to change notification settings - Fork 1
/
req_test.go
38 lines (31 loc) · 1000 Bytes
/
req_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
package nxos
import (
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/h2non/gock.v1"
)
// TestSetRaw tests the Body::SetRaw method.
func TestSetRaw(t *testing.T) {
name := Body{}.SetRaw("a", `{"name":"a"}`).Res().Get("a.name").Str
assert.Equal(t, "a", name)
}
// TestDelete tests the Body::Delete method.
func TestDelete(t *testing.T) {
body := Body{}
body = body.SetRaw("a", `{"name":"a"}`)
assert.Equal(t, "a", body.Res().Get("a.name").Str)
body = body.Delete("a.name")
assert.Equal(t, "", body.Res().Get("a.name").Str)
}
// TestQuery tests the Query function.
func TestQuery(t *testing.T) {
defer gock.Off()
client := testClient()
gock.New(testURL).Get("/url").MatchParam("foo", "bar").Reply(200)
_, err := client.Get("/url", Query("foo", "bar"))
assert.NoError(t, err)
// Test case for comma-separated parameters
gock.New(testURL).Get("/url").MatchParam("foo", "bar,baz").Reply(200)
_, err = client.Get("/url", Query("foo", "bar,baz"))
assert.NoError(t, err)
}