forked from litmuschaos/litmus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ChaosCenter]: Add unit tests to k8s and cluster package in GraphQL s…
…erver (litmuschaos#3971) * feat: add unit tests to k8s package Signed-off-by: namkyu1999 <[email protected]> * feat: add unit tests to cluster package Signed-off-by: namkyu1999 <[email protected]> * fix: fix codacy analysis Signed-off-by: namkyu1999 <[email protected]> * fix: fix test cases Signed-off-by: namkyu1999 <[email protected]> * fix: chore Signed-off-by: namkyu1999 <[email protected]> * fix: rename function Signed-off-by: namkyu1999 <[email protected]> --------- Signed-off-by: namkyu1999 <[email protected]> Signed-off-by: SohamRatnaparkhi <[email protected]>
- Loading branch information
1 parent
84680f9
commit fbd7961
Showing
17 changed files
with
1,948 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
litmus-portal/graphql-server/pkg/cluster/cluster_jwt_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package cluster_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/cluster" | ||
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/utils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestCreateClusterJWT tests the CreateClusterJWT function | ||
func TestCreateClusterJWT(t *testing.T) { | ||
// given | ||
utils.Config.JwtSecret = uuid.NewString() | ||
// when | ||
_, err := cluster.CreateClusterJWT(uuid.NewString()) | ||
// then | ||
assert.NoError(t, err) | ||
} | ||
|
||
// TestValidateClusterJWT tests the ValidateClusterJWT function | ||
func TestValidateClusterJWT(t *testing.T) { | ||
// given | ||
testcases := []struct { | ||
name string | ||
wantError bool | ||
given func() string | ||
}{ | ||
{ | ||
name: "success", | ||
wantError: false, | ||
given: func() string { | ||
utils.Config.JwtSecret = uuid.NewString() | ||
token, _ := cluster.CreateClusterJWT(uuid.NewString()) | ||
return token | ||
}, | ||
}, | ||
{ | ||
name: "failure: invalid token", | ||
wantError: true, | ||
given: func() string { | ||
return uuid.NewString() | ||
}, | ||
}, | ||
{ | ||
name: "failure: valid token but secret changed", | ||
wantError: true, | ||
given: func() string { | ||
utils.Config.JwtSecret = uuid.NewString() | ||
token, _ := cluster.CreateClusterJWT(uuid.NewString()) | ||
utils.Config.JwtSecret = uuid.NewString() | ||
return token | ||
}, | ||
}, | ||
} | ||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
// given | ||
token := tc.given() | ||
// when | ||
_, err := cluster.ValidateClusterJWT(token) | ||
// then | ||
if tc.wantError { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.