Пример #1
0
func (td *TDApiTest) RunTests(t *testing.T) {
	for _, route := range td.TestContainers {
		for _, testToRun := range route.TestsToRun {
			req, err := http.NewRequest(route.Method, route.Path, nil)
			funcName := runtime.FuncForPC(reflect.ValueOf(testToRun.TestFunc).Pointer()).Name()

			assert.Nil(t, err)
			req.Form = testToRun.Params

			for k, v := range testToRun.Header {
				req.Header.Set(k, v)
			}

			td.beforeEach()

			if funcName != "" {
				t.Logf("Executing test: %s, function called: %s", testToRun.Desc, funcName)
			} else {
				t.Logf("Executing test: %s", testToRun.Desc)
			}

			td.router.ServeHTTP(td.RespRec, req)
			assert.Equal(t, testToRun.Status, td.RespRec.Code)
			content, err := ioutil.ReadAll(td.RespRec.Body)
			assert.Nil(t, err)
			if testToRun.TestFunc != nil {
				testToRun.TestFunc(t, strings.TrimSpace(string(content)))
			}
		}
	}
}
Пример #2
0
func checkHelloRoute(t *testing.T, result string) {
	expected, err := json.Marshal(urlParams)

	assert.Nil(t, err)
	assert.Equal(t, result, string(expected))
}