Skip to content

Commit 53af1b9

Browse files
authored
tests: don't use _test suffix in service and controller tests (#944)
1 parent 654b5cc commit 53af1b9

11 files changed

Lines changed: 157 additions & 168 deletions

internal/controller/context_controller_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package controller_test
1+
package controller
22

33
import (
44
"encoding/json"
@@ -9,7 +9,6 @@ import (
99
"github.com/gin-gonic/gin"
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
12-
"github.com/tinyauthapp/tinyauth/internal/controller"
1312
"github.com/tinyauthapp/tinyauth/internal/model"
1413
"github.com/tinyauthapp/tinyauth/internal/test"
1514
"github.com/tinyauthapp/tinyauth/internal/utils"
@@ -33,22 +32,22 @@ func TestContextController(t *testing.T) {
3332
middlewares: []gin.HandlerFunc{},
3433
path: "/api/context/app",
3534
expected: func() string {
36-
expectedAppContextResponse := controller.AppContextResponse{
35+
expectedAppContextResponse := AppContextResponse{
3736
Status: 200,
3837
Message: "Success",
39-
Auth: controller.ACRAuth{
38+
Auth: ACRAuth{
4039
Providers: runtime.ConfiguredProviders,
4140
},
42-
OAuth: controller.ACROAuth{
41+
OAuth: ACROAuth{
4342
AutoRedirect: cfg.OAuth.AutoRedirect,
4443
},
45-
UI: controller.ACRUI{
44+
UI: ACRUI{
4645
Title: cfg.UI.Title,
4746
ForgotPasswordMessage: cfg.UI.ForgotPasswordMessage,
4847
BackgroundImage: cfg.UI.BackgroundImage,
4948
WarningsEnabled: cfg.UI.WarningsEnabled,
5049
},
51-
App: controller.ACRApp{
50+
App: ACRApp{
5251
AppURL: runtime.AppURL,
5352
CookieDomain: runtime.CookieDomain,
5453
TrustedDomains: runtime.TrustedDomains,
@@ -64,7 +63,7 @@ func TestContextController(t *testing.T) {
6463
middlewares: []gin.HandlerFunc{},
6564
path: "/api/context/user",
6665
expected: func() string {
67-
expectedUserContextResponse := controller.UserContextResponse{
66+
expectedUserContextResponse := UserContextResponse{
6867
Status: 401,
6968
Message: "Unauthorized",
7069
}
@@ -92,10 +91,10 @@ func TestContextController(t *testing.T) {
9291
},
9392
path: "/api/context/user",
9493
expected: func() string {
95-
expectedUserContextResponse := controller.UserContextResponse{
94+
expectedUserContextResponse := UserContextResponse{
9695
Status: 200,
9796
Message: "Success",
98-
Auth: controller.UCRAuth{
97+
Auth: UCRAuth{
9998
Authenticated: true,
10099
Username: "johndoe",
101100
Name: "John Doe",
@@ -121,7 +120,7 @@ func TestContextController(t *testing.T) {
121120
group := router.Group("/api")
122121
gin.SetMode(gin.TestMode)
123122

124-
controller.NewContextController(controller.ContextControllerInput{
123+
NewContextController(ContextControllerInput{
125124
Log: log,
126125
Config: &cfg,
127126
Runtime: &runtime,

internal/controller/health_controller_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package controller_test
1+
package controller
22

33
import (
44
"encoding/json"
@@ -9,7 +9,6 @@ import (
99
"github.com/gin-gonic/gin"
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
12-
"github.com/tinyauthapp/tinyauth/internal/controller"
1312
)
1413

1514
func TestHealthController(t *testing.T) {
@@ -55,7 +54,7 @@ func TestHealthController(t *testing.T) {
5554
group := router.Group("/api")
5655
gin.SetMode(gin.TestMode)
5756

58-
controller.NewHealthController(controller.HealthControllerInput{
57+
NewHealthController(HealthControllerInput{
5958
RouterGroup: group,
6059
})
6160

internal/controller/oidc_controller_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package controller_test
1+
package controller
22

33
import (
44
"context"
@@ -15,7 +15,6 @@ import (
1515
"github.com/steveiliop56/ding"
1616
"github.com/stretchr/testify/assert"
1717
"github.com/stretchr/testify/require"
18-
"github.com/tinyauthapp/tinyauth/internal/controller"
1918
"github.com/tinyauthapp/tinyauth/internal/model"
2019
"github.com/tinyauthapp/tinyauth/internal/repository"
2120
"github.com/tinyauthapp/tinyauth/internal/repository/memory"
@@ -45,7 +44,7 @@ func TestOIDCController(t *testing.T) {
4544
require.NoError(t, err)
4645

4746
// Middleware that injects an authenticated local user into the gin context,
48-
// mimicking the context middleware that runs before the OIDC controller.
47+
// mimicking the context middleware that runs before the OIDC
4948
authedUser := func(c *gin.Context) {
5049
c.Set("context", &model.UserContext{
5150
Authenticated: true,
@@ -213,7 +212,7 @@ func TestOIDCController(t *testing.T) {
213212
{
214213
description: "Authorize complete returns a JSON error when the user context is missing",
215214
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
216-
body, err := json.Marshal(controller.AuthorizeCompleteRequest{Ticket: "some-ticket"})
215+
body, err := json.Marshal(AuthorizeCompleteRequest{Ticket: "some-ticket"})
217216
require.NoError(t, err)
218217

219218
req := httptest.NewRequest("POST", "/api/oidc/authorize-complete", strings.NewReader(string(body)))
@@ -243,7 +242,7 @@ func TestOIDCController(t *testing.T) {
243242
},
244243
},
245244
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
246-
body, err := json.Marshal(controller.AuthorizeCompleteRequest{Ticket: "some-ticket"})
245+
body, err := json.Marshal(AuthorizeCompleteRequest{Ticket: "some-ticket"})
247246
require.NoError(t, err)
248247

249248
req := httptest.NewRequest("POST", "/api/oidc/authorize-complete", strings.NewReader(string(body)))
@@ -263,7 +262,7 @@ func TestOIDCController(t *testing.T) {
263262
description: "Authorize complete returns a JSON error when the ticket is invalid",
264263
middlewares: []gin.HandlerFunc{authedUser},
265264
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
266-
body, err := json.Marshal(controller.AuthorizeCompleteRequest{Ticket: "nonexistent-ticket"})
265+
body, err := json.Marshal(AuthorizeCompleteRequest{Ticket: "nonexistent-ticket"})
267266
require.NoError(t, err)
268267

269268
req := httptest.NewRequest("POST", "/api/oidc/authorize-complete", strings.NewReader(string(body)))
@@ -291,7 +290,7 @@ func TestOIDCController(t *testing.T) {
291290
State: "state-123",
292291
})
293292

294-
body, err := json.Marshal(controller.AuthorizeCompleteRequest{Ticket: ticket})
293+
body, err := json.Marshal(AuthorizeCompleteRequest{Ticket: ticket})
295294
require.NoError(t, err)
296295

297296
req := httptest.NewRequest("POST", "/api/oidc/authorize-complete", strings.NewReader(string(body)))
@@ -837,7 +836,7 @@ func TestOIDCController(t *testing.T) {
837836
svc = nil
838837
}
839838

840-
controller.NewOIDCController(controller.OIDCControllerInput{
839+
NewOIDCController(OIDCControllerInput{
841840
Log: log,
842841
OIDCService: svc,
843842
RuntimeConfig: &runtime,

internal/controller/proxy_controller_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package controller_test
1+
package controller
22

33
import (
44
"context"
@@ -10,7 +10,6 @@ import (
1010
"github.com/steveiliop56/ding"
1111
"github.com/stretchr/testify/assert"
1212
"github.com/stretchr/testify/require"
13-
"github.com/tinyauthapp/tinyauth/internal/controller"
1413
"github.com/tinyauthapp/tinyauth/internal/model"
1514
"github.com/tinyauthapp/tinyauth/internal/repository/memory"
1615
"github.com/tinyauthapp/tinyauth/internal/service"
@@ -432,7 +431,7 @@ func TestProxyController(t *testing.T) {
432431

433432
recorder := httptest.NewRecorder()
434433

435-
controller.NewProxyController(controller.ProxyControllerInput{
434+
NewProxyController(ProxyControllerInput{
436435
Log: log,
437436
RuntimeConfig: &runtime,
438437
RouterGroup: group,

internal/controller/resources_controller_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package controller_test
1+
package controller
22

33
import (
44
"net/http/httptest"
@@ -9,7 +9,6 @@ import (
99
"github.com/gin-gonic/gin"
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
12-
"github.com/tinyauthapp/tinyauth/internal/controller"
1312
"github.com/tinyauthapp/tinyauth/internal/test"
1413
)
1514

@@ -69,7 +68,7 @@ func TestResourcesController(t *testing.T) {
6968
group := router.Group("/")
7069
gin.SetMode(gin.TestMode)
7170

72-
controller.NewResourcesController(controller.ResourcesControllerInput{
71+
NewResourcesController(ResourcesControllerInput{
7372
RouterGroup: group,
7473
Config: &cfg,
7574
})

internal/controller/user_controller_test.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package controller_test
1+
package controller
22

33
import (
44
"context"
@@ -14,7 +14,6 @@ import (
1414
"github.com/steveiliop56/ding"
1515
"github.com/stretchr/testify/assert"
1616
"github.com/stretchr/testify/require"
17-
"github.com/tinyauthapp/tinyauth/internal/controller"
1817
"github.com/tinyauthapp/tinyauth/internal/model"
1918
"github.com/tinyauthapp/tinyauth/internal/repository"
2019
"github.com/tinyauthapp/tinyauth/internal/repository/memory"
@@ -86,7 +85,7 @@ func TestUserController(t *testing.T) {
8685
description: "Should be able to login with valid credentials",
8786
middlewares: []gin.HandlerFunc{},
8887
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
89-
loginReq := controller.LoginRequest{
88+
loginReq := LoginRequest{
9089
Username: "testuser",
9190
Password: "password",
9291
}
@@ -114,7 +113,7 @@ func TestUserController(t *testing.T) {
114113
description: "Should reject login with invalid credentials",
115114
middlewares: []gin.HandlerFunc{},
116115
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
117-
loginReq := controller.LoginRequest{
116+
loginReq := LoginRequest{
118117
Username: "testuser",
119118
Password: "wrongpassword",
120119
}
@@ -135,7 +134,7 @@ func TestUserController(t *testing.T) {
135134
description: "Should rate limit on 3 invalid attempts",
136135
middlewares: []gin.HandlerFunc{},
137136
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
138-
loginReq := controller.LoginRequest{
137+
loginReq := LoginRequest{
139138
Username: "testuser",
140139
Password: "wrongpassword",
141140
}
@@ -170,7 +169,7 @@ func TestUserController(t *testing.T) {
170169
description: "Should not allow full login with totp",
171170
middlewares: []gin.HandlerFunc{},
172171
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
173-
loginReq := controller.LoginRequest{
172+
loginReq := LoginRequest{
174173
Username: "totpuser",
175174
Password: "password",
176175
}
@@ -207,7 +206,7 @@ func TestUserController(t *testing.T) {
207206
},
208207
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
209208
// First login to get a session cookie
210-
loginReq := controller.LoginRequest{
209+
loginReq := LoginRequest{
211210
Username: "testuser",
212211
Password: "password",
213212
}
@@ -264,7 +263,7 @@ func TestUserController(t *testing.T) {
264263
code, err := totp.GenerateCode("JPIEBDKJH6UGWJMX66RR3S55UFP2SGKK", time.Now())
265264
require.NoError(t, err)
266265

267-
totpReq := controller.TotpRequest{
266+
totpReq := TotpRequest{
268267
Code: code,
269268
}
270269

@@ -302,7 +301,7 @@ func TestUserController(t *testing.T) {
302301
},
303302
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
304303
for range 3 {
305-
totpReq := controller.TotpRequest{
304+
totpReq := TotpRequest{
306305
Code: "000000", // invalid code
307306
}
308307

@@ -334,7 +333,7 @@ func TestUserController(t *testing.T) {
334333
description: "Login uses name and email from user attributes",
335334
middlewares: []gin.HandlerFunc{},
336335
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
337-
loginReq := controller.LoginRequest{Username: "attruser", Password: "password"}
336+
loginReq := LoginRequest{Username: "attruser", Password: "password"}
338337
body, err := json.Marshal(loginReq)
339338
require.NoError(t, err)
340339

@@ -352,7 +351,7 @@ func TestUserController(t *testing.T) {
352351
description: "Login with TOTP uses name and email from user attributes in pending session",
353352
middlewares: []gin.HandlerFunc{},
354353
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
355-
loginReq := controller.LoginRequest{Username: "attrtotpuser", Password: "password"}
354+
loginReq := LoginRequest{Username: "attrtotpuser", Password: "password"}
356355
body, err := json.Marshal(loginReq)
357356
require.NoError(t, err)
358357

@@ -388,7 +387,7 @@ func TestUserController(t *testing.T) {
388387
code, err := totp.GenerateCode("JPIEBDKJH6UGWJMX66RR3S55UFP2SGKK", time.Now())
389388
require.NoError(t, err)
390389

391-
totpReq := controller.TotpRequest{Code: code}
390+
totpReq := TotpRequest{Code: code}
392391
body, err := json.Marshal(totpReq)
393392
require.NoError(t, err)
394393

@@ -455,7 +454,7 @@ func TestUserController(t *testing.T) {
455454
group := router.Group("/api")
456455
gin.SetMode(gin.TestMode)
457456

458-
controller.NewUserController(controller.UserControllerInput{
457+
NewUserController(UserControllerInput{
459458
Log: log,
460459
RuntimeConfig: &runtime,
461460
RouterGroup: group,

internal/controller/well_known_controller_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package controller_test
1+
package controller
22

33
import (
44
"context"
@@ -11,7 +11,6 @@ import (
1111
"github.com/steveiliop56/ding"
1212
"github.com/stretchr/testify/assert"
1313
"github.com/stretchr/testify/require"
14-
"github.com/tinyauthapp/tinyauth/internal/controller"
1514
"github.com/tinyauthapp/tinyauth/internal/repository/memory"
1615
"github.com/tinyauthapp/tinyauth/internal/service"
1716
"github.com/tinyauthapp/tinyauth/internal/test"
@@ -38,11 +37,11 @@ func TestWellKnownController(t *testing.T) {
3837

3938
assert.Equal(t, 200, recorder.Code)
4039

41-
res := controller.OpenIDConnectConfiguration{}
40+
res := OpenIDConnectConfiguration{}
4241
err := json.Unmarshal(recorder.Body.Bytes(), &res)
4342
assert.NoError(t, err)
4443

45-
expected := controller.OpenIDConnectConfiguration{
44+
expected := OpenIDConnectConfiguration{
4645
Issuer: runtime.AppURL,
4746
AuthorizationEndpoint: fmt.Sprintf("%s/authorize", runtime.AppURL),
4847
TokenEndpoint: fmt.Sprintf("%s/api/oidc/token", runtime.AppURL),
@@ -109,7 +108,7 @@ func TestWellKnownController(t *testing.T) {
109108

110109
recorder := httptest.NewRecorder()
111110

112-
controller.NewWellKnownController(controller.WellKnownControllerInput{
111+
NewWellKnownController(WellKnownControllerInput{
113112
OIDCService: oidcService,
114113
RouterGroup: &router.RouterGroup,
115114
})

internal/middleware/context_middleware_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package middleware_test
1+
package middleware
22

33
import (
44
"context"
@@ -12,7 +12,6 @@ import (
1212
"github.com/steveiliop56/ding"
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"
15-
"github.com/tinyauthapp/tinyauth/internal/middleware"
1615
"github.com/tinyauthapp/tinyauth/internal/model"
1716
"github.com/tinyauthapp/tinyauth/internal/repository"
1817
"github.com/tinyauthapp/tinyauth/internal/repository/memory"
@@ -278,7 +277,7 @@ func TestContextMiddleware(t *testing.T) {
278277
PolicyEngine: policyEngine,
279278
})
280279

281-
contextMiddleware := middleware.NewContextMiddleware(middleware.ContextMiddlewareInput{
280+
contextMiddleware := NewContextMiddleware(ContextMiddlewareInput{
282281
Log: log,
283282
RuntimeConfig: &runtime,
284283
AuthService: authService,

0 commit comments

Comments
 (0)