This repository has been archived by the owner on Apr 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
params_from_internal_test.go
67 lines (60 loc) · 1.66 KB
/
params_from_internal_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
package vkapi
import (
"net/url"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("paramsFrom", func() {
It("should build params from struct", func() {
s := "string"
d := struct {
Bool bool `json:"bool_param"`
String string `json:"string_param"`
Number uint64 `json:"number_param"`
Repeated []uint64 `json:"repeated_param"`
Empty string `json:"empty_param,omitempty"`
Omitted string `json:"-"`
Pointer *string `json:"pointer_param"`
Nil *string `json:"nil_param"`
}{
Bool: true,
String: "string_value",
Number: 42,
Repeated: []uint64{1, 2, 3},
Empty: "",
Omitted: "omitted",
Pointer: &s,
Nil: nil,
}
Expect(paramsFrom(d)).To(Equal(url.Values{
"bool_param": []string{"1"},
"string_param": []string{"string_value"},
"number_param": []string{"42"},
"repeated_param": []string{"1,2,3"},
"pointer_param": []string{"string"},
}))
})
It("should build params from map", func() {
s := "string"
d := map[string]interface{}{
"bool_param": true,
"string_param": "string_value",
"number_param": 42,
"repeated_param": []uint64{1, 2, 3},
"pointer_param": &s,
"nil_param": nil,
}
Expect(paramsFrom(d)).To(Equal(url.Values{
"bool_param": []string{"1"},
"string_param": []string{"string_value"},
"number_param": []string{"42"},
"repeated_param": []string{"1,2,3"},
"pointer_param": []string{"string"},
}))
})
It("should ignore unsupported types", func() {
Expect(paramsFrom(nil)).To(BeNil())
Expect(paramsFrom(42)).To(BeNil())
Expect(paramsFrom("string")).To(BeNil())
})
})