diff --git a/cmd/tnf/claim/show/failures/failures.go b/cmd/tnf/claim/show/failures/failures.go index d4885699d..51d2106e2 100644 --- a/cmd/tnf/claim/show/failures/failures.go +++ b/cmd/tnf/claim/show/failures/failures.go @@ -157,17 +157,17 @@ func parseOutputFormatFlag() (string, error) { return "", fmt.Errorf("invalid output format flag %q - available formats: %v", outputFormatFlag, availableOutputFormats) } -// Parses the claim's test case's skipReason field and creates a list +// Parses the claim's test case's checkDetails field and creates a list // of NonCompliantObject's. -func getNonCompliantObjectsFromFailureReason(skipReason string) ([]NonCompliantObject, error) { +func getNonCompliantObjectsFromFailureReason(checkDetails string) ([]NonCompliantObject, error) { objects := struct { Compliant []testhelper.ReportObject `json:"CompliantObjectsOut"` NonCompliant []testhelper.ReportObject `json:"NonCompliantObjectsOut"` }{} - err := json.Unmarshal([]byte(skipReason), &objects) + err := json.Unmarshal([]byte(checkDetails), &objects) if err != nil { - return nil, fmt.Errorf("failed to decode skipReason %s: %v", skipReason, err) + return nil, fmt.Errorf("failed to decode checkDetails %s: %v", checkDetails, err) } // Now let's create a list of our NonCompliantObject-type items. @@ -194,7 +194,7 @@ func printFailuresText(testSuites []FailedTestSuite) { // In case this tc was not using report objects, just print the failure reason string. if len(tc.NonCompliantObjects) == 0 { - fmt.Printf(" Failure reason: %s\n", tc.SkipReason) + fmt.Printf(" Failure reason: %s\n", tc.CheckDetails) continue } @@ -253,12 +253,12 @@ func getFailedTestCasesByTestSuite(claimResultsByTestSuite map[string][]*claim.T TestCaseDescription: tc.CatalogInfo.Description, } - nonCompliantObjects, err := getNonCompliantObjectsFromFailureReason(tc.SkipReason) + nonCompliantObjects, err := getNonCompliantObjectsFromFailureReason(tc.CheckDetails) if err != nil { // This means the test case doesn't use the report objects yet. Just use the raw failure reason instead. // Also, send the error into stderr, so it can be filtered out with "2>/errors.txt" or "2>/dev/null". fmt.Fprintf(os.Stderr, "Failed to parse non compliant objects from test case %s (test suite %s): %v", tc.TestID.ID, testSuite, err) - failingTc.SkipReason = tc.SkipReason + failingTc.CheckDetails = tc.CheckDetails } else { failingTc.NonCompliantObjects = nonCompliantObjects } diff --git a/cmd/tnf/claim/show/failures/failures_test.go b/cmd/tnf/claim/show/failures/failures_test.go index 08727a396..484580afb 100644 --- a/cmd/tnf/claim/show/failures/failures_test.go +++ b/cmd/tnf/claim/show/failures/failures_test.go @@ -90,22 +90,22 @@ func TestParseOutputFormatFlag(t *testing.T) { func TestGetNonCompliantObjectsFromFailureReason(t *testing.T) { testCases := []struct { - skipReason string + checkDetails string expectedNonCompliantObjects []NonCompliantObject expectedError string }{ { - skipReason: "", + checkDetails: "", expectedNonCompliantObjects: nil, - expectedError: `failed to decode skipReason : unexpected end of JSON input`, + expectedError: `failed to decode checkDetails : unexpected end of JSON input`, }, { - skipReason: `{"CompliantObjectsOut": null, "NonCompliantObjectsOut": null}`, + checkDetails: `{"CompliantObjectsOut": null, "NonCompliantObjectsOut": null}`, expectedNonCompliantObjects: []NonCompliantObject{}, }, // One container failed the SYS_ADMIN check. { - skipReason: `{ + checkDetails: `{ "CompliantObjectsOut": null, "NonCompliantObjectsOut": [ { @@ -159,7 +159,7 @@ func TestGetNonCompliantObjectsFromFailureReason(t *testing.T) { }, // Two containers failed the SYS_ADMIN check. { - skipReason: `{ + checkDetails: `{ "CompliantObjectsOut": null, "NonCompliantObjectsOut": [ { @@ -260,7 +260,7 @@ func TestGetNonCompliantObjectsFromFailureReason(t *testing.T) { } for _, tc := range testCases { - nonCompliantObjects, err := getNonCompliantObjectsFromFailureReason(tc.skipReason) + nonCompliantObjects, err := getNonCompliantObjectsFromFailureReason(tc.checkDetails) if err != nil { assert.Equal(t, tc.expectedError, err.Error()) } @@ -271,7 +271,7 @@ func TestGetNonCompliantObjectsFromFailureReason(t *testing.T) { // Uses claim files in testdata folder: // claim1.json -> Two test suites, access-control & platform-alteration. One failed test case in the access-control ts. -// claim2.json -> Same as clam1.json, but the skipReason is a simple string, not using report objects yet. +// claim2.json -> Same as clam1.json, but the checkDetails is a simple string, not using report objects yet. func TestGetFailedTestCasesByTestSuite(t *testing.T) { testCases := []struct { claimFilePath string @@ -295,7 +295,7 @@ func TestGetFailedTestCasesByTestSuite(t *testing.T) { { TestCaseName: "access-control-sys-admin-capability-check", TestCaseDescription: "Ensures that containers do not use SYS_ADMIN capability", - SkipReason: "pod xxx ns yyy container zzz uses SYS_ADMIN", + CheckDetails: "pod xxx ns yyy container zzz uses SYS_ADMIN", }, }, }, diff --git a/cmd/tnf/claim/show/failures/testdata/claim1.json b/cmd/tnf/claim/show/failures/testdata/claim1.json index d38af3764..7312662c2 100644 --- a/cmd/tnf/claim/show/failures/testdata/claim1.json +++ b/cmd/tnf/claim/show/failures/testdata/claim1.json @@ -7,7 +7,7 @@ "endTime": "2023-07-18 03:37:42.095508375 -0500 CDT m=+23.133713410", "failureLineContent": "\t\tfail(string(bytes))", "failureLocation": "/home/greyerof/github/tnf/pkg/testhelper/testhelper.go:352", - "skipReason": "{\"CompliantObjectsOut\":null,\"NonCompliantObjectsOut\":[{\"ObjectType\":\"Container\",\"ObjectFieldsKeys\":[\"Reason For Non Compliance\",\"Namespace\",\"Pod Name\",\"Container Name\",\"SCC Capability\"],\"ObjectFieldsValues\":[\"Non compliant capability detected in container\",\"tnf\",\"test-887998557-8gwwm\",\"test\",\"SYS_ADMIN\"]},{\"ObjectType\":\"Container\",\"ObjectFieldsKeys\":[\"Reason For Non Compliance\",\"Namespace\",\"Pod Name\",\"Container Name\",\"SCC Capability\"],\"ObjectFieldsValues\":[\"Non compliant capability detected in container\",\"tnf\",\"test-887998557-pr2w5\",\"test\",\"SYS_ADMIN\"]}]}", + "checkDetails": "{\"CompliantObjectsOut\":null,\"NonCompliantObjectsOut\":[{\"ObjectType\":\"Container\",\"ObjectFieldsKeys\":[\"Reason For Non Compliance\",\"Namespace\",\"Pod Name\",\"Container Name\",\"SCC Capability\"],\"ObjectFieldsValues\":[\"Non compliant capability detected in container\",\"tnf\",\"test-887998557-8gwwm\",\"test\",\"SYS_ADMIN\"]},{\"ObjectType\":\"Container\",\"ObjectFieldsKeys\":[\"Reason For Non Compliance\",\"Namespace\",\"Pod Name\",\"Container Name\",\"SCC Capability\"],\"ObjectFieldsValues\":[\"Non compliant capability detected in container\",\"tnf\",\"test-887998557-pr2w5\",\"test\",\"SYS_ADMIN\"]}]}", "startTime": "2023-07-18 03:37:42.095225914 -0500 CDT m=+23.133430956", "state": "failed", "testID": { @@ -34,7 +34,7 @@ "endTime": "2023-07-18 03:37:44.324268378 -0500 CDT m=+25.362473413", "failureLineContent": "", "failureLocation": ":0", - "skipReason": "", + "checkDetails": "", "startTime": "2023-07-18 03:37:44.324023044 -0500 CDT m=+25.362228078", "state": "passed", "testID": { @@ -61,7 +61,7 @@ "endTime": "0001-01-01 00:00:00 +0000 UTC", "failureLineContent": "", "failureLocation": ":0", - "skipReason": "", + "checkDetails": "", "startTime": "2023-07-18 03:37:46.483797163 -0500 CDT m=+27.522002219", "state": "skipped", "testID": { @@ -88,7 +88,7 @@ "endTime": "0001-01-01 00:00:00 +0000 UTC", "failureLineContent": "", "failureLocation": ":0", - "skipReason": "", + "checkDetails": "", "startTime": "2023-07-18 03:37:46.483566421 -0500 CDT m=+27.521771494", "state": "skipped", "testID": { diff --git a/cmd/tnf/claim/show/failures/testdata/claim2.json b/cmd/tnf/claim/show/failures/testdata/claim2.json index 25f78d784..5090e0708 100644 --- a/cmd/tnf/claim/show/failures/testdata/claim2.json +++ b/cmd/tnf/claim/show/failures/testdata/claim2.json @@ -7,7 +7,7 @@ "endTime": "2023-07-18 03:37:42.095508375 -0500 CDT m=+23.133713410", "failureLineContent": "\t\tfail(string(bytes))", "failureLocation": "/home/greyerof/github/tnf/pkg/testhelper/testhelper.go:352", - "skipReason": "pod xxx ns yyy container zzz uses SYS_ADMIN", + "checkDetails": "pod xxx ns yyy container zzz uses SYS_ADMIN", "startTime": "2023-07-18 03:37:42.095225914 -0500 CDT m=+23.133430956", "state": "failed", "testID": { @@ -34,7 +34,7 @@ "endTime": "2023-07-18 03:37:44.324268378 -0500 CDT m=+25.362473413", "failureLineContent": "", "failureLocation": ":0", - "skipReason": "", + "checkDetails": "", "startTime": "2023-07-18 03:37:44.324023044 -0500 CDT m=+25.362228078", "state": "passed", "testID": { @@ -61,7 +61,7 @@ "endTime": "0001-01-01 00:00:00 +0000 UTC", "failureLineContent": "", "failureLocation": ":0", - "skipReason": "", + "checkDetails": "", "startTime": "2023-07-18 03:37:46.483797163 -0500 CDT m=+27.522002219", "state": "skipped", "testID": { @@ -88,7 +88,7 @@ "endTime": "0001-01-01 00:00:00 +0000 UTC", "failureLineContent": "", "failureLocation": ":0", - "skipReason": "", + "checkDetails": "", "startTime": "2023-07-18 03:37:46.483566421 -0500 CDT m=+27.521771494", "state": "skipped", "testID": { diff --git a/cmd/tnf/claim/show/failures/types.go b/cmd/tnf/claim/show/failures/types.go index 487e5dad6..fbb76445a 100644 --- a/cmd/tnf/claim/show/failures/types.go +++ b/cmd/tnf/claim/show/failures/types.go @@ -42,7 +42,7 @@ func (spec *ObjectSpec) MarshalJSON() ([]byte, error) { type FailedTestCase struct { TestCaseName string `json:"name"` TestCaseDescription string `json:"description"` - SkipReason string `json:"skipReason,omitempty"` + CheckDetails string `json:"checkDetails,omitempty"` NonCompliantObjects []NonCompliantObject `json:"nonCompliantObjects,omitempty"` }