Add ToURLE tests

This commit is contained in:
andrewheberle 2019-06-24 10:16:04 +08:00 committed by GitHub
parent ff7c360a3e
commit 2dd4a14d2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1285,3 +1285,31 @@ func TestToDurationE(t *testing.T) {
assert.Equal(t, test.expect, v, errmsg)
}
}
func TestToURLE(t *testing.T) {
type args struct {
i interface{}
}
tests := []struct {
name string
args args
wantU *url.URL
wantErr bool
}{
{"url", args{&url.URL{Scheme: "https", Host: "example.net", Path: "/"}}, &url.URL{Scheme: "https", Host: "example.net", Path: "/"}, false},
{"string", args{string("https://example.net/")}, &url.URL{Scheme: "https", Host: "example.net", Path: "/"}, false},
{"invalid", args{int(100)}, nil, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotU, err := ToURLE(tt.args.i)
if (err != nil) != tt.wantErr {
t.Errorf("ToURLE() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(gotU, tt.wantU) {
t.Errorf("ToURLE() = %v, want %v", gotU, tt.wantU)
}
})
}
}