Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
Fix linter erros
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith Mattix II committed Nov 12, 2021
1 parent 8d77900 commit b2ba37f
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions cmd/gtoken/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import (
"github.com/stretchr/testify/mock"
)

const (
testEmail = "[email protected]"
testToken = "jwt.token"
)

//nolint:funlen
func Test_generateIDToken(t *testing.T) {
type args struct {
Expand All @@ -35,10 +40,10 @@ func Test_generateIDToken(t *testing.T) {
{
name: "one time token generation",
args: args{
file: "jwt.token",
file: testToken,
},
fields: fields{
email: "[email protected]",
email: testEmail,
jwt: "whatever",
},
mockInit: func(ctx context.Context, sa *gcp.MockServiceAccountInfo, token *gcp.MockToken, args args, fields fields) {
Expand All @@ -50,10 +55,10 @@ func Test_generateIDToken(t *testing.T) {
{
name: "one time token generation from email",
args: args{
file: "jwt.token",
file: testToken,
},
fields: fields{
email: "[email protected]",
email: testEmail,
jwt: "whatever",
},
mockInit: func(ctx context.Context, sa *gcp.MockServiceAccountInfo, token *gcp.MockToken, args args, fields fields) {
Expand All @@ -66,11 +71,11 @@ func Test_generateIDToken(t *testing.T) {
{
name: "refresh token generation",
args: args{
file: "jwt.token",
file: testToken,
refresh: true,
},
fields: fields{
email: "[email protected]",
email: testEmail,
jwt: "whatever",
},
mockInit: func(ctx context.Context, sa *gcp.MockServiceAccountInfo, token *gcp.MockToken, args args, fields fields) {
Expand All @@ -93,10 +98,10 @@ func Test_generateIDToken(t *testing.T) {
{
name: "failed to generate token",
args: args{
file: "jwt.token",
file: testToken,
},
fields: fields{
email: "[email protected]",
email: testEmail,
jwt: "whatever",
},
mockInit: func(ctx context.Context, sa *gcp.MockServiceAccountInfo, token *gcp.MockToken, args args, fields fields) {
Expand All @@ -109,10 +114,10 @@ func Test_generateIDToken(t *testing.T) {
{
name: "failed to write token",
args: args{
file: "jwt.token",
file: testToken,
},
fields: fields{
email: "[email protected]",
email: testEmail,
jwt: "whatever",
},
mockInit: func(ctx context.Context, sa *gcp.MockServiceAccountInfo, token *gcp.MockToken, args args, fields fields) {
Expand All @@ -124,11 +129,11 @@ func Test_generateIDToken(t *testing.T) {
{
name: "failed to get duration from token",
args: args{
file: "jwt.token",
file: testToken,
refresh: true,
},
fields: fields{
email: "[email protected]",
email: testEmail,
jwt: "whatever",
},
mockInit: func(ctx context.Context, sa *gcp.MockServiceAccountInfo, token *gcp.MockToken, args args, fields fields) {
Expand Down Expand Up @@ -163,8 +168,8 @@ func Test_generateIDTokenCmd(t *testing.T) {
ctx := context.Background()
mockSA := &gcp.MockServiceAccountInfo{}
mockToken := &gcp.MockToken{}
fileName := "jwt.token"
email := "[email protected]"
fileName := testToken
email := testEmail
mockSA.On("GetID", mock.AnythingOfType("*context.cancelCtx")).Return(email, nil)
mockToken.On("Generate", mock.AnythingOfType("*context.cancelCtx"), email).Return("whatever", nil)
mockToken.On("WriteToFile", "whatever", fileName).Return(nil)
Expand Down Expand Up @@ -205,19 +210,17 @@ func Test_generateIDTokenCmdNoRefresh(t *testing.T) {
ctx := context.Background()
mockSA := &gcp.MockServiceAccountInfo{}
mockToken := &gcp.MockToken{}
fileName := "jwt.token"
email := "[email protected]"
mockSA.On("GetID", mock.AnythingOfType("*context.cancelCtx")).Return(email, nil)
mockToken.On("Generate", mock.AnythingOfType("*context.cancelCtx"), email).Return("whatever", nil)
mockToken.On("WriteToFile", "whatever", fileName).Return(nil)
mockSA.On("GetID", mock.AnythingOfType("*context.cancelCtx")).Return(testEmail, nil)
mockToken.On("Generate", mock.AnythingOfType("*context.cancelCtx"), testEmail).Return("whatever", nil)
mockToken.On("WriteToFile", "whatever", testToken).Return(nil)
mockToken.On("GetDuration", "whatever").Return(31*time.Second, nil)
mockToken.On("Generate", mock.AnythingOfType("*context.cancelCtx"), email).Return("whatever", nil)
mockToken.On("WriteToFile", "whatever", fileName).Return(nil)
mockToken.On("Generate", mock.AnythingOfType("*context.cancelCtx"), testEmail).Return("whatever", nil)
mockToken.On("WriteToFile", "whatever", testToken).Return(nil)

var wg sync.WaitGroup
wg.Add(1)
go func() {
err := startServerAndGenerator(ctx, mockSA, mockToken, fileName, false)
err := startServerAndGenerator(ctx, mockSA, mockToken, testToken, false)
assert.Nil(t, err, "generateIDTokenCmd should not return an error when context is canceled")
wg.Done()
}()
Expand Down

0 comments on commit b2ba37f

Please sign in to comment.