Skip to content

Testing Custom Context #2158

Answered by jordan-rash
jordan-rash asked this question in Q&A
Discussion options

You must be logged in to vote

Ehh, its funny how you can stare at something for hours, then as soon as you ask for help, you figure it out...thanks for looking...ill leave this here incase someone else gets confused like i did.

package main

import (
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/labstack/echo/v4"
	"github.com/stretchr/testify/assert"
)

func TestCustomContext(t *testing.T) {
	e := echo.New()
	e.Use(CustomContextMiddleware)

	req := httptest.NewRequest(
		http.MethodGet,
		"/",
		nil,
	)
	rec := httptest.NewRecorder()
	ctx := e.NewContext(req, rec)
	c := &CustomContext{
		Context: ctx,
		Custom:  true,
	}
	assert.NoError(t, get200(c))
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jordan-rash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant