Skip to content

Commit

Permalink
Use testcase-scoped variables
Browse files Browse the repository at this point in the history
Signed-off-by: Dale Haiducek <[email protected]>
(cherry picked from commit fe476e6)
  • Loading branch information
dhaiducek authored and Magic Mirror committed Feb 16, 2024
1 parent 5052dfb commit 1ec3ad5
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 141 deletions.
20 changes: 10 additions & 10 deletions test/e2e/case10_policyset_propagation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ import (
"open-cluster-management.io/governance-policy-propagator/test/utils"
)

const (
path string = "../resources/case10_policyset_propagation/"
case10PolicyName string = "case10-test-policy"
case10PolicySetName string = "case10-test-policyset"
case10PolicySetYaml string = path + "case10-test-policyset.yaml"
case10PolicySetPlacementYaml string = path + "case10-test-policyset-placement.yaml"
case10PolicySetPolicyYaml string = path + "case10-test-policyset-policy.yaml"
case10PolicySetPolicyPlacementYaml string = path + "case10-test-policyset-policy-placement.yaml"
)

var _ = Describe("Test policyset propagation", func() {
const (
path string = "../resources/case10_policyset_propagation/"
case10PolicyName string = "case10-test-policy"
case10PolicySetName string = "case10-test-policyset"
case10PolicySetYaml string = path + "case10-test-policyset.yaml"
case10PolicySetPlacementYaml string = path + "case10-test-policyset-placement.yaml"
case10PolicySetPolicyYaml string = path + "case10-test-policyset-policy.yaml"
case10PolicySetPolicyPlacementYaml string = path + "case10-test-policyset-policy-placement.yaml"
)

Describe("Test policy propagation through policyset placementbinding with placementrule", func() {
It("should be created in user ns", func() {
By("Creating " + case10PolicySetYaml)
Expand Down
39 changes: 20 additions & 19 deletions test/e2e/case11_policyset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@ import (
"open-cluster-management.io/governance-policy-propagator/test/utils"
)

const (
case11PolicyName string = "case11-test-policy"
case11PolicySetName string = "case11-test-policyset"
case11PolicySetNameManaged1 string = "test-plcset-managed1"
case11PolicyNameManaged2 string = "case11-multiple-placements-rule"
case11PolicySetEmpty string = "case11-empty-policyset"
case11PolicySetMultiStatus string = "case11-multistatus-policyset"
case11PolicyCompliant string = "case11-compliant-plc"
case11PolicyYaml string = "../resources/case11_policyset_controller/case11-test-policy.yaml"
case11PolicySetPatchYaml string = "../resources/case11_policyset_controller/case11-patch-plcset.yaml"
case11PolicySetPatch2Yaml string = "../resources/case11_policyset_controller/case11-patch-plcset-2.yaml"
case11DisablePolicyYaml string = "../resources/case11_policyset_controller/case11-disable-plc.yaml"
case11PolicySetManaged1Yaml string = "../resources/case11_policyset_controller/case11-plcset-managed1.yaml"
case11PolicyManaged2Yaml string = "../resources/case11_policyset_controller/case11-plc-managed2.yaml"
case11PolicySetEmptyYaml string = "../resources/case11_policyset_controller/case11-empty-plcset.yaml"
case11PolicySetMultiStatusYaml string = "../resources/case11_policyset_controller/case11-plcset-multistatus.yaml"
case11PolicyCompliantYaml string = "../resources/case11_policyset_controller/case11-compliant-plc.yaml"
)

var _ = Describe("Test policyset controller status updates", func() {
const (
case11PolicyName string = "case11-test-policy"
case11PolicySetName string = "case11-test-policyset"
case11PolicySetNameManaged1 string = "test-plcset-managed1"
case11PolicyNameManaged2 string = "case11-multiple-placements-rule"
case11PolicySetEmpty string = "case11-empty-policyset"
case11PolicySetMultiStatus string = "case11-multistatus-policyset"
case11PolicyCompliant string = "case11-compliant-plc"
case11Path string = "../resources/case11_policyset_controller/"
case11PolicyYaml string = case11Path + "case11-test-policy.yaml"
case11PolicySetPatchYaml string = case11Path + "case11-patch-plcset.yaml"
case11PolicySetPatch2Yaml string = case11Path + "case11-patch-plcset-2.yaml"
case11DisablePolicyYaml string = case11Path + "case11-disable-plc.yaml"
case11PolicySetManaged1Yaml string = case11Path + "case11-plcset-managed1.yaml"
case11PolicyManaged2Yaml string = case11Path + "case11-plc-managed2.yaml"
case11PolicySetEmptyYaml string = case11Path + "case11-empty-plcset.yaml"
case11PolicySetMultiStatusYaml string = case11Path + "case11-plcset-multistatus.yaml"
case11PolicyCompliantYaml string = case11Path + "case11-compliant-plc.yaml"
)

Describe("Create policy, policyset, and placement in ns:"+testNamespace, func() {
It("should create and process policy and policyset", func() {
By("Creating " + case11PolicyYaml)
Expand Down
7 changes: 0 additions & 7 deletions test/e2e/case12_encryptionkeys_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ import (
"open-cluster-management.io/governance-policy-propagator/test/utils"
)

const (
EncryptionKeySecret = "policy-encryption-key"
LastRotatedAnnotation = "policy.open-cluster-management.io/last-rotated"
RootPolicyLabel = "policy.open-cluster-management.io/root-policy"
TriggerUpdateAnnotation = "policy.open-cluster-management.io/trigger-update"
)

var _ = Describe("Test policy encryption key rotation", func() {
key := bytes.Repeat([]byte{byte('A')}, 256/8)
keyB64 := base64.StdEncoding.EncodeToString(key)
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/case14_root_policy_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (

var _ = Describe("Test root policy metrics", Ordered, func() {
const (
policyName = "case9-test-policy"
policyYaml = "../resources/case9_templates/case9-test-policy.yaml"
policyName = "case9-test-policy"
policyYaml = "../resources/case9_templates/case9-test-policy.yaml"
replicatedPolicyYaml = "../resources/case9_templates/case9-test-replpolicy-managed1.yaml"
)

Describe("Create policy, placement and referenced resource in ns:"+testNamespace, func() {
Expand Down Expand Up @@ -63,7 +64,7 @@ var _ = Describe("Test root policy metrics", Ordered, func() {
)
Expect(plc).ToNot(BeNil())

yamlPlc := utils.ParseYaml(case9ReplicatedPolicyYamlM1)
yamlPlc := utils.ParseYaml(replicatedPolicyYaml)
Eventually(func(g Gomega) interface{} {
replicatedPlc := utils.GetWithTimeout(
clientHubDynamic,
Expand Down
44 changes: 22 additions & 22 deletions test/e2e/case17_policy_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ import (
"open-cluster-management.io/governance-policy-propagator/test/utils"
)

const (
case17Prefix string = "../resources/case17_policy_webhook/"
case17PolicyLongYaml string = case17Prefix + "case17_policy_long.yaml"
case17PolicyReplicatedYaml string = case17Prefix + "case17_policy_replicate.yaml"
case17PolicyRemediationYaml string = case17Prefix + "case17_invalid_remediation_policy.yaml"
case17PolicyRootRemediationYaml string = case17Prefix + "case17_valid_remediation_policy_root.yaml"
case17PolicyCfplcRemediationYaml string = case17Prefix + "case17_valid_remediation_policy_cfplc.yaml"
longNamespace string = "long-long-long-long-long-long-long"
case17PolicyReplicatedName string = "case17-test-policy-replicated-longlong"
case17PolicyReplicatedPlr string = "case17-test-policy-replicated-longlong-plr"
case17PolicyReplicatedPb string = "case17-test-policy-replicated-longlong-pb"
case17PolicyRemediationName string = "case17-test-policy-no-remediation"
case17PolicyRootRemediationName string = "case17-test-policy-root-remediation"
case17PolicyCfplcRemediationName string = "case17-test-policy-cfplc-remediation"
errPrefix string = `admission webhook "policy.open-cluster-management.io.webhook" ` +
`denied the request: `
combinedLengthErr string = errPrefix + "the combined length of the policy namespace and name " +
"cannot exceed 62 characters"
remediationErr string = errPrefix + "RemediationAction field of the policy and policy template " +
"cannot both be unset"
)

var _ = Describe("Test policy webhook", Label("webhook"), Ordered, func() {
const (
case17Prefix string = "../resources/case17_policy_webhook/"
case17PolicyLongYaml string = case17Prefix + "case17_policy_long.yaml"
case17PolicyReplicatedYaml string = case17Prefix + "case17_policy_replicate.yaml"
case17PolicyRemediationYaml string = case17Prefix + "case17_invalid_remediation_policy.yaml"
case17PolicyRootRemediationYaml string = case17Prefix + "case17_valid_remediation_policy_root.yaml"
case17PolicyCfplcRemediationYaml string = case17Prefix + "case17_valid_remediation_policy_cfplc.yaml"
longNamespace string = "long-long-long-long-long-long-long"
case17PolicyReplicatedName string = "case17-test-policy-replicated-longlong"
case17PolicyReplicatedPlr string = "case17-test-policy-replicated-longlong-plr"
case17PolicyReplicatedPb string = "case17-test-policy-replicated-longlong-pb"
case17PolicyRemediationName string = "case17-test-policy-no-remediation"
case17PolicyRootRemediationName string = "case17-test-policy-root-remediation"
case17PolicyCfplcRemediationName string = "case17-test-policy-cfplc-remediation"
errPrefix string = `admission webhook "policy.open-cluster-management.io.webhook" ` +
`denied the request: `
combinedLengthErr string = errPrefix + "the combined length of the policy namespace and name " +
"cannot exceed 62 characters"
remediationErr string = errPrefix + "RemediationAction field of the policy and policy template " +
"cannot both be unset"
)

Describe("Test name + namespace over 63", func() {
BeforeAll(func() {
_, err := utils.KubectlWithOutput("create",
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/case19_rep_policy_placement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"open-cluster-management.io/governance-policy-propagator/test/utils"
)

const (
case19PolicyName string = "case19-test-policy"
case19PolicyYaml string = "../resources/case19_rep_policy_placement/case19-test-policy.yaml"
)

var _ = Describe("Test replicated_policy controller and propagation", Ordered, Serial, func() {
const (
case19PolicyName string = "case19-test-policy"
case19PolicyYaml string = "../resources/case19_rep_policy_placement/case19-test-policy.yaml"
)

BeforeAll(func() {
By("Creating " + case19PolicyName)
utils.Kubectl("apply",
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/case1_propagation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (
"open-cluster-management.io/governance-policy-propagator/test/utils"
)

const (
case1PolicyName string = "case1-test-policy"
case1PolicyYaml string = "../resources/case1_propagation/case1-test-policy.yaml"
)

var _ = Describe("Test policy propagation", func() {
const (
case1PolicyName string = "case1-test-policy"
case1PolicyYaml string = "../resources/case1_propagation/case1-test-policy.yaml"
)

Describe("Test event emission when policy is disabled", Ordered, func() {
BeforeAll(func() {
By("Creating the policy, placementrule, and placementbinding")
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/case20_compliance_api_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import (
"open-cluster-management.io/governance-policy-propagator/test/utils"
)

const (
case20PolicyName string = "case20-policy"
case20PolicyYAML string = "../resources/case20_compliance_api_controller/policy.yaml"
)

var _ = Describe("Test governance-policy-database secret changes and DB annotations", Serial, Ordered, func() {
const (
case20PolicyName string = "case20-policy"
case20PolicyYAML string = "../resources/case20_compliance_api_controller/policy.yaml"
)

seededRand := rand.New(rand.NewSource(time.Now().UnixNano()))
nsName := fmt.Sprintf("case20-%d", seededRand.Int31())

Expand Down
10 changes: 5 additions & 5 deletions test/e2e/case3_mutation_recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
"open-cluster-management.io/governance-policy-propagator/test/utils"
)

const (
case3PolicyName string = "case3-test-policy"
case3PolicyYaml string = "../resources/case3_mutation_recovery/case3-test-policy.yaml"
)

var _ = Describe("Test unexpected policy mutation", func() {
const (
case3PolicyName string = "case3-test-policy"
case3PolicyYaml string = "../resources/case3_mutation_recovery/case3-test-policy.yaml"
)

BeforeEach(func() {
By("Creating " + case3PolicyYaml)
utils.Kubectl("apply",
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/case4_unexpected_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"open-cluster-management.io/governance-policy-propagator/test/utils"
)

const (
case4PolicyName string = "case4-test-policy"
case4PolicyYaml string = "../resources/case4_unexpected_policy/case4-test-policy.yaml"
)

var _ = Describe("Test unexpect policy handling", func() {
const (
case4PolicyName string = "case4-test-policy"
case4PolicyYaml string = "../resources/case4_unexpected_policy/case4-test-policy.yaml"
)

It("Unexpected root policy in cluster namespace should be deleted", func() {
By("Creating " + case4PolicyYaml + "in cluster namespace: managed1")
out, err := utils.KubectlWithOutput("apply",
Expand Down
13 changes: 6 additions & 7 deletions test/e2e/case5_policy_automation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import (
"open-cluster-management.io/governance-policy-propagator/test/utils"
)

const (
case5PolicyName string = "case5-test-policy"
case5PolicyYaml string = "../resources/case5_policy_automation/case5-test-policy.yaml"
)

const automationName string = "create-service.now-ticket"

var _ = Describe("Test policy automation", Label("policyautomation"), Ordered, func() {
const (
case5PolicyName string = "case5-test-policy"
case5PolicyYaml string = "../resources/case5_policy_automation/case5-test-policy.yaml"
automationName string = "create-service.now-ticket"
)

ansiblelistlen := 0
// Use this only when target_clusters managed1 managed2 managed3
getLastAnsiblejob := func() *unstructured.Unstructured {
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/case6_placement_propagation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
"open-cluster-management.io/governance-policy-propagator/test/utils"
)

const (
case6PolicyName string = "case6-test-policy"
case6PolicyYaml string = "../resources/case6_placement_propagation/case6-test-policy.yaml"
)

var _ = Describe("Test policy propagation", func() {
const (
case6PolicyName string = "case6-test-policy"
case6PolicyYaml string = "../resources/case6_placement_propagation/case6-test-policy.yaml"
)

Describe("Create policy/pb/plc in ns:"+testNamespace+" and then update pb/plc", Ordered, func() {
BeforeAll(func() {
By("Creating " + case6PolicyYaml)
Expand Down
18 changes: 9 additions & 9 deletions test/e2e/case7_bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import (
"open-cluster-management.io/governance-policy-propagator/test/utils"
)

const (
case7PolicyName string = "case7-test-policy"
case7PolicyYaml string = "../resources/case7_placement_bindings/case7-test-policy.yaml"
case7BindingYaml1 string = "../resources/case7_placement_bindings/case7-test-binding1.yaml"
case7BindingYaml2 string = "../resources/case7_placement_bindings/case7-test-binding2.yaml"
case7BindingYaml3 string = "../resources/case7_placement_bindings/case7-test-binding3.yaml"
case7BindingYaml4 string = "../resources/case7_placement_bindings/case7-test-binding4.yaml"
)

var _ = Describe("Test policy propagation", func() {
const (
case7PolicyName string = "case7-test-policy"
case7PolicyYaml string = "../resources/case7_placement_bindings/case7-test-policy.yaml"
case7BindingYaml1 string = "../resources/case7_placement_bindings/case7-test-binding1.yaml"
case7BindingYaml2 string = "../resources/case7_placement_bindings/case7-test-binding2.yaml"
case7BindingYaml3 string = "../resources/case7_placement_bindings/case7-test-binding3.yaml"
case7BindingYaml4 string = "../resources/case7_placement_bindings/case7-test-binding4.yaml"
)

Describe("Create policy/pb/plc in ns:"+testNamespace, Ordered, func() {
BeforeAll(func() {
By("Creating " + case7PolicyYaml)
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/case8_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
"open-cluster-management.io/governance-policy-propagator/test/utils"
)

const (
case8PolicyName string = "case8-test-policy"
case8PolicyYaml string = "../resources/case8_metrics/case8-test-policy.yaml"
)

var _ = Describe("Test metrics appear locally", func() {
const (
case8PolicyName string = "case8-test-policy"
case8PolicyYaml string = "../resources/case8_metrics/case8-test-policy.yaml"
)

It("should report 0 for compliant root policy and replicated policies", func() {
By("Creating " + case8PolicyYaml)
utils.Kubectl("apply",
Expand Down
Loading

0 comments on commit 1ec3ad5

Please sign in to comment.