Switch to stretchr/testify / mockery for mocks
testify is used throughout the codebase; this switches mocks from gomock to testify with the help of mockery for code generation. Handlers and mocks in test/utils/oidc are moved to a new package: mockery operates package by package, and requires packages to build correctly; test/utils/oidc/testserver.go relies on the mocks and fails to build when they are removed. Moving the interface and mocks to a different package allows mockery to process that package without having to build testserver.go. Signed-off-by: Stephen Kitt <skitt@redhat.com>
This commit is contained in:
@@ -32,8 +32,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/mock/gomock"
|
||||
"gopkg.in/square/go-jose.v2"
|
||||
"k8s.io/kubernetes/test/utils/oidc/handlers"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -50,17 +50,17 @@ var (
|
||||
|
||||
type TestServer struct {
|
||||
httpServer *httptest.Server
|
||||
tokenHandler *MockTokenHandler
|
||||
jwksHandler *MockJWKsHandler
|
||||
tokenHandler *handlers.MockTokenHandler
|
||||
jwksHandler *handlers.MockJWKsHandler
|
||||
}
|
||||
|
||||
// JwksHandler is getter of JSON Web Key Sets handler
|
||||
func (ts *TestServer) JwksHandler() *MockJWKsHandler {
|
||||
func (ts *TestServer) JwksHandler() *handlers.MockJWKsHandler {
|
||||
return ts.jwksHandler
|
||||
}
|
||||
|
||||
// TokenHandler is getter of JWT token handler
|
||||
func (ts *TestServer) TokenHandler() *MockTokenHandler {
|
||||
func (ts *TestServer) TokenHandler() *handlers.MockTokenHandler {
|
||||
return ts.tokenHandler
|
||||
}
|
||||
|
||||
@@ -98,17 +98,14 @@ func BuildAndRunTestServer(t *testing.T, caPath, caKeyPath, issuerOverride strin
|
||||
}
|
||||
httpServer.StartTLS()
|
||||
|
||||
mockCtrl := gomock.NewController(t)
|
||||
|
||||
t.Cleanup(func() {
|
||||
mockCtrl.Finish()
|
||||
httpServer.Close()
|
||||
})
|
||||
|
||||
oidcServer := &TestServer{
|
||||
httpServer: httpServer,
|
||||
tokenHandler: NewMockTokenHandler(mockCtrl),
|
||||
jwksHandler: NewMockJWKsHandler(mockCtrl),
|
||||
tokenHandler: handlers.NewMockTokenHandler(t),
|
||||
jwksHandler: handlers.NewMockJWKsHandler(t),
|
||||
}
|
||||
|
||||
issuer := httpServer.URL
|
||||
@@ -197,10 +194,10 @@ func TokenHandlerBehaviorReturningPredefinedJWT[K JosePrivateKey](
|
||||
t *testing.T,
|
||||
privateKey K,
|
||||
claims map[string]interface{}, accessToken, refreshToken string,
|
||||
) func() (Token, error) {
|
||||
) func() (handlers.Token, error) {
|
||||
t.Helper()
|
||||
|
||||
return func() (Token, error) {
|
||||
return func() (handlers.Token, error) {
|
||||
signer, err := jose.NewSigner(jose.SigningKey{Algorithm: GetSignatureAlgorithm(privateKey), Key: privateKey}, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -212,7 +209,7 @@ func TokenHandlerBehaviorReturningPredefinedJWT[K JosePrivateKey](
|
||||
idToken, err := idTokenSignature.CompactSerialize()
|
||||
require.NoError(t, err)
|
||||
|
||||
return Token{
|
||||
return handlers.Token{
|
||||
IDToken: idToken,
|
||||
AccessToken: accessToken,
|
||||
RefreshToken: refreshToken,
|
||||
|
Reference in New Issue
Block a user