Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Zunker <christian@mondoo.com>
  • Loading branch information
czunker committed Nov 16, 2023
1 parent 1d909dc commit 4c78466
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions controllers/status/operator_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestReportStatusRequestFromAuditConfig_AllDisabled(t *testing.T) {
{Identifier: NodeScanningIdentifier, Status: mondooclient.MessageStatus_MESSAGE_INFO, Message: "Node scanning is disabled"},
{Identifier: AdmissionControllerIdentifier, Status: mondooclient.MessageStatus_MESSAGE_INFO, Message: "Admission controller is disabled"},
{Identifier: ScanApiIdentifier, Status: mondooclient.MessageStatus_MESSAGE_INFO, Message: "Scan API is disabled"},
{Identifier: MondooOperatorIdentifier, Status: mondooclient.MessageStatus_MESSAGE_UNKNOWN, Message: "No status reported yet"},
}
assert.ElementsMatch(t, messages, reportStatus.Messages.Messages)
}
Expand Down Expand Up @@ -74,6 +75,7 @@ func TestReportStatusRequestFromAuditConfig_AllEnabled(t *testing.T) {
{Message: "Node Scanning is available", Status: v1.ConditionFalse, Type: v1alpha2.NodeScanningDegraded},
{Message: "Admission controller is available", Status: v1.ConditionFalse, Type: v1alpha2.AdmissionDegraded},
{Message: "ScanAPI controller is available", Status: v1.ConditionFalse, Type: v1alpha2.ScanAPIDegraded},
{Message: "Mondoo Operator controller is available", Status: v1.ConditionFalse, Type: v1alpha2.MondooOperaotrDegraded},
}

reportStatus := ReportStatusRequestFromAuditConfig(integrationMrn, m, nodes, v, logger)
Expand Down Expand Up @@ -101,6 +103,7 @@ func TestReportStatusRequestFromAuditConfig_AllEnabled(t *testing.T) {
{Identifier: NodeScanningIdentifier, Status: mondooclient.MessageStatus_MESSAGE_INFO, Message: m.Status.Conditions[2].Message},
{Identifier: AdmissionControllerIdentifier, Status: mondooclient.MessageStatus_MESSAGE_INFO, Message: m.Status.Conditions[3].Message},
{Identifier: ScanApiIdentifier, Status: mondooclient.MessageStatus_MESSAGE_INFO, Message: m.Status.Conditions[4].Message},
{Identifier: MondooOperatorIdentifier, Status: mondooclient.MessageStatus_MESSAGE_INFO, Message: m.Status.Conditions[5].Message},
}
assert.ElementsMatch(t, messages, reportStatus.Messages.Messages)
}
Expand Down Expand Up @@ -130,6 +133,7 @@ func TestReportStatusRequestFromAuditConfig_AllEnabled_DeprecatedFields(t *testi
{Message: "Node Scanning is available", Status: v1.ConditionFalse, Type: v1alpha2.NodeScanningDegraded},
{Message: "Admission controller is available", Status: v1.ConditionFalse, Type: v1alpha2.AdmissionDegraded},
{Message: "ScanAPI controller is available", Status: v1.ConditionFalse, Type: v1alpha2.ScanAPIDegraded},
{Message: "Mondoo Operator controller is available", Status: v1.ConditionFalse, Type: v1alpha2.MondooOperaotrDegraded},
}

reportStatus := ReportStatusRequestFromAuditConfig(integrationMrn, m, nodes, v, logger)
Expand Down Expand Up @@ -157,6 +161,7 @@ func TestReportStatusRequestFromAuditConfig_AllEnabled_DeprecatedFields(t *testi
{Identifier: NodeScanningIdentifier, Status: mondooclient.MessageStatus_MESSAGE_INFO, Message: m.Status.Conditions[2].Message},
{Identifier: AdmissionControllerIdentifier, Status: mondooclient.MessageStatus_MESSAGE_INFO, Message: m.Status.Conditions[3].Message},
{Identifier: ScanApiIdentifier, Status: mondooclient.MessageStatus_MESSAGE_INFO, Message: m.Status.Conditions[4].Message},
{Identifier: MondooOperatorIdentifier, Status: mondooclient.MessageStatus_MESSAGE_INFO, Message: m.Status.Conditions[5].Message},
}
assert.ElementsMatch(t, messages, reportStatus.Messages.Messages)
}
Expand All @@ -182,6 +187,7 @@ func TestReportStatusRequestFromAuditConfig_AllError(t *testing.T) {
{Message: "Node Scanning error", Status: v1.ConditionTrue, Type: v1alpha2.NodeScanningDegraded},
{Message: "Admission controller error", Status: v1.ConditionTrue, Type: v1alpha2.AdmissionDegraded},
{Message: "ScanAPI controller error", Status: v1.ConditionTrue, Type: v1alpha2.ScanAPIDegraded},
{Message: "Mondoo Operator controller is unavailable", Status: v1.ConditionTrue, Type: v1alpha2.MondooOperaotrDegraded},
}

reportStatus := ReportStatusRequestFromAuditConfig(integrationMrn, m, nodes, v, logger)
Expand All @@ -204,6 +210,7 @@ func TestReportStatusRequestFromAuditConfig_AllError(t *testing.T) {
{Identifier: NodeScanningIdentifier, Status: mondooclient.MessageStatus_MESSAGE_ERROR, Message: m.Status.Conditions[2].Message},
{Identifier: AdmissionControllerIdentifier, Status: mondooclient.MessageStatus_MESSAGE_ERROR, Message: m.Status.Conditions[3].Message},
{Identifier: ScanApiIdentifier, Status: mondooclient.MessageStatus_MESSAGE_ERROR, Message: m.Status.Conditions[4].Message},
{Identifier: MondooOperatorIdentifier, Status: mondooclient.MessageStatus_MESSAGE_ERROR, Message: m.Status.Conditions[5].Message},
}
assert.ElementsMatch(t, messages, reportStatus.Messages.Messages)
}
Expand Down
10 changes: 10 additions & 0 deletions controllers/status/status_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ func (s *StatusReporterSuite) TestReport() {
Identifier: ScanApiIdentifier,
Status: mondooclient.MessageStatus_MESSAGE_INFO,
},
{
Message: "No status reported yet",
Identifier: MondooOperatorIdentifier,
Status: mondooclient.MessageStatus_MESSAGE_UNKNOWN,
},
},
},
LastState: OperatorCustomState{
Expand Down Expand Up @@ -179,6 +184,11 @@ func (s *StatusReporterSuite) TestReport_StatusChange() {
Identifier: ScanApiIdentifier,
Status: mondooclient.MessageStatus_MESSAGE_INFO,
},
{
Message: "No status reported yet",
Identifier: MondooOperatorIdentifier,
Status: mondooclient.MessageStatus_MESSAGE_UNKNOWN,
},
},
},
LastState: operatorState,
Expand Down

0 comments on commit 4c78466

Please sign in to comment.