Skip to content

Commit

Permalink
style: simplify []string{} definitions
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
  • Loading branch information
maxatome committed Jan 15, 2024
1 parent cf7d6a8 commit 866bc2a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 54 deletions.
106 changes: 53 additions & 53 deletions helpers/tdhttp/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func TestBasicAuthHeader(t *testing.T) {
td.Cmp(t,
tdhttp.BasicAuthHeader("max", "5ecr3T"),
http.Header{"Authorization": []string{"Basic bWF4OjVlY3IzVA=="}})
http.Header{"Authorization": {"Basic bWF4OjVlY3IzVA=="}})
}

func TestNewRequest(tt *testing.T) {
Expand All @@ -31,8 +31,8 @@ func TestNewRequest(tt *testing.T) {
"Zip", "Test")

t.Cmp(req.Header, http.Header{
"Foo": []string{"Bar"},
"Zip": []string{"Test"},
"Foo": {"Bar"},
"Zip": {"Test"},
})
})

Expand All @@ -42,21 +42,21 @@ func TestNewRequest(tt *testing.T) {
"Zip")

t.Cmp(req.Header, http.Header{
"Foo": []string{"Bar"},
"Zip": []string{""},
"Foo": {"Bar"},
"Zip": {""},
})
})

t.Run("NewRequest header http.Header", func(t *td.T) {
req := tdhttp.NewRequest("GET", "/path", nil,
http.Header{
"Foo": []string{"Bar"},
"Zip": []string{"Test"},
"Foo": {"Bar"},
"Zip": {"Test"},
})

t.Cmp(req.Header, http.Header{
"Foo": []string{"Bar"},
"Zip": []string{"Test"},
"Foo": {"Bar"},
"Zip": {"Test"},
})
})

Expand All @@ -82,19 +82,19 @@ func TestNewRequest(tt *testing.T) {
)

t.Cmp(req.Header, http.Header{
"Foo": []string{"Bar"},
"Zip": []string{"Test"},
"Pipo": []string{"Bingo"},
"Hey": []string{"Yo"},
"Foo": {"Bar"},
"Zip": {"Test"},
"Pipo": {"Bingo"},
"Hey": {"Yo"},
})
})

t.Run("NewRequest header combined", func(t *td.T) {
req := tdhttp.NewRequest("GET", "/path", nil,
"H1", "V1",
http.Header{
"H1": []string{"V2"},
"H2": []string{"V1", "V2"},
"H1": {"V2"},
"H2": {"V1", "V2"},
},
"H2", "V3",
td.Flatten([]string{
Expand All @@ -109,16 +109,16 @@ func TestNewRequest(tt *testing.T) {
)

t.Cmp(req.Header, http.Header{
"H1": []string{"V1", "V2"},
"H2": []string{"V1", "V2", "V3", "V4", "V5"},
"H3": []string{"V1", "V2", "V3"},
"H1": {"V1", "V2"},
"H2": {"V1", "V2", "V3", "V4", "V5"},
"H3": {"V1", "V2", "V3"},
})
})

t.Run("NewRequest and query params", func(t *td.T) {
req := tdhttp.NewRequest("GET", "/path", nil,
url.Values{"p1": []string{"a", "b"}},
url.Values{"p2": []string{"a", "b"}},
url.Values{"p1": {"a", "b"}},
url.Values{"p2": {"a", "b"}},
tdhttp.Q{"p1": "c", "p2": []string{"c", "d"}},
tdhttp.Q{"p1": 123, "p3": true},
)
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestNewRequest(tt *testing.T) {
td.Struct(
&http.Request{
Method: "GET",
Header: http.Header{"Foo": []string{"Bar"}},
Header: http.Header{"Foo": {"Bar"}},
},
td.StructFields{
"URL": td.String("/path"),
Expand All @@ -204,7 +204,7 @@ func TestNewRequest(tt *testing.T) {
td.Struct(
&http.Request{
Method: "HEAD",
Header: http.Header{"Foo": []string{"Bar"}},
Header: http.Header{"Foo": {"Bar"}},
},
td.StructFields{
"URL": td.String("/path"),
Expand All @@ -215,7 +215,7 @@ func TestNewRequest(tt *testing.T) {
td.Struct(
&http.Request{
Method: "OPTIONS",
Header: http.Header{"Foo": []string{"Bar"}},
Header: http.Header{"Foo": {"Bar"}},
},
td.StructFields{
"URL": td.String("/path"),
Expand All @@ -226,7 +226,7 @@ func TestNewRequest(tt *testing.T) {
td.Struct(
&http.Request{
Method: "POST",
Header: http.Header{"Foo": []string{"Bar"}},
Header: http.Header{"Foo": {"Bar"}},
},
td.StructFields{
"URL": td.String("/path"),
Expand All @@ -236,16 +236,16 @@ func TestNewRequest(tt *testing.T) {
t.Cmp(
tdhttp.PostForm("/path",
url.Values{
"param1": []string{"val1", "val2"},
"param2": []string{"zip"},
"param1": {"val1", "val2"},
"param2": {"zip"},
},
"Foo", "Bar"),
td.Struct(
&http.Request{
Method: "POST",
Header: http.Header{
"Content-Type": []string{"application/x-www-form-urlencoded"},
"Foo": []string{"Bar"},
"Content-Type": {"application/x-www-form-urlencoded"},
"Foo": {"Bar"},
},
},
td.StructFields{
Expand All @@ -268,8 +268,8 @@ func TestNewRequest(tt *testing.T) {
&http.Request{
Method: "POST",
Header: http.Header{
"Content-Type": []string{"application/x-www-form-urlencoded"},
"Foo": []string{"Bar"},
"Content-Type": {"application/x-www-form-urlencoded"},
"Foo": {"Bar"},
},
},
td.StructFields{
Expand All @@ -287,8 +287,8 @@ func TestNewRequest(tt *testing.T) {
&http.Request{
Method: "POST",
Header: http.Header{
"Content-Type": []string{"application/x-www-form-urlencoded"},
"Foo": []string{"Bar"},
"Content-Type": {"application/x-www-form-urlencoded"},
"Foo": {"Bar"},
},
},
td.StructFields{
Expand All @@ -314,8 +314,8 @@ func TestNewRequest(tt *testing.T) {
&http.Request{
Method: "POST",
Header: http.Header{
"Content-Type": []string{`multipart/form-data; boundary="BoUnDaRy"`},
"Foo": []string{"Bar"},
"Content-Type": {`multipart/form-data; boundary="BoUnDaRy"`},
"Foo": {"Bar"},
},
},
td.StructFields{
Expand All @@ -331,7 +331,7 @@ func TestNewRequest(tt *testing.T) {
td.Struct(
&http.Request{
Method: "PUT",
Header: http.Header{"Foo": []string{"Bar"}},
Header: http.Header{"Foo": {"Bar"}},
},
td.StructFields{
"URL": td.String("/path"),
Expand All @@ -342,7 +342,7 @@ func TestNewRequest(tt *testing.T) {
td.Struct(
&http.Request{
Method: "PATCH",
Header: http.Header{"Foo": []string{"Bar"}},
Header: http.Header{"Foo": {"Bar"}},
},
td.StructFields{
"URL": td.String("/path"),
Expand All @@ -353,7 +353,7 @@ func TestNewRequest(tt *testing.T) {
td.Struct(
&http.Request{
Method: "DELETE",
Header: http.Header{"Foo": []string{"Bar"}},
Header: http.Header{"Foo": {"Bar"}},
},
td.StructFields{
"URL": td.String("/path"),
Expand Down Expand Up @@ -422,8 +422,8 @@ func TestNewJSONRequest(tt *testing.T) {
&http.Request{
Method: "POST",
Header: http.Header{
"Foo": []string{"Bar"},
"Content-Type": []string{"application/json"},
"Foo": {"Bar"},
"Content-Type": {"application/json"},
},
},
td.StructFields{
Expand All @@ -436,8 +436,8 @@ func TestNewJSONRequest(tt *testing.T) {
&http.Request{
Method: "PUT",
Header: http.Header{
"Foo": []string{"Bar"},
"Content-Type": []string{"application/json"},
"Foo": {"Bar"},
"Content-Type": {"application/json"},
},
},
td.StructFields{
Expand All @@ -450,8 +450,8 @@ func TestNewJSONRequest(tt *testing.T) {
&http.Request{
Method: "PATCH",
Header: http.Header{
"Foo": []string{"Bar"},
"Content-Type": []string{"application/json"},
"Foo": {"Bar"},
"Content-Type": {"application/json"},
},
},
td.StructFields{
Expand All @@ -464,8 +464,8 @@ func TestNewJSONRequest(tt *testing.T) {
&http.Request{
Method: "DELETE",
Header: http.Header{
"Foo": []string{"Bar"},
"Content-Type": []string{"application/json"},
"Foo": {"Bar"},
"Content-Type": {"application/json"},
},
},
td.StructFields{
Expand Down Expand Up @@ -522,8 +522,8 @@ func TestNewXMLRequest(tt *testing.T) {
&http.Request{
Method: "POST",
Header: http.Header{
"Foo": []string{"Bar"},
"Content-Type": []string{"application/xml"},
"Foo": {"Bar"},
"Content-Type": {"application/xml"},
},
},
td.StructFields{
Expand All @@ -536,8 +536,8 @@ func TestNewXMLRequest(tt *testing.T) {
&http.Request{
Method: "PUT",
Header: http.Header{
"Foo": []string{"Bar"},
"Content-Type": []string{"application/xml"},
"Foo": {"Bar"},
"Content-Type": {"application/xml"},
},
},
td.StructFields{
Expand All @@ -550,8 +550,8 @@ func TestNewXMLRequest(tt *testing.T) {
&http.Request{
Method: "PATCH",
Header: http.Header{
"Foo": []string{"Bar"},
"Content-Type": []string{"application/xml"},
"Foo": {"Bar"},
"Content-Type": {"application/xml"},
},
},
td.StructFields{
Expand All @@ -564,8 +564,8 @@ func TestNewXMLRequest(tt *testing.T) {
&http.Request{
Method: "DELETE",
Header: http.Header{
"Foo": []string{"Bar"},
"Content-Type": []string{"application/xml"},
"Foo": {"Bar"},
"Content-Type": {"application/xml"},
},
},
td.StructFields{
Expand Down
2 changes: 1 addition & 1 deletion helpers/tdhttp/test_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func TestNewTestAPI(t *testing.T) {
mockT = tdutil.NewT("test")
td.CmpFalse(t,
tdhttp.NewTestAPI(mockT, mux).
PostForm("/any", url.Values{"p1": []string{"v1"}, "p2": []string{"v2"}}).
PostForm("/any", url.Values{"p1": {"v1"}, "p2": {"v2"}}).
CmpStatus(200).
CmpHeader(containsKey).
CmpBody("POST!\n---\np1=v1&p2=v2").
Expand Down

0 comments on commit 866bc2a

Please sign in to comment.