Merge pull request #1538 from AllenZMC/improve_test

improve test coverage
This commit is contained in:
karmada-bot 2022-03-25 09:25:55 +08:00 committed by GitHub
commit 042762b096
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 60 additions and 0 deletions

View File

@ -284,3 +284,63 @@ func TestGenerateEstimatorServiceName(t *testing.T) {
}
}
}
func TestIsReservedNamespace(t *testing.T) {
tests := []struct {
name string
namespace string
expected bool
}{
{
name: "karmada-system",
namespace: NamespaceKarmadaSystem,
expected: true,
},
{
name: "karmada-cluster",
namespace: NamespaceKarmadaCluster,
expected: true,
},
{
name: "kube-",
namespace: KubernetesReservedNSPrefix,
expected: true,
},
{
name: "karmada-es-",
namespace: ExecutionSpacePrefix,
expected: true,
},
{
name: "not reserved namespace",
namespace: "test-A",
expected: false,
},
}
for _, test := range tests {
got := IsReservedNamespace(test.namespace)
if got != test.expected {
t.Errorf("Test %s failed: expected %v, but got %v", test.name, test.expected, got)
}
}
}
func TestGenerateImpersonationSecretName(t *testing.T) {
tests := []struct {
name string
clusterName string
expected string
}{
{
name: "impersonator",
clusterName: "clusterA",
expected: "clusterA-impersonator",
},
}
for _, test := range tests {
got := GenerateImpersonationSecretName(test.clusterName)
if got != test.expected {
t.Errorf("Test %s failed: expected %v, but got %v", test.name, test.expected, got)
}
}
}