1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 21:11:29 +00:00

controller_test.go 既然叫test,那就按照go的规则进行test吧

This commit is contained in:
nkbai 2015-11-24 14:55:59 +08:00
parent 83696a40f6
commit 5e915cb614

View File

@ -17,42 +17,48 @@ package beego
import ( import (
"fmt" "fmt"
"github.com/astaxie/beego/context" "github.com/astaxie/beego/context"
"testing"
) )
func ExampleGetInt() { func TestGetInt(t *testing.T) {
i := &context.BeegoInput{Params: map[string]string{"age": "40"}} i := &context.BeegoInput{Params: map[string]string{"age": "40"}}
ctx := &context.Context{Input: i} ctx := &context.Context{Input: i}
ctrlr := Controller{Ctx: ctx} ctrlr := Controller{Ctx: ctx}
val, _ := ctrlr.GetInt("age") val, _ := ctrlr.GetInt("age")
fmt.Printf("%T", val)
//Output: int if (val != 40) {
t.Errorf("TestGetInt expect 40,get %T,%v", val, val)
}
} }
func ExampleGetInt8() { func TestGetInt8(t *testing.T) {
i := &context.BeegoInput{Params: map[string]string{"age": "40"}} i := &context.BeegoInput{Params: map[string]string{"age": "40"}}
ctx := &context.Context{Input: i} ctx := &context.Context{Input: i}
ctrlr := Controller{Ctx: ctx} ctrlr := Controller{Ctx: ctx}
val, _ := ctrlr.GetInt8("age") val, _ := ctrlr.GetInt8("age")
fmt.Printf("%T", val) if val != 40 {
t.Errorf("TestGetInt8 expect 40,get %T,%v", val, val)
}
//Output: int8 //Output: int8
} }
func ExampleGetInt16() { func TestGetInt16(t *testing.T) {
i := &context.BeegoInput{Params: map[string]string{"age": "40"}} i := &context.BeegoInput{Params: map[string]string{"age": "40"}}
ctx := &context.Context{Input: i} ctx := &context.Context{Input: i}
ctrlr := Controller{Ctx: ctx} ctrlr := Controller{Ctx: ctx}
val, _ := ctrlr.GetInt16("age") val, _ := ctrlr.GetInt16("age")
fmt.Printf("%T", val) if val != 40 {
//Output: int16 t.Errorf("TestGetInt16 expect 40,get %T,%v", val, val)
}
} }
func ExampleGetInt32() { func TestGetInt32(t *testing.T) {
i := &context.BeegoInput{Params: map[string]string{"age": "40"}} i := &context.BeegoInput{Params: map[string]string{"age": "40"}}
ctx := &context.Context{Input: i} ctx := &context.Context{Input: i}
@ -60,16 +66,19 @@ func ExampleGetInt32() {
val, _ := ctrlr.GetInt32("age") val, _ := ctrlr.GetInt32("age")
fmt.Printf("%T", val) fmt.Printf("%T", val)
//Output: int32 if val != 40 {
t.Errorf("TestGetInt32 expect 40,get %T,%v", val, val)
}
} }
func ExampleGetInt64() { func TestGetInt64(t *testing.T) {
i := &context.BeegoInput{Params: map[string]string{"age": "40"}} i := &context.BeegoInput{Params: map[string]string{"age": "40"}}
ctx := &context.Context{Input: i} ctx := &context.Context{Input: i}
ctrlr := Controller{Ctx: ctx} ctrlr := Controller{Ctx: ctx}
val, _ := ctrlr.GetInt64("age") val, _ := ctrlr.GetInt64("age")
fmt.Printf("%T", val) if val != 40 {
//Output: int64 t.Errorf("TestGeetInt64 expect 40,get %T,%v", val, val)
}
} }