11package middleware
22
33import (
4- "context"
4+ _ "context"
55 "testing"
66
77 "github.com/stretchr/testify/assert"
8- "github.com/stretchr/testify/mock"
9-
10- "github.com/platform-mesh/golang-commons/policy_services"
8+ _ "github.com/stretchr/testify/mock"
119)
1210
13- // MockTenantRetriever is a mock implementation of TenantRetriever
14- type MockTenantRetriever struct {
15- mock.Mock
16- }
17-
18- func (m * MockTenantRetriever ) RetrieveTenant (ctx context.Context ) (string , error ) {
19- args := m .Called (ctx )
20- return args .String (0 ), args .Error (1 )
21- }
22-
2311func TestCreateAuthMiddleware (t * testing.T ) {
24- mockRetriever := & MockTenantRetriever {}
25-
26- middlewares := CreateAuthMiddleware (mockRetriever )
12+ middlewares := CreateAuthMiddleware ()
2713
2814 // Should return 3 middlewares: StoreWebToken, StoreAuthHeader, StoreSpiffeHeader
2915 assert .Len (t , middlewares , 3 )
@@ -35,7 +21,7 @@ func TestCreateAuthMiddleware(t *testing.T) {
3521}
3622
3723func TestCreateAuthMiddleware_WithNilRetriever (t * testing.T ) {
38- middlewares := CreateAuthMiddleware (nil )
24+ middlewares := CreateAuthMiddleware ()
3925
4026 // Should still return 3 middlewares even with nil retriever
4127 assert .Len (t , middlewares , 3 )
@@ -47,9 +33,7 @@ func TestCreateAuthMiddleware_WithNilRetriever(t *testing.T) {
4733}
4834
4935func TestCreateAuthMiddleware_ReturnsCorrectMiddlewares (t * testing.T ) {
50- mockRetriever := & MockTenantRetriever {}
51-
52- middlewares := CreateAuthMiddleware (mockRetriever )
36+ middlewares := CreateAuthMiddleware ()
5337
5438 // Verify we get exactly 3 middlewares
5539 assert .Len (t , middlewares , 3 )
@@ -62,16 +46,3 @@ func TestCreateAuthMiddleware_ReturnsCorrectMiddlewares(t *testing.T) {
6246 // This is implicitly tested by the fact that the function compiles and returns without error
6347 }
6448}
65-
66- // Test that implements policy_services.TenantRetriever interface
67- func TestTenantRetrieverInterface (t * testing.T ) {
68- mockRetriever := & MockTenantRetriever {}
69-
70- // Verify our mock implements the interface
71- var retriever policy_services.TenantRetriever = mockRetriever
72- assert .NotNil (t , retriever )
73-
74- // Test that we can use it with the middleware functions
75- middlewares := CreateAuthMiddleware (retriever )
76- assert .Len (t , middlewares , 3 )
77- }
0 commit comments