Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
edcdavid committed Dec 14, 2023
1 parent af7b248 commit cecfefc
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 204 deletions.
180 changes: 90 additions & 90 deletions cmd/tnf/claim/compare/testdata/claim_access_control.json

Large diffs are not rendered by default.

180 changes: 90 additions & 90 deletions cmd/tnf/claim/compare/testdata/claim_observability.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions cmd/tnf/claim/show/failures/failures.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 failureReason field and creates a list
// Parses the claim's test case's skipReason field and creates a list
// of NonCompliantObject's.
func getNonCompliantObjectsFromFailureReason(failureReason string) ([]NonCompliantObject, error) {
func getNonCompliantObjectsFromFailureReason(skipReason string) ([]NonCompliantObject, error) {
objects := struct {
Compliant []testhelper.ReportObject `json:"CompliantObjectsOut"`
NonCompliant []testhelper.ReportObject `json:"NonCompliantObjectsOut"`
}{}

err := json.Unmarshal([]byte(failureReason), &objects)
err := json.Unmarshal([]byte(skipReason), &objects)
if err != nil {
return nil, fmt.Errorf("failed to decode failureReason %s: %v", failureReason, err)
return nil, fmt.Errorf("failed to decode skipReason %s: %v", skipReason, err)
}

// Now let's create a list of our NonCompliantObject-type items.
Expand Down
16 changes: 8 additions & 8 deletions cmd/tnf/claim/show/failures/failures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,22 @@ func TestParseOutputFormatFlag(t *testing.T) {

func TestGetNonCompliantObjectsFromFailureReason(t *testing.T) {
testCases := []struct {
failureReason string
skipReason string
expectedNonCompliantObjects []NonCompliantObject
expectedError string
}{
{
failureReason: "",
skipReason: "",
expectedNonCompliantObjects: nil,
expectedError: `failed to decode failureReason : unexpected end of JSON input`,
expectedError: `failed to decode skipReason : unexpected end of JSON input`,
},
{
failureReason: `{"CompliantObjectsOut": null, "NonCompliantObjectsOut": null}`,
skipReason: `{"CompliantObjectsOut": null, "NonCompliantObjectsOut": null}`,
expectedNonCompliantObjects: []NonCompliantObject{},
},
// One container failed the SYS_ADMIN check.
{
failureReason: `{
skipReason: `{
"CompliantObjectsOut": null,
"NonCompliantObjectsOut": [
{
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestGetNonCompliantObjectsFromFailureReason(t *testing.T) {
},
// Two containers failed the SYS_ADMIN check.
{
failureReason: `{
skipReason: `{
"CompliantObjectsOut": null,
"NonCompliantObjectsOut": [
{
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestGetNonCompliantObjectsFromFailureReason(t *testing.T) {
}

for _, tc := range testCases {
nonCompliantObjects, err := getNonCompliantObjectsFromFailureReason(tc.failureReason)
nonCompliantObjects, err := getNonCompliantObjectsFromFailureReason(tc.skipReason)
if err != nil {
assert.Equal(t, tc.expectedError, err.Error())
}
Expand All @@ -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 failureReason is a simple string, not using report objects yet.
// claim2.json -> Same as clam1.json, but the skipReason is a simple string, not using report objects yet.
func TestGetFailedTestCasesByTestSuite(t *testing.T) {
testCases := []struct {
claimFilePath string
Expand Down
8 changes: 4 additions & 4 deletions cmd/tnf/claim/show/failures/testdata/claim1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"failureReason": "{\"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\"]}]}",
"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\"]}]}",
"startTime": "2023-07-18 03:37:42.095225914 -0500 CDT m=+23.133430956",
"state": "failed",
"testID": {
Expand All @@ -34,7 +34,7 @@
"endTime": "2023-07-18 03:37:44.324268378 -0500 CDT m=+25.362473413",
"failureLineContent": "",
"failureLocation": ":0",
"failureReason": "",
"skipReason": "",
"startTime": "2023-07-18 03:37:44.324023044 -0500 CDT m=+25.362228078",
"state": "passed",
"testID": {
Expand All @@ -61,7 +61,7 @@
"endTime": "0001-01-01 00:00:00 +0000 UTC",
"failureLineContent": "",
"failureLocation": ":0",
"failureReason": "",
"skipReason": "",
"startTime": "2023-07-18 03:37:46.483797163 -0500 CDT m=+27.522002219",
"state": "skipped",
"testID": {
Expand All @@ -88,7 +88,7 @@
"endTime": "0001-01-01 00:00:00 +0000 UTC",
"failureLineContent": "",
"failureLocation": ":0",
"failureReason": "",
"skipReason": "",
"startTime": "2023-07-18 03:37:46.483566421 -0500 CDT m=+27.521771494",
"state": "skipped",
"testID": {
Expand Down
8 changes: 4 additions & 4 deletions cmd/tnf/claim/show/failures/testdata/claim2.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"failureReason": "pod xxx ns yyy container zzz uses SYS_ADMIN",
"skipReason": "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": {
Expand All @@ -34,7 +34,7 @@
"endTime": "2023-07-18 03:37:44.324268378 -0500 CDT m=+25.362473413",
"failureLineContent": "",
"failureLocation": ":0",
"failureReason": "",
"skipReason": "",
"startTime": "2023-07-18 03:37:44.324023044 -0500 CDT m=+25.362228078",
"state": "passed",
"testID": {
Expand All @@ -61,7 +61,7 @@
"endTime": "0001-01-01 00:00:00 +0000 UTC",
"failureLineContent": "",
"failureLocation": ":0",
"failureReason": "",
"skipReason": "",
"startTime": "2023-07-18 03:37:46.483797163 -0500 CDT m=+27.522002219",
"state": "skipped",
"testID": {
Expand All @@ -88,7 +88,7 @@
"endTime": "0001-01-01 00:00:00 +0000 UTC",
"failureLineContent": "",
"failureLocation": ":0",
"failureReason": "",
"skipReason": "",
"startTime": "2023-07-18 03:37:46.483566421 -0500 CDT m=+27.521771494",
"state": "skipped",
"testID": {
Expand Down
2 changes: 1 addition & 1 deletion cmd/tnf/claim/show/failures/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package failures
import "fmt"

// Custom object type needed to provide a different JSON serialization than
// the one in claim's test cases' failureReason field.
// the one in claim's test cases' skipReason field.
type NonCompliantObject struct {
Type string `json:"type"`
Reason string `json:"reason"`
Expand Down
6 changes: 3 additions & 3 deletions cmd/tnf/pkg/claim/claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ func TestIsClaimFormatVersionSupported(t *testing.T) {
},
{
claimFormatVersion: "v0.0.0",
expectedError: "claim format version v0.0.0 is not supported. Supported version is v0.2.0",
expectedError: "claim format version v0.0.0 is not supported. Supported version is v0.3.0",
},
{
claimFormatVersion: "v0.0.1",
expectedError: "claim format version v0.0.1 is not supported. Supported version is v0.2.0",
expectedError: "claim format version v0.0.1 is not supported. Supported version is v0.3.0",
},
{
claimFormatVersion: "v0.2.0",
claimFormatVersion: "v0.3.0",
expectedError: "",
},
}
Expand Down

0 comments on commit cecfefc

Please sign in to comment.