|
1 | 1 | package httpbin_test
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
| 5 | + "net/url" |
4 | 6 | "testing"
|
5 | 7 |
|
6 | 8 | webtest "github.com/podhmo/go-webtest"
|
@@ -108,4 +110,62 @@ func TestUnit(t *testing.T) {
|
108 | 110 |
|
109 | 111 | // todo: assertion db check
|
110 | 112 | })
|
| 113 | + |
| 114 | + t.Run("get", func(t *testing.T) { |
| 115 | + client = client.Bind( |
| 116 | + hook.ExpectCode(200), |
| 117 | + ) |
| 118 | + |
| 119 | + cases := []struct { |
| 120 | + path string |
| 121 | + query url.Values |
| 122 | + expected interface{} |
| 123 | + }{ |
| 124 | + { |
| 125 | + path: "/get", |
| 126 | + expected: map[string][]string{}, |
| 127 | + }, |
| 128 | + { |
| 129 | + path: "/get?xxx=111", |
| 130 | + expected: map[string][]string{"xxx": []string{"111"}}, |
| 131 | + }, |
| 132 | + { |
| 133 | + path: "/get?xxx=111", |
| 134 | + query: webtest.MustParseQuery("yyy=222"), |
| 135 | + expected: map[string][]string{ |
| 136 | + "xxx": []string{"111"}, |
| 137 | + "yyy": []string{"222"}, |
| 138 | + }, |
| 139 | + }, |
| 140 | + { |
| 141 | + path: "/get?xxx=111", |
| 142 | + query: webtest.MustParseQuery("yyy=222&xxx=333"), |
| 143 | + expected: map[string][]string{ |
| 144 | + "xxx": []string{"333", "111"}, |
| 145 | + "yyy": []string{"222"}, |
| 146 | + }, |
| 147 | + }, |
| 148 | + } |
| 149 | + for i, c := range cases { |
| 150 | + c := c |
| 151 | + t.Run(fmt.Sprintf("case%d", i), func(t *testing.T) { |
| 152 | + var options []func(*webtest.Config) |
| 153 | + if c.query != nil { |
| 154 | + options = append(options, webtest.WithQuery(c.query)) |
| 155 | + } |
| 156 | + got, _, teardown := client.Do(t, "GET", c.path, options...) |
| 157 | + defer teardown() |
| 158 | + |
| 159 | + var data map[string]interface{} |
| 160 | + noerror.Must(t, got.ParseJSONData(&data)) |
| 161 | + |
| 162 | + noerror.Should(t, |
| 163 | + jsonequal.ShouldBeSame( |
| 164 | + jsonequal.From(data["args"]), |
| 165 | + jsonequal.From(c.expected), |
| 166 | + ), |
| 167 | + ) |
| 168 | + }) |
| 169 | + } |
| 170 | + }) |
111 | 171 | }
|
0 commit comments