Ejemplo n.º 1
0
func TestMockCallApi(t *testing.T) {
	c := kmgHttp.NewTestContext().
		SetPost().
		SetInStr("a", "1")
	TestObj{}.TestFunc(c)
	Equal(c.GetResponseString(), "2")
}
Ejemplo n.º 2
0
func TestCallApiGet(t *testing.T) {
	kmgControllerRunner.RegisterController(TestObj{})
	out := CallApiByHttp(
		"/?n=github.com.bronze1man.kmg.kmgControllerRunner.kmgControllerTest.TestObj.TestFunc&a=10",
		kmgHttp.NewTestContext(),
	)
	Equal(out, "11")
}
Ejemplo n.º 3
0
func TestCallApiPost(t *testing.T) {
	kmgControllerRunner.RegisterController(TestObj{})
	out := CallApiByHttp(
		"/?n=github.com.bronze1man.kmg.kmgControllerRunner.kmgControllerTest.TestObj.TestFunc",
		kmgHttp.NewTestContext().
			SetPost().
			SetInStr("a", "1"))
	Equal(out, "2")
}
Ejemplo n.º 4
0
func TestUploadFile(t *testing.T) {
	testFileRealPath := "/tmp/UFile.md"
	file, err := os.Create(testFileRealPath)
	defer file.Close()
	if err != nil {
		panic(err)
	}
	file.WriteString("hello")
	file.Close()
	kmgControllerRunner.RegisterController(TestObj{})
	out := CallApiByHttpWithUploadFile("/?n=github.com.bronze1man.kmg.kmgControllerRunner.kmgControllerTest.TestObj.TestHandleUploadFile",
		kmgHttp.NewTestContext().
			SetPost().
			SetInStr("a", "10"),
		map[string]string{
			"UFile": "/tmp/UFile.md",
		},
	)
	Equal(out, "UFile.md 10 hello")
}