Skip to content

Commit

Permalink
extract test functions
Browse files Browse the repository at this point in the history
  • Loading branch information
stehessel committed Nov 7, 2023
1 parent 3e3c82a commit 67c60ee
Showing 1 changed file with 19 additions and 106 deletions.
125 changes: 19 additions & 106 deletions internal/dinosaur/pkg/gitops/default_central_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ import (
"sigs.k8s.io/yaml"
)

func TestDefaultCentral(t *testing.T) {
p := getDummyCentralParams()
central, err := renderDefaultCentral(p)
assert.NoError(t, err)

func wantCentralForDummyParams(p *CentralParams) *v1alpha1.Central {
exposeEndpointEnabled := v1alpha1.ExposeEndpointEnabled
autoScalingEnabled := v1alpha1.ScannerAutoScalingEnabled
scannerComponentEnabled := v1alpha1.ScannerComponentEnabled

wantCentral := v1alpha1.Central{
return &v1alpha1.Central{
ObjectMeta: metav1.ObjectMeta{
Name: p.Name,
Namespace: p.Namespace,
Expand Down Expand Up @@ -109,122 +105,39 @@ func TestDefaultCentral(t *testing.T) {
},
},
}
}

func assertCentralEquality(t *testing.T, wantCentral *v1alpha1.Central, gotCentral *v1alpha1.Central) {
assert.Equal(t, wantCentral, gotCentral)

// compare yaml
wantBytes, err := yaml.Marshal(wantCentral)
assert.NoError(t, err)

gotBytes, err := yaml.Marshal(central)
gotBytes, err := yaml.Marshal(gotCentral)
assert.NoError(t, err)

assert.YAMLEq(t, string(wantBytes), string(gotBytes))
}

func TestInternalCentral(t *testing.T) {
func TestDefaultCentral(t *testing.T) {
p := getDummyCentralParams()
p.IsInternal = true
central, err := renderDefaultCentral(p)
gotCentral, err := renderDefaultCentral(p)
assert.NoError(t, err)

exposeEndpointEnabled := v1alpha1.ExposeEndpointEnabled
autoScalingEnabled := v1alpha1.ScannerAutoScalingEnabled
scannerComponentEnabled := v1alpha1.ScannerComponentEnabled
wantCentral := wantCentralForDummyParams(&p)

wantCentral := v1alpha1.Central{
ObjectMeta: metav1.ObjectMeta{
Name: p.Name,
Namespace: p.Namespace,
Labels: map[string]string{
"rhacs.redhat.com/instance-type": p.InstanceType,
"rhacs.redhat.com/org-id": p.OrganizationID,
"rhacs.redhat.com/tenant": p.ID,
},
Annotations: map[string]string{
"rhacs.redhat.com/org-name": p.OrganizationName,
"platform.stackrox.io/managed-services": "true",
},
},
Spec: v1alpha1.CentralSpec{
Central: &v1alpha1.CentralComponentSpec{
AdminPasswordGenerationDisabled: pointers.Bool(true),
Monitoring: &v1alpha1.Monitoring{
ExposeEndpoint: &exposeEndpointEnabled,
},
DeploymentSpec: v1alpha1.DeploymentSpec{
Resources: &v1.ResourceRequirements{
Limits: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("4"),
v1.ResourceMemory: resource.MustParse("8Gi"),
},
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("2"),
v1.ResourceMemory: resource.MustParse("4Gi"),
},
},
},
},
Customize: &v1alpha1.CustomizeSpec{
Annotations: map[string]string{
"rhacs.redhat.com/org-name": p.OrganizationName,
},
Labels: map[string]string{
"rhacs.redhat.com/instance-type": p.InstanceType,
"rhacs.redhat.com/org-id": p.OrganizationID,
"rhacs.redhat.com/tenant": p.ID,
},
},
Scanner: &v1alpha1.ScannerComponentSpec{
Analyzer: &v1alpha1.ScannerAnalyzerComponent{
Scaling: &v1alpha1.ScannerAnalyzerScaling{
AutoScaling: &autoScalingEnabled,
MaxReplicas: pointers.Int32(3),
MinReplicas: pointers.Int32(1),
Replicas: pointers.Int32(1),
},
DeploymentSpec: v1alpha1.DeploymentSpec{
Resources: &v1.ResourceRequirements{
Limits: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("3"),
v1.ResourceMemory: resource.MustParse("8Gi"),
},
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("1.5"),
v1.ResourceMemory: resource.MustParse("4Gi"),
},
},
},
},
ScannerComponent: &scannerComponentEnabled,
DB: &v1alpha1.DeploymentSpec{
Resources: &v1.ResourceRequirements{
Limits: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("2.5"),
v1.ResourceMemory: resource.MustParse("4Gi"),
},
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("1.25"),
v1.ResourceMemory: resource.MustParse("2Gi"),
},
},
},
Monitoring: &v1alpha1.Monitoring{
ExposeEndpoint: &exposeEndpointEnabled,
},
},
Monitoring: &v1alpha1.GlobalMonitoring{
OpenShiftMonitoring: &v1alpha1.OpenShiftMonitoring{
Enabled: false,
},
},
},
}
assertCentralEquality(t, wantCentral, &gotCentral)
}

// compare yaml
wantBytes, err := yaml.Marshal(wantCentral)
func TestInternalCentral(t *testing.T) {
p := getDummyCentralParams()
p.IsInternal = true
gotCentral, err := renderDefaultCentral(p)
assert.NoError(t, err)

gotBytes, err := yaml.Marshal(central)
assert.NoError(t, err)
wantCentral := wantCentralForDummyParams(&p)
wantCentral.Spec.Monitoring.OpenShiftMonitoring.Enabled = false

assert.YAMLEq(t, string(wantBytes), string(gotBytes))
assertCentralEquality(t, wantCentral, &gotCentral)
}

0 comments on commit 67c60ee

Please sign in to comment.