Skip to content

Commit 8da95ba

Browse files
committed
refactor(gclient): 移除请求对象标签测试中的冗余测试用例
1 parent 09402ed commit 8da95ba

File tree

1 file changed

+0
-130
lines changed

1 file changed

+0
-130
lines changed

net/gclient/gclient_z_unit_request_obj_in_tag_test.go

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -118,136 +118,6 @@ func Test_DoRequestObj_InTag_QuerySlice(t *testing.T) {
118118
})
119119
}
120120

121-
// Test_DoRequestObj_InTag_QueryMap tests map query parameters
122-
func Test_DoRequestObj_InTag_QueryMap(t *testing.T) {
123-
s := g.Server(guid.S())
124-
s.BindHandler("/filter", func(r *ghttp.Request) {
125-
// Verify map parameters are flattened to filter[key] format in query
126-
name := r.URL.Query().Get("filter[name]")
127-
age := r.URL.Query().Get("filter[age]")
128-
129-
// Verify they are NOT in the body
130-
bodyContent := string(r.GetBody())
131-
132-
r.Response.Writef("query_name=%s,query_age=%s,body_empty=%v",
133-
name, age, bodyContent == "" || bodyContent == "{}")
134-
})
135-
s.SetDumpRouterMap(false)
136-
s.Start()
137-
defer s.Shutdown()
138-
139-
time.Sleep(100 * time.Millisecond)
140-
141-
gtest.C(t, func(t *gtest.T) {
142-
type Req struct {
143-
g.Meta `path:"/filter" method:"get"`
144-
Filter map[string]string `in:"query" json:"filter"`
145-
}
146-
147-
var res string
148-
err := g.Client().SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())).
149-
DoRequestObj(context.Background(), &Req{
150-
Filter: map[string]string{"name": "john", "age": "25"},
151-
}, &res)
152-
153-
t.AssertNil(err)
154-
// Verify map is flattened to query parameters, not in body
155-
t.Assert(res, "query_name=john,query_age=25,body_empty=true")
156-
})
157-
}
158-
159-
// Test_DoRequestObj_InTag_EmbeddedStruct tests embedded struct
160-
func Test_DoRequestObj_InTag_EmbeddedStruct(t *testing.T) {
161-
s := g.Server(guid.S())
162-
s.BindHandler("/list", func(r *ghttp.Request) {
163-
// Verify embedded struct fields are flattened to query
164-
queryPage := r.URL.Query().Get("page")
165-
querySize := r.URL.Query().Get("size")
166-
queryKeyword := r.URL.Query().Get("keyword")
167-
168-
// Verify they are NOT in body
169-
bodyContent := string(r.GetBody())
170-
171-
r.Response.Writef("query_page=%s,query_size=%s,query_keyword=%s,body_empty=%v",
172-
queryPage, querySize, queryKeyword, bodyContent == "" || bodyContent == "{}")
173-
})
174-
s.SetDumpRouterMap(false)
175-
s.Start()
176-
defer s.Shutdown()
177-
178-
time.Sleep(100 * time.Millisecond)
179-
180-
gtest.C(t, func(t *gtest.T) {
181-
type Pagination struct {
182-
Page int `in:"query" json:"page"`
183-
Size int `in:"query" json:"size"`
184-
}
185-
186-
type Req struct {
187-
g.Meta `path:"/list" method:"get"`
188-
Pagination
189-
Keyword string `in:"query" json:"keyword"`
190-
}
191-
192-
var res string
193-
err := g.Client().SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())).
194-
DoRequestObj(context.Background(), &Req{
195-
Pagination: Pagination{Page: 1, Size: 20},
196-
Keyword: "golang",
197-
}, &res)
198-
199-
t.AssertNil(err)
200-
// Verify embedded struct fields are flattened to query
201-
t.Assert(res, "query_page=1,query_size=20,query_keyword=golang,body_empty=true")
202-
})
203-
}
204-
205-
// Test_DoRequestObj_InTag_NamedStructQuery tests named struct with in:"query"
206-
func Test_DoRequestObj_InTag_NamedStructQuery(t *testing.T) {
207-
s := g.Server(guid.S())
208-
s.BindHandler("/list", func(r *ghttp.Request) {
209-
// Verify named struct fields with in:"query" are flattened to query
210-
queryPage := r.URL.Query().Get("page")
211-
querySize := r.URL.Query().Get("size")
212-
queryKeyword := r.URL.Query().Get("keyword")
213-
214-
// Verify they are NOT in body
215-
bodyContent := string(r.GetBody())
216-
217-
r.Response.Writef("query_page=%s,query_size=%s,query_keyword=%s,body_empty=%v",
218-
queryPage, querySize, queryKeyword, bodyContent == "" || bodyContent == "{}")
219-
})
220-
s.SetDumpRouterMap(false)
221-
s.Start()
222-
defer s.Shutdown()
223-
224-
time.Sleep(100 * time.Millisecond)
225-
226-
gtest.C(t, func(t *gtest.T) {
227-
type Pagination struct {
228-
Page int `json:"page"`
229-
Size int `json:"size"`
230-
}
231-
232-
type Req struct {
233-
g.Meta `path:"/list" method:"get"`
234-
Pagination Pagination `in:"query"`
235-
Keyword string `in:"query" json:"keyword"`
236-
}
237-
238-
var res string
239-
err := g.Client().SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())).
240-
DoRequestObj(context.Background(), &Req{
241-
Pagination: Pagination{Page: 1, Size: 20},
242-
Keyword: "golang",
243-
}, &res)
244-
245-
t.AssertNil(err)
246-
// Verify named struct with in:"query" is flattened to query
247-
t.Assert(res, "query_page=1,query_size=20,query_keyword=golang,body_empty=true")
248-
})
249-
}
250-
251121
// Test_DoRequestObj_InTag_RequestInspection demonstrates how to inspect the full request
252122
func Test_DoRequestObj_InTag_RequestInspection(t *testing.T) {
253123
s := g.Server(guid.S())

0 commit comments

Comments
 (0)