-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test that ran du cluste has compliant policies
- Loading branch information
1 parent
01c784b
commit d3e41e3
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package ran_du_system_test | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/openshift-kni/eco-goinfra/pkg/ocm" | ||
"github.com/openshift-kni/eco-goinfra/pkg/polarion" | ||
"github.com/openshift-kni/eco-gosystem/tests/internal/cluster" | ||
. "github.com/openshift-kni/eco-gosystem/tests/ran-du/internal/randuinittools" | ||
"github.com/openshift-kni/eco-gosystem/tests/ran-du/internal/randuparams" | ||
policiesv1 "open-cluster-management.io/governance-policy-propagator/api/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
var _ = Describe( | ||
"ZTPPoliciesCompliance", | ||
Label("ZTPPoliciesCompliance"), | ||
Ordered, | ||
func() { | ||
var ( | ||
clusterName string | ||
err error | ||
) | ||
BeforeAll(func() { | ||
By("Fetching Cluster name") | ||
clusterName, err = cluster.GetClusterName(randuparams.KubeEnvKey) | ||
Expect(err).ToNot(HaveOccurred(), "Failed to get cluster name") | ||
}) | ||
|
||
It("All policies compliant", polarion.ID("OCP-48465"), | ||
func() { | ||
By("Retrieve policy list") | ||
policies, err := ocm.ListPoliciesInAllNamespaces( | ||
APIClient, | ||
client.ListOptions{Namespace: clusterName}, | ||
) | ||
Expect(err).NotTo(HaveOccurred(), "Failed to get policy list") | ||
|
||
By("Checking for NonCompliant policies") | ||
nonCompliantPolicies := make([]string, 0) | ||
for _, policy := range policies { | ||
if policy.Definition.Status.ComplianceState == policiesv1.NonCompliant { | ||
nonCompliantPolicies = append(nonCompliantPolicies, policy.Definition.Name) | ||
} | ||
} | ||
Expect(nonCompliantPolicies).To( | ||
BeEmpty(), | ||
fmt.Sprintf("NonCompliant policies found: %s", strings.Join(nonCompliantPolicies, ",")), | ||
) | ||
}, | ||
) | ||
}, | ||
) |