1
0
mirror of https://github.com/astaxie/beego.git synced 2024-06-18 12:24:14 +00:00
Beego/utils_test.go

46 lines
858 B
Go
Raw Normal View History

2013-07-25 14:25:12 +00:00
package beego
import (
"net/url"
"testing"
)
func TestParseForm(t *testing.T) {
type user struct {
Id int
tag string `form:tag`
Name interface{} `form:"username"`
Age int `form:"age"`
Email string
}
u := user{}
form := url.Values{
"tag": []string{"no"},
"username": []string{"test"},
"age": []string{"40"},
"Email": []string{"test@gmail.com"},
}
if err := ParseForm(form, u); err == nil {
t.Fatal("nothing will be changed")
}
if err := ParseForm(form, &u); err != nil {
t.Fatal(err)
}
2013-07-25 14:50:29 +00:00
if u.Id != 0 {
t.Error("Id should not be changed")
}
if len(u.tag) != 0 {
t.Error("tag should not be changed")
}
2013-07-25 14:25:12 +00:00
if u.Name.(string) != "test" {
t.Error("should be equal")
}
if u.Age != 40 {
t.Error("should be equal")
}
if u.Email != "test@gmail.com" {
t.Error("should be equal")
}
}