forked from clevergo/dnspodcn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
values_test.go
60 lines (51 loc) · 1.14 KB
/
values_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
// Copyright 2020 CleverGo. All rights reserved.
// Use of this source code is governed by a MIT style license that can be found
// in the LICENSE file.
package dnspodcn
import (
"fmt"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestValuesSet(t *testing.T) {
cases := []struct {
key, value string
}{
{"foo", ""},
{"foo", "bar"},
{"foo", "fizz"},
{"foo", "buzz"},
}
vs := Values{}
for _, test := range cases {
vs.Set(test.key, test.value)
assert.Equal(t, test.value, vs[test.key])
}
}
func TestValuesGet(t *testing.T) {
vs := Values{
"foo": "bar",
"fizz": "buzz",
}
assert.Equal(t, "", vs.Get("nil"))
assert.Equal(t, "bar", vs.Get("foo"))
assert.Equal(t, "buzz", vs.Get("fizz"))
}
func TestValuesDel(t *testing.T) {
vs := Values{
"foo": "bar",
}
vs.Del("foo")
_, ok := vs["foo"]
assert.False(t, ok)
}
func TestValuesEncode(t *testing.T) {
vs := Values{}
assert.Equal(t, "", vs.Encode())
vs.Set("foo", "bar")
assert.Equal(t, "foo=bar", vs.Encode())
email := "fizz@buzz.com"
vs.Set("email", email)
assert.Equal(t, fmt.Sprintf("%s=%s&%s", "email", url.QueryEscape(email), "foo=bar"), vs.Encode())
}