-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathauth_mock.go
More file actions
34 lines (28 loc) · 863 Bytes
/
auth_mock.go
File metadata and controls
34 lines (28 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package scalingo
import (
"context"
"time"
"github.com/golang-jwt/jwt/v5"
"go.uber.org/mock/gomock"
httpclient "github.com/Scalingo/go-scalingo/v11/http"
"github.com/Scalingo/go-scalingo/v11/http/httpmock"
)
func MockAuth(ctrl *gomock.Controller) *httpmock.MockClient {
mock := httpmock.NewMockClient(ctrl)
mock.EXPECT().DoRequest(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, _ *httpclient.APIRequest, data any) error {
claims := &jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(5 * time.Minute)),
}
jwtToken := jwt.NewWithClaims(jwt.SigningMethodNone, claims)
jwt, err := jwtToken.SignedString(jwt.UnsafeAllowNoneSignatureType)
if err != nil {
return err
}
if data != nil {
res, _ := data.(*BearerTokenRes)
res.Token = jwt
}
return nil
}).AnyTimes()
return mock
}