MCPcopy Index your code
hub / github.com/tinyauthapp/tinyauth / TestGetContext

Function TestGetContext

internal/utils/app_utils_test.go:132–152  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

130}
131
132func TestGetContext(t *testing.T) {
133 // Setup
134 gin.SetMode(gin.TestMode)
135 c, _ := gin.CreateTestContext(nil)
136
137 // Normal case
138 c.Set("context", &config.UserContext{Username: "testuser"})
139 result, err := utils.GetContext(c)
140 assert.NilError(t, err)
141 assert.Equal(t, "testuser", result.Username)
142
143 // Case with no context
144 c.Set("context", nil)
145 _, err = utils.GetContext(c)
146 assert.Error(t, err, "invalid user context in request")
147
148 // Case with invalid context type
149 c.Set("context", "invalid type")
150 _, err = utils.GetContext(c)
151 assert.Error(t, err, "invalid user context in request")
152}
153
154func TestIsRedirectSafe(t *testing.T) {
155 // Setup

Callers

nothing calls this directly

Calls 1

GetContextFunction · 0.92

Tested by

no test coverage detected