Exemplo n.º 1
0
func assertPathMatchHandler(t *testing.T, handler *PathMatchHandler, path, method string, message string) bool {

	if assert.NotNil(t, handler) {

		ctx := context_test.MakeTestContextWithDetails(path, method)

		willHandle, _ := handler.WillHandle(ctx)
		if assert.True(t, willHandle, fmt.Sprintf("This handler is expected to handle it: %s", message)) {

			// make sure the method is in the list
			methodFound := false
			for _, methodInList := range handler.HttpMethods {
				if methodInList == method {
					methodFound = true
					break
				}
			}

			return assert.True(t, methodFound, "Method (%s) should be in the method list (%s)", method, handler.HttpMethods)
		}

	}

	return false

}
Exemplo n.º 2
0
func TestPathMatches_WithHttpMethod(t *testing.T) {

	pathPattern, _ := paths.NewPathPattern("people/123")

	h := NewPathMatchHandler(pathPattern, HandlerExecutionFunc(func(c context.Context) error { return nil }))
	h.HttpMethods = []string{"POST"}

	ctx := context_test.MakeTestContextWithDetails("/people/123", "GET")

	willHandle, _ := h.WillHandle(ctx)
	assert.Equal(t, false, willHandle)

	ctx2 := context_test.MakeTestContextWithDetails("/people/123", "POST")

	willHandle, _ = h.WillHandle(ctx2)
	assert.Equal(t, true, willHandle)

}