From d89d92fa5b568099db4a01a108bef3ad65f1f56d Mon Sep 17 00:00:00 2001 From: "xin.li" Date: Sat, 1 Oct 2022 18:32:02 +0800 Subject: [PATCH] add ut function for util/name.go Signed-off-by: xin.li --- pkg/util/names/names_test.go | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/pkg/util/names/names_test.go b/pkg/util/names/names_test.go index 584cd731f..8c7851e50 100644 --- a/pkg/util/names/names_test.go +++ b/pkg/util/names/names_test.go @@ -290,6 +290,26 @@ func TestGenerateDerivedServiceName(t *testing.T) { } } +func TestGenerateEstimatorDeploymentName(t *testing.T) { + tests := []struct { + name string + clusterName string + expected string + }{ + { + name: "generate estimator deployment name", + clusterName: "cluster", + expected: "karmada-scheduler-estimator-cluster", + }, + } + for _, test := range tests { + got := GenerateEstimatorDeploymentName(test.clusterName) + if got != test.expected { + t.Errorf("Test %s failed: expected %v, but got %v", test.name, test.expected, got) + } + } +} + func TestGenerateEstimatorServiceName(t *testing.T) { tests := []struct { name string @@ -369,3 +389,27 @@ func TestGenerateImpersonationSecretName(t *testing.T) { } } } + +func TestGeneratePolicyName(t *testing.T) { + tests := []struct { + name string + namespace string + resourcename string + gvk string + expected string + }{ + { + name: "generate policy name", + namespace: "ns-foo", + resourcename: "foo", + gvk: "rand", + expected: "foo-b4978784", + }, + } + for _, test := range tests { + got := GeneratePolicyName(test.namespace, test.resourcename, test.gvk) + if got != test.expected { + t.Errorf("Test %s failed: expected %v, but got %v", test.name, test.expected, got) + } + } +}