@@ -2,14 +2,14 @@ package iam
22
33import (
44 "net/url"
5- "reflect"
65 "testing"
76
87 "github.com/aws/aws-sdk-go/service/iam"
98 "github.com/go-logr/logr"
109 corev1 "k8s.io/api/core/v1"
1110
1211 "github.com/spectrocloud-labs/valid8or-plugin-aws/api/v1alpha1"
12+ "github.com/spectrocloud-labs/valid8or-plugin-aws/internal/utils/test"
1313 v8or "github.com/spectrocloud-labs/valid8or/api/v1alpha1"
1414 "github.com/spectrocloud-labs/valid8or/pkg/types"
1515 "github.com/spectrocloud-labs/valid8or/pkg/util/ptr"
@@ -76,7 +76,7 @@ const (
7676
7777var iamService = NewIAMRuleService (logr.Logger {}, iamApiMock {
7878 attachedGroupPolicies : map [string ]* iam.ListAttachedGroupPoliciesOutput {
79- "iamGroup" : & iam. ListAttachedGroupPoliciesOutput {
79+ "iamGroup" : {
8080 AttachedPolicies : []* iam.AttachedPolicy {
8181 {
8282 PolicyArn : ptr .Ptr ("iamRoleArn1" ),
@@ -86,15 +86,15 @@ var iamService = NewIAMRuleService(logr.Logger{}, iamApiMock{
8686 },
8787 },
8888 attachedRolePolicies : map [string ]* iam.ListAttachedRolePoliciesOutput {
89- "iamRole1" : & iam. ListAttachedRolePoliciesOutput {
89+ "iamRole1" : {
9090 AttachedPolicies : []* iam.AttachedPolicy {
9191 {
9292 PolicyArn : ptr .Ptr ("iamRoleArn1" ),
9393 PolicyName : ptr .Ptr ("iamPolicy" ),
9494 },
9595 },
9696 },
97- "iamRole2" : & iam. ListAttachedRolePoliciesOutput {
97+ "iamRole2" : {
9898 AttachedPolicies : []* iam.AttachedPolicy {
9999 {
100100 PolicyArn : ptr .Ptr ("iamRoleArn2" ),
@@ -104,19 +104,19 @@ var iamService = NewIAMRuleService(logr.Logger{}, iamApiMock{
104104 },
105105 },
106106 policyArns : map [string ]* iam.GetPolicyOutput {
107- "iamRoleArn1" : & iam. GetPolicyOutput {
107+ "iamRoleArn1" : {
108108 Policy : ptr .Ptr (iam.Policy {
109109 DefaultVersionId : ptr .Ptr ("1" ),
110110 }),
111111 },
112- "iamRoleArn2" : & iam. GetPolicyOutput {
112+ "iamRoleArn2" : {
113113 Policy : ptr .Ptr (iam.Policy {
114114 DefaultVersionId : ptr .Ptr ("1" ),
115115 }),
116116 },
117117 },
118118 attachedUserPolicies : map [string ]* iam.ListAttachedUserPoliciesOutput {
119- "iamUser" : & iam. ListAttachedUserPoliciesOutput {
119+ "iamUser" : {
120120 AttachedPolicies : []* iam.AttachedPolicy {
121121 {
122122 PolicyArn : ptr .Ptr ("iamRoleArn1" ),
@@ -126,12 +126,12 @@ var iamService = NewIAMRuleService(logr.Logger{}, iamApiMock{
126126 },
127127 },
128128 policyVersions : map [string ]* iam.GetPolicyVersionOutput {
129- "iamRoleArn1" : & iam. GetPolicyVersionOutput {
129+ "iamRoleArn1" : {
130130 PolicyVersion : ptr .Ptr (iam.PolicyVersion {
131131 Document : ptr .Ptr (url .QueryEscape (policyDocumentOutput1 )),
132132 }),
133133 },
134- "iamRoleArn2" : & iam. GetPolicyVersionOutput {
134+ "iamRoleArn2" : {
135135 PolicyVersion : ptr .Ptr (iam.PolicyVersion {
136136 Document : ptr .Ptr (url .QueryEscape (policyDocumentOutput2 )),
137137 }),
@@ -146,33 +146,6 @@ type testCase struct {
146146 expectedError error
147147}
148148
149- func checkTestCase (t * testing.T , c testCase , res * types.ValidationResult , err error ) {
150- if ! reflect .DeepEqual (res .State , c .expectedResult .State ) {
151- t .Errorf ("expected state (%+v), got (%+v)" , c .expectedResult .State , res .State )
152- }
153- if ! reflect .DeepEqual (res .Condition .ValidationType , c .expectedResult .Condition .ValidationType ) {
154- t .Errorf ("expected validation type (%s), got (%s)" , c .expectedResult .Condition .ValidationType , res .Condition .ValidationType )
155- }
156- if ! reflect .DeepEqual (res .Condition .ValidationRule , c .expectedResult .Condition .ValidationRule ) {
157- t .Errorf ("expected validation rule (%s), got (%s)" , c .expectedResult .Condition .ValidationRule , res .Condition .ValidationRule )
158- }
159- if ! reflect .DeepEqual (res .Condition .Message , c .expectedResult .Condition .Message ) {
160- t .Errorf ("expected message (%s), got (%s)" , c .expectedResult .Condition .Message , res .Condition .Message )
161- }
162- if ! reflect .DeepEqual (res .Condition .Details , c .expectedResult .Condition .Details ) {
163- t .Errorf ("expected details (%s), got (%s)" , c .expectedResult .Condition .Details , res .Condition .Details )
164- }
165- if ! reflect .DeepEqual (res .Condition .Failures , c .expectedResult .Condition .Failures ) {
166- t .Errorf ("expected failures (%s), got (%s)" , c .expectedResult .Condition .Failures , res .Condition .Failures )
167- }
168- if ! reflect .DeepEqual (res .Condition .Status , c .expectedResult .Condition .Status ) {
169- t .Errorf ("expected status (%s), got (%s)" , c .expectedResult .Condition .Status , res .Condition .Status )
170- }
171- if ! reflect .DeepEqual (err , c .expectedError ) {
172- t .Errorf ("expected error (%v), got (%v)" , c .expectedError , err )
173- }
174- }
175-
176149func TestIAMGroupValidation (t * testing.T ) {
177150 cs := []testCase {
178151 {
@@ -240,7 +213,7 @@ func TestIAMGroupValidation(t *testing.T) {
240213 }
241214 for _ , c := range cs {
242215 result , err := iamService .ReconcileIAMGroupRule (c .rule )
243- checkTestCase (t , c , result , err )
216+ test . CheckTestCase (t , result , c . expectedResult , err , c . expectedError )
244217 }
245218}
246219
@@ -341,7 +314,7 @@ func TestIAMRoleValidation(t *testing.T) {
341314 }
342315 for _ , c := range cs {
343316 result , err := iamService .ReconcileIAMRoleRule (c .rule )
344- checkTestCase (t , c , result , err )
317+ test . CheckTestCase (t , result , c . expectedResult , err , c . expectedError )
345318 }
346319}
347320
@@ -412,7 +385,7 @@ func TestIAMUserValidation(t *testing.T) {
412385 }
413386 for _ , c := range cs {
414387 result , err := iamService .ReconcileIAMUserRule (c .rule )
415- checkTestCase (t , c , result , err )
388+ test . CheckTestCase (t , result , c . expectedResult , err , c . expectedError )
416389 }
417390}
418391
@@ -483,6 +456,6 @@ func TestIAMPolicyValidation(t *testing.T) {
483456 }
484457 for _ , c := range cs {
485458 result , err := iamService .ReconcileIAMPolicyRule (c .rule )
486- checkTestCase (t , c , result , err )
459+ test . CheckTestCase (t , result , c . expectedResult , err , c . expectedError )
487460 }
488461}
0 commit comments