Merge pull request #2606 from my-git9/conversion_test

add ut function for util/name.go
This commit is contained in:
karmada-bot 2022-10-11 21:10:07 +08:00 committed by GitHub
commit b9287479c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 0 deletions

View File

@ -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)
}
}
}