Skip to content

Commit

Permalink
remove redundant tests
Browse files Browse the repository at this point in the history
Signed-off-by: Stephane Selim <[email protected]>
  • Loading branch information
stefnans committed Aug 13, 2024
1 parent 76b1b92 commit af749fc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 111 deletions.
25 changes: 3 additions & 22 deletions pkg/controller/cloudwatchlogs/resourcepolicy/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/pkg/errors"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

svcapitypes "github.com/crossplane-contrib/provider-aws/apis/cloudwatchlogs/v1alpha1"
"github.com/crossplane-contrib/provider-aws/apis/v1alpha1"
Expand All @@ -35,7 +34,7 @@ func SetupResourcePolicy(mgr ctrl.Manager, o controller.Options) error {

opts := []option{
func(e *external) {
c := &custom{client: e.client, kube: e.kube, external: e}
c := &custom{client: e.client}
e.filterList = filterList
e.preCreate = preCreate
e.preDelete = preDelete
Expand All @@ -60,9 +59,7 @@ func SetupResourcePolicy(mgr ctrl.Manager, o controller.Options) error {
}

type custom struct {
kube client.Client
client svcsdkapi.CloudWatchLogsAPI
external *external
client svcsdkapi.CloudWatchLogsAPI
}

func preCreate(_ context.Context, cr *svcapitypes.ResourcePolicy, obj *svcsdk.PutResourcePolicyInput) error {
Expand All @@ -84,14 +81,6 @@ func postObserve(_ context.Context, cr *svcapitypes.ResourcePolicy, _ *svcsdk.De
}

func isUpToDate(_ context.Context, cr *svcapitypes.ResourcePolicy, obj *svcsdk.DescribeResourcePoliciesOutput) (bool, string, error) {
if obj == nil || len(obj.ResourcePolicies) == 0 {
return false, "", nil
}

if cr == nil || cr.Spec.ForProvider.PolicyDocument == nil {
return false, "", nil
}

// Check if the policy exists
for _, policy := range obj.ResourcePolicies {
if policy.PolicyName != nil && *policy.PolicyName == meta.GetExternalName(cr) {
Expand All @@ -103,16 +92,8 @@ func isUpToDate(_ context.Context, cr *svcapitypes.ResourcePolicy, obj *svcsdk.D
}

func filterList(cr *svcapitypes.ResourcePolicy, obj *svcsdk.DescribeResourcePoliciesOutput) *svcsdk.DescribeResourcePoliciesOutput {
resp := &svcsdk.DescribeResourcePoliciesOutput{}
if obj == nil || len(obj.ResourcePolicies) == 0 {
return resp
}

if cr == nil {
return resp
}

resourcePolicyIdentifier := pointer.ToOrNilIfZeroValue(meta.GetExternalName(cr))
resp := &svcsdk.DescribeResourcePoliciesOutput{}

for _, resourcePolicy := range obj.ResourcePolicies {
if pointer.StringValue(resourcePolicy.PolicyName) == pointer.StringValue(resourcePolicyIdentifier) {
Expand Down
89 changes: 0 additions & 89 deletions pkg/controller/cloudwatchlogs/resourcepolicy/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,55 +194,6 @@ func TestIsUpToDate(t *testing.T) {
err: nil,
},
},
"ResourcePolicyNotFoundNilDescribeResourcePoliciesOutput": {
args: args{
describeResourcePoliciesOutput: nil,
resourcePolicy: &svcapitypes.ResourcePolicy{
ObjectMeta: metav1.ObjectMeta{
Name: policyName,
Annotations: map[string]string{
meta.AnnotationKeyExternalName: policyName,
},
},
Spec: svcapitypes.ResourcePolicySpec{
ForProvider: svcapitypes.ResourcePolicyParameters{
PolicyDocument: aws.String(testPolicyDocument),
},
},
},
},
want: want{
result: false,
err: nil,
},
},
"ResourcePolicyNotFoundNilResourcePolicy": {
args: args{
describeResourcePoliciesOutput: &svcsdk.DescribeResourcePoliciesOutput{
ResourcePolicies: []*svcsdk.ResourcePolicy{
{
PolicyName: aws.String(policyName),
PolicyDocument: aws.String(testPolicyDocument),
},
},
},
resourcePolicy: nil,
},
want: want{
result: false,
err: nil,
},
},
"ResourcePolicyNotFoundNilResourcePolicyAndDescribeResourcePoliciesOutput": {
args: args{
describeResourcePoliciesOutput: nil,
resourcePolicy: nil,
},
want: want{
result: false,
err: nil,
},
},
}

for name, tc := range cases {
Expand Down Expand Up @@ -339,46 +290,6 @@ func TestFilterList(t *testing.T) {
resp: &svcsdk.DescribeResourcePoliciesOutput{},
},
},
"ResourcePolicyNotFoundNilDescribeResourcePoliciesOutput": {
args: args{
describeResourcePoliciesOutput: nil,
resourcePolicy: &svcapitypes.ResourcePolicy{
ObjectMeta: metav1.ObjectMeta{
Name: policyName,
Annotations: map[string]string{
meta.AnnotationKeyExternalName: policyName,
},
},
},
},
want: want{
resp: &svcsdk.DescribeResourcePoliciesOutput{},
},
},
"ResourcePolicyNotFoundNilResourcePolicy": {
args: args{
describeResourcePoliciesOutput: &svcsdk.DescribeResourcePoliciesOutput{
ResourcePolicies: []*svcsdk.ResourcePolicy{
{
PolicyName: aws.String(policyName),
},
},
},
resourcePolicy: nil,
},
want: want{
resp: &svcsdk.DescribeResourcePoliciesOutput{},
},
},
"ResourcePolicyNotFoundNilResourcePolicyAndDescribeResourcePoliciesOutput": {
args: args{
describeResourcePoliciesOutput: nil,
resourcePolicy: nil,
},
want: want{
resp: &svcsdk.DescribeResourcePoliciesOutput{},
},
},
}

for name, tc := range cases {
Expand Down

0 comments on commit af749fc

Please sign in to comment.