Beispiel #1
0
// DefaultHttpHandler gets the HttpHandler that can be used to handle
// requests.
//
// If nothing has been set using SetDefaultHttpHandler(), a fresh one
// will be created and served each time this function is called.
func DefaultHttpHandler() *handlers.HttpHandler {

	if defaultHttpHandler == nil {
		defaultHttpHandler = handlers.NewHttpHandler(CodecService)
	}

	return defaultHttpHandler

}
Beispiel #2
0
func TestRoutes(t *testing.T) {

	// make a test HttpHandler and use it
	codecService := new(services.WebCodecService)
	handler := handlers.NewHttpHandler(codecService)
	goweb.SetDefaultHttpHandler(handler)

	// call the target code
	mapRoutes()

	goweb.Test(t, "GET people/me", func(t *testing.T, response *testifyhttp.TestResponseWriter) {

		// should be a redirect
		assert.Equal(t, http.StatusFound, response.WrittenHeaderInt, "Status code should be correct")

	})

}
Beispiel #3
0
func TestTestFunc(t *testing.T) {

	// keep track of things that occur
	var actualT *testing.T
	var called bool = false

	// setup test objects
	testingObj := new(testing.T)

	// map something to a handler
	testCodecService := new(services.WebCodecService)
	handler := handlers.NewHttpHandler(testCodecService)

	// map the target method
	handler.Map("GET", "people/{id}", func(ctx context.Context) error {
		return Respond.With(ctx, 201, []byte("Hello Goweb"))
	})

	// call the target method
	TestOn(testingObj, handler, "GET people/123", func(passedT *testing.T, response *testifyhttp.TestResponseWriter) {

		called = true

		// save the passed in T object
		actualT = passedT

	})

	if assert.True(t, called, "The assertion method should be called.") {

		// make assertions about what happened
		assert.Equal(t, actualT, testingObj, "Passed in T wasn't right")

	}

}