From 84b306365fbc9fa242c456c21c136f82d53bbbc5 Mon Sep 17 00:00:00 2001 From: Felix Kunde Date: Fri, 6 Nov 2020 16:27:56 +0100 Subject: [PATCH] add test for quantityToGigabyte --- pkg/cluster/volumes_test.go | 38 +++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/pkg/cluster/volumes_test.go b/pkg/cluster/volumes_test.go index 1a1073603..139195835 100644 --- a/pkg/cluster/volumes_test.go +++ b/pkg/cluster/volumes_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/assert" acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1" "github.com/zalando/postgres-operator/pkg/util/config" + "github.com/zalando/postgres-operator/pkg/util/constants" "github.com/zalando/postgres-operator/pkg/util/k8sutil" "k8s.io/client-go/kubernetes/fake" ) @@ -56,7 +57,7 @@ func TestResizeVolumeClaim(t *testing.T) { Items: []v1.PersistentVolumeClaim{ { ObjectMeta: metav1.ObjectMeta{ - Name: "pgdata-" + clusterName + "-0", + Name: constants.DataVolumeName + "-" + clusterName + "-0", Namespace: namespace, Labels: filterLabels, }, @@ -70,7 +71,7 @@ func TestResizeVolumeClaim(t *testing.T) { }, { ObjectMeta: metav1.ObjectMeta{ - Name: "pgdata-" + clusterName + "-1", + Name: constants.DataVolumeName + "-" + clusterName + "-1", Namespace: namespace, Labels: filterLabels, }, @@ -109,3 +110,36 @@ func TestResizeVolumeClaim(t *testing.T) { } } } + +func TestQuantityToGigabyte(t *testing.T) { + tests := []struct { + name string + quantityStr string + expected int64 + }{ + { + "test with 1Gi", + "1Gi", + 1, + }, + { + "test with float", + "1.5Gi", + int64(1), + }, + { + "test with 1000Mi", + "1000Mi", + int64(0), + }, + } + + for _, tt := range tests { + quantity, err := resource.ParseQuantity(tt.quantityStr) + assert.NoError(t, err) + gigabyte := quantityToGigabyte(quantity) + if gigabyte != tt.expected { + t.Errorf("%s: got %v, expected %v", tt.name, gigabyte, tt.expected) + } + } +}