|
| 1 | +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"). You may |
| 4 | +// not use this file except in compliance with the License. A copy of the |
| 5 | +// License is located at |
| 6 | +// |
| 7 | +// http://aws.amazon.com/apache2.0/ |
| 8 | +// |
| 9 | +// or in the "license" file accompanying this file. This file is distributed |
| 10 | +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 11 | +// express or implied. See the License for the specific language governing |
| 12 | +// permissions and limitations under the License. |
| 13 | + |
| 14 | +package broker |
| 15 | + |
| 16 | +import ( |
| 17 | + "testing" |
| 18 | + |
| 19 | + svcapitypes "github.com/aws-controllers-k8s/mq-controller/apis/v1alpha1" |
| 20 | + "github.com/aws/aws-sdk-go-v2/aws" |
| 21 | +) |
| 22 | + |
| 23 | +func TestNewResourceDelta_EngineVersionPrefix(t *testing.T) { |
| 24 | + tests := []struct { |
| 25 | + name string |
| 26 | + aEngineVersion *string |
| 27 | + bEngineVersion *string |
| 28 | + expectDelta bool |
| 29 | + }{ |
| 30 | + { |
| 31 | + name: "a is prefix of b - no delta expected", |
| 32 | + aEngineVersion: aws.String("3.13"), |
| 33 | + bEngineVersion: aws.String("3.13.1"), |
| 34 | + expectDelta: false, |
| 35 | + }, |
| 36 | + { |
| 37 | + name: "a is prefix of b with patch version - no delta expected", |
| 38 | + aEngineVersion: aws.String("5.18"), |
| 39 | + bEngineVersion: aws.String("5.18.4"), |
| 40 | + expectDelta: false, |
| 41 | + }, |
| 42 | + { |
| 43 | + name: "exact match - no delta expected", |
| 44 | + aEngineVersion: aws.String("3.13.1"), |
| 45 | + bEngineVersion: aws.String("3.13.1"), |
| 46 | + expectDelta: false, |
| 47 | + }, |
| 48 | + { |
| 49 | + name: "different patch versions - no delta expected", |
| 50 | + aEngineVersion: aws.String("3.13.2"), |
| 51 | + bEngineVersion: aws.String("3.13.1"), |
| 52 | + expectDelta: true, |
| 53 | + }, |
| 54 | + { |
| 55 | + name: "different minor versions - delta expected", |
| 56 | + aEngineVersion: aws.String("3.13"), |
| 57 | + bEngineVersion: aws.String("3.14.1"), |
| 58 | + expectDelta: true, |
| 59 | + }, |
| 60 | + { |
| 61 | + name: "a is longer than b - delta expected", |
| 62 | + aEngineVersion: aws.String("3.13.1"), |
| 63 | + bEngineVersion: aws.String("3.13"), |
| 64 | + expectDelta: true, |
| 65 | + }, |
| 66 | + { |
| 67 | + name: "nil versions - no delta expected", |
| 68 | + aEngineVersion: nil, |
| 69 | + bEngineVersion: nil, |
| 70 | + expectDelta: false, |
| 71 | + }, |
| 72 | + { |
| 73 | + name: "a nil, b not nil - delta expected", |
| 74 | + aEngineVersion: nil, |
| 75 | + bEngineVersion: aws.String("3.13.1"), |
| 76 | + expectDelta: true, |
| 77 | + }, |
| 78 | + { |
| 79 | + name: "a not nil, b nil - delta expected", |
| 80 | + aEngineVersion: aws.String("3.13"), |
| 81 | + bEngineVersion: nil, |
| 82 | + expectDelta: true, |
| 83 | + }, |
| 84 | + } |
| 85 | + |
| 86 | + for _, tt := range tests { |
| 87 | + t.Run(tt.name, func(t *testing.T) { |
| 88 | + a := &resource{ |
| 89 | + ko: &svcapitypes.Broker{ |
| 90 | + Spec: svcapitypes.BrokerSpec{ |
| 91 | + EngineVersion: tt.aEngineVersion, |
| 92 | + }, |
| 93 | + }, |
| 94 | + } |
| 95 | + b := &resource{ |
| 96 | + ko: &svcapitypes.Broker{ |
| 97 | + Spec: svcapitypes.BrokerSpec{ |
| 98 | + EngineVersion: tt.bEngineVersion, |
| 99 | + }, |
| 100 | + }, |
| 101 | + } |
| 102 | + |
| 103 | + delta := newResourceDelta(a, b) |
| 104 | + hasDelta := delta.DifferentAt("Spec.EngineVersion") |
| 105 | + |
| 106 | + if tt.expectDelta && !hasDelta { |
| 107 | + t.Errorf("Expected delta for EngineVersion but none found") |
| 108 | + } |
| 109 | + if !tt.expectDelta && hasDelta { |
| 110 | + t.Errorf("Expected no delta for EngineVersion but found one") |
| 111 | + } |
| 112 | + }) |
| 113 | + } |
| 114 | +} |
0 commit comments