Skip to content

Commit

Permalink
fix bind test errors (#1950)
Browse files Browse the repository at this point in the history
* test(transport): fix assertion condition error

* test(transport): it need a unparsed request
  • Loading branch information
Donglong authored and tonybase committed May 31, 2022
1 parent 11273fc commit 65e5d68
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions transport/http/binding/bind_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package binding

import (
"io"
"net/http"
"net/url"
"reflect"
"strings"
"testing"
)

Expand All @@ -30,15 +32,15 @@ func TestBindQuery(t *testing.T) {
target: &p1,
},
wantErr: false,
want: TestBind{"kratos", "https://go-kratos.dev/"},
want: &TestBind{"kratos", "https://go-kratos.dev/"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := BindQuery(tt.args.vars, tt.args.target); (err != nil) != tt.wantErr {
t.Errorf("BindQuery() error = %v, wantErr %v", err, tt.wantErr)
}
if reflect.DeepEqual(tt.args.target, tt.want) {
if !tt.wantErr && !reflect.DeepEqual(tt.args.target, tt.want) {
t.Errorf("BindQuery() target = %v, want %v", tt.args.target, tt.want)
}
})
Expand Down Expand Up @@ -73,11 +75,15 @@ func TestBindForm(t *testing.T) {
{
name: "error is nil",
args: args{
req: &http.Request{Form: map[string][]string{"name": {"kratos"}, "url": {"https://go-kratos.dev/"}}},
req: &http.Request{
Method: "POST",
Header: http.Header{"Content-Type": {"application/x-www-form-urlencoded; param=value"}},
Body: io.NopCloser(strings.NewReader("name=kratos&url=https://go-kratos.dev/")),
},
target: &p1,
},
wantErr: false,
want: TestBind{"kratos", "https://go-kratos.dev/"},
want: &TestBind{"kratos", "https://go-kratos.dev/"},
},
}
for _, tt := range tests {
Expand All @@ -86,8 +92,8 @@ func TestBindForm(t *testing.T) {
if (err != nil) != tt.wantErr {
t.Errorf("BindForm() error = %v, wantErr %v", err, tt.wantErr)
}
if err != nil && reflect.DeepEqual(tt.args.target, tt.want) {
t.Errorf("BindQuery() target = %v, want %v", tt.args.target, tt.want)
if !tt.wantErr && !reflect.DeepEqual(tt.args.target, tt.want) {
t.Errorf("BindForm() target = %v, want %v", tt.args.target, tt.want)
}
})
}
Expand Down

0 comments on commit 65e5d68

Please sign in to comment.