|  | 
|  | 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 compare_test | 
|  | 15 | + | 
|  | 16 | +import ( | 
|  | 17 | +	"testing" | 
|  | 18 | + | 
|  | 19 | +	"github.com/stretchr/testify/require" | 
|  | 20 | + | 
|  | 21 | +	"github.com/aws-controllers-k8s/runtime/pkg/compare" | 
|  | 22 | +	acktags "github.com/aws-controllers-k8s/runtime/pkg/tags" | 
|  | 23 | +) | 
|  | 24 | + | 
|  | 25 | +func TestTagsDifference(t *testing.T) { | 
|  | 26 | +	require := require.New(t) | 
|  | 27 | + | 
|  | 28 | +	a := acktags.NewTags() | 
|  | 29 | +	b := acktags.NewTags() | 
|  | 30 | + | 
|  | 31 | +	a["tag1"] = "value1" | 
|  | 32 | + | 
|  | 33 | +	a["tag2"] = "value2" | 
|  | 34 | +	b["tag2"] = "value2" | 
|  | 35 | + | 
|  | 36 | +	b["tag3"] = "value3" | 
|  | 37 | +	b["tag4"] = "value4" | 
|  | 38 | + | 
|  | 39 | +	added, unchanged, removed := compare.GetTagsDifference(a, b) | 
|  | 40 | + | 
|  | 41 | +	require.Len(added, 2) | 
|  | 42 | +	require.Len(unchanged, 1) | 
|  | 43 | +	require.Len(removed, 1) | 
|  | 44 | + | 
|  | 45 | +	require.Contains(added, "tag3") | 
|  | 46 | +	require.Contains(added, "tag4") | 
|  | 47 | +	require.Contains(unchanged, "tag2") | 
|  | 48 | +	require.Contains(removed, "tag1") | 
|  | 49 | + | 
|  | 50 | +	// add test for updating the value of an existing tag | 
|  | 51 | +	a["tag2"] = "oldvalue" | 
|  | 52 | +	b["tag2"] = "newvalue" | 
|  | 53 | + | 
|  | 54 | +	added, unchanged, removed = compare.GetTagsDifference(a, b) | 
|  | 55 | + | 
|  | 56 | +	require.Len(added, 3) | 
|  | 57 | +	require.Len(unchanged, 0) | 
|  | 58 | +	require.Len(removed, 2) | 
|  | 59 | + | 
|  | 60 | +	require.Contains(added, "tag2") | 
|  | 61 | +	require.Equal(added["tag2"], "newvalue") | 
|  | 62 | +} | 
0 commit comments