diff --git a/THIRD_PARTY_LICENSES.txt b/THIRD_PARTY_LICENSES.txt index 8c86c7b..aea6ad2 100644 --- a/THIRD_PARTY_LICENSES.txt +++ b/THIRD_PARTY_LICENSES.txt @@ -1,10 +1,11 @@ github.com/verrazzano/pkg -------- Copyrights -Copyright (c) 2020 Oracle America, Inc. and its affiliates. +Copyright (c) 2021 Oracle America, Inc. and its affiliates. +Copyright (c) 2021, Oracle and/or its affiliates. Copyright (C) 2021, Oracle and/or its affiliates. -------- License -Copyright (c) 2020 Oracle America, Inc. and its affiliates. +Copyright (c) 2021 Oracle America, Inc. and its affiliates. The Universal Permissive License (UPL), Version 1.0 @@ -85,4 +86,4 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ATTRIBUTION-HELPER-GENERATED: -License file based on go.mod with md5 sum: ceeb284685d01c120a0c982ef88a56e7 +License file based on go.mod with md5 sum: ad8ff9601475c864dcd8d768548e6017 diff --git a/diff/diff_test.go b/diff/diff_test.go index 783d055..b51d420 100644 --- a/diff/diff_test.go +++ b/diff/diff_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "testing" ) @@ -185,6 +186,33 @@ func TestTimes(t *testing.T) { verifyDiff(t, fromObj, toObj, true, "Time changed") } +func TestResources(t *testing.T) { + r1 := corev1.ResourceRequirements{Limits: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1024Mi")}} + r2 := corev1.ResourceRequirements{Limits: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}} + verifyDiff(t, r1, r2, false, "Same resource, different units") + r1 = corev1.ResourceRequirements{Limits: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1028Mi")}} + r2 = corev1.ResourceRequirements{Limits: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1Gi")}} + verifyDiff(t, r1, r2, true, "Different resource, different units") + r1 = corev1.ResourceRequirements{Limits: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1028Mi")}} + r2 = corev1.ResourceRequirements{Limits: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("1030Mi")}} + verifyDiff(t, r1, r2, true, "Different resource, same units") + r1 = corev1.ResourceRequirements{Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1000m")}} + r2 = corev1.ResourceRequirements{Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1")}} + verifyDiff(t, r1, r2, false, "Same resource, different units") + r1 = corev1.ResourceRequirements{Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1001m")}} + r2 = corev1.ResourceRequirements{Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1")}} + verifyDiff(t, r1, r2, true, "Different resource, different units") + r1 = corev1.ResourceRequirements{Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1001m")}} + r2 = corev1.ResourceRequirements{Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1002m")}} + verifyDiff(t, r1, r2, true, "Different resource, same units") + r1 = corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1000m")}, Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("3000m")}} + r2 = corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1")}, Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("3")}} + verifyDiff(t, r1, r2, false, "Same resources, different units") + r1 = corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1001m")}, Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1000m")}} + r2 = corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1")}, Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1")}} + verifyDiff(t, r1, r2, true, "Different units for limits (but same resource), different resource for requests") +} + // One unit test that contains a complex diff and actually verifies the full output func TestOutput(t *testing.T) { fromObj := X{ diff --git a/go.mod b/go.mod index 7b2e350..e02bdc5 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,10 @@ require ( github.com/google/go-cmp v0.5.0 github.com/stretchr/testify v1.6.1 k8s.io/api v0.19.0 + k8s.io/apimachinery v0.21.1 ) -replace k8s.io/api => k8s.io/api v0.18.6 +replace ( + k8s.io/api => k8s.io/api v0.18.6 + k8s.io/apimachinery => k8s.io/apimachinery v0.18.6 +)