Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a file for assertions #424

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/e2e/framework/assertions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package framework

import (
"context"
"testing"

compv1alpha1 "github.com/ComplianceAsCode/compliance-operator/pkg/apis/compliance/v1alpha1"

"k8s.io/apimachinery/pkg/labels"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func (f *Framework) AssertMustHaveParsedProfiles(t *testing.T, pbName, productType, productName string) {
var l compv1alpha1.ProfileList
o := &client.ListOptions{
LabelSelector: labels.SelectorFromSet(map[string]string{
compv1alpha1.ProfileBundleOwnerLabel: pbName,
}),
}
if err := f.Client.List(context.TODO(), &l, o); err != nil {
t.Fatalf("failed checking profiles in ProfileBundle: %s", err)
}
if len(l.Items) <= 0 {
t.Fatalf("failed to get profiles from ProfileBundle %s. Expected at least one but got %d", pbName, len(l.Items))
}

for _, p := range l.Items {
if p.Annotations[compv1alpha1.ProductTypeAnnotation] != productType {
t.Fatalf("expected %s to be %s, got %s instead", compv1alpha1.ProductTypeAnnotation, productType, p.Annotations[compv1alpha1.ProductTypeAnnotation])
}

if p.Annotations[compv1alpha1.ProductAnnotation] != productName {
t.Fatalf("expected %s to be %s, got %s instead", compv1alpha1.ProductAnnotation, productName, p.Annotations[compv1alpha1.ProductAnnotation])
}
}
}
26 changes: 0 additions & 26 deletions tests/e2e/framework/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

func (f *Framework) AssertMustHaveParsedProfiles(pbName, productType, productName string) error {
var l compv1alpha1.ProfileList
o := &client.ListOptions{
LabelSelector: labels.SelectorFromSet(map[string]string{
compv1alpha1.ProfileBundleOwnerLabel: pbName,
}),
}
if err := f.Client.List(context.TODO(), &l, o); err != nil {
return err
}
if len(l.Items) <= 0 {
return fmt.Errorf("failed to get profiles from ProfileBundle %s. Expected at least one but got %d", pbName, len(l.Items))
}

for _, p := range l.Items {
if p.Annotations[compv1alpha1.ProductTypeAnnotation] != productType {
return fmt.Errorf("expected %s to be %s, got %s instead", compv1alpha1.ProductTypeAnnotation, productType, p.Annotations[compv1alpha1.ProductTypeAnnotation])
}

if p.Annotations[compv1alpha1.ProductAnnotation] != productName {
return fmt.Errorf("expected %s to be %s, got %s instead", compv1alpha1.ProductAnnotation, productName, p.Annotations[compv1alpha1.ProductAnnotation])
}
}
return nil
}

// AssertScanHasTotalCheckCounts asserts that the scan has the expected total check counts
func (f *Framework) AssertScanHasTotalCheckCounts(namespace, scanName string) error {
// check if scan has annotation
Expand Down
12 changes: 3 additions & 9 deletions tests/e2e/parallel/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ func TestProfileModification(t *testing.T) {
if err := f.WaitForProfileBundleStatus(pbName, compv1alpha1.DataStreamValid); err != nil {
t.Fatalf("failed waiting for the ProfileBundle to become available: %s", err)
}
if err := f.AssertMustHaveParsedProfiles(pbName, string(compv1alpha1.ScanTypeNode), "redhat_enterprise_linux_coreos_4"); err != nil {
t.Fatalf("failed checking profiles in ProfileBundle: %s", err)
}
f.AssertMustHaveParsedProfiles(t, pbName, string(compv1alpha1.ScanTypeNode), "redhat_enterprise_linux_coreos_4")

// Check that the rule we removed exists in the original profile
removedRuleName := prefixName(pbName, removedRule)
Expand Down Expand Up @@ -215,9 +213,7 @@ func TestProfileISTagUpdate(t *testing.T) {
if err := f.WaitForProfileBundleStatus(pbName, compv1alpha1.DataStreamValid); err != nil {
t.Fatalf("failed waiting for the ProfileBundle to become available: %s", err)
}
if err := f.AssertMustHaveParsedProfiles(pbName, string(compv1alpha1.ScanTypeNode), "redhat_enterprise_linux_coreos_4"); err != nil {
t.Fatalf("failed checking profiles in ProfileBundle: %s", err)
}
f.AssertMustHaveParsedProfiles(t, pbName, string(compv1alpha1.ScanTypeNode), "redhat_enterprise_linux_coreos_4")

// Check that the rule we removed exists in the original profile
removedRuleName := prefixName(pbName, removedRule)
Expand Down Expand Up @@ -324,9 +320,7 @@ func TestProfileISTagOtherNs(t *testing.T) {
if err := f.WaitForProfileBundleStatus(pbName, compv1alpha1.DataStreamValid); err != nil {
t.Fatalf("failed waiting for ProfileBundle to parse: %s", err)
}
if err := f.AssertMustHaveParsedProfiles(pbName, string(compv1alpha1.ScanTypeNode), "redhat_enterprise_linux_coreos_4"); err != nil {
t.Fatalf("failed to assert profiles in ProfileBundle %s: %s", pbName, err)
}
f.AssertMustHaveParsedProfiles(t, pbName, string(compv1alpha1.ScanTypeNode), "redhat_enterprise_linux_coreos_4")

// Check that the rule we removed exists in the original profile
removedRuleName := prefixName(pbName, removedRule)
Expand Down
Loading