From f951a8da7c328c38a822b334988a98fdd32bf3bf Mon Sep 17 00:00:00 2001 From: David Elie-Dit-Cosaque Date: Wed, 20 Oct 2021 10:46:40 -0500 Subject: [PATCH] fix --- pkg/claim/schema.go | 275 +++++++++++++++++++++++++++++++++++++- schemas/claim.schema.json | 6 +- 2 files changed, 277 insertions(+), 4 deletions(-) diff --git a/pkg/claim/schema.go b/pkg/claim/schema.go index 7092cbc..4a2ed0e 100644 --- a/pkg/claim/schema.go +++ b/pkg/claim/schema.go @@ -11,7 +11,7 @@ // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// Code generated by `test-network-function-claim/cmd/generate/generate.go` on: 2021-10-19 17:41:32.102203846 -0500 CDT m=+0.000775904 +// Code generated by `test-network-function-claim/cmd/generate/generate.go` on: 2021-10-20 10:45:48.026387017 -0500 CDT m=+0.000652323 // // `https://github.com/a-h/generate` provides a generic set of interfaces to convert JSON schema into // workable GoLang struct implementations. However, the code generator is limited and does not allow @@ -72,6 +72,40 @@ type Metadata struct { StartTime string `json:"startTime"` } +// Result result is the result of running a testcase. +type Result struct { + + // Ginkgo writer output during the test run. + CapturedTestOutput string `json:"CapturedTestOutput"` + + // The duration of the test in nanoseconds. + Duration int `json:"duration"` + + // The end time of the test. + EndTime string `json:"endTime,omitempty"` + + // The content of the line where the failure happened + FailureLineContent string `json:"failureLineContent"` + + // The Filename and line number where the failure happened + FailureLocation string `json:"failureLocation"` + + // Describes the test failure in detail. + FailureReason string `json:"failureReason"` + + // The start time of the test. + StartTime string `json:"startTime"` + + // The test result state: INVALID SPEC STATE, pending,skipped,passed,failed,aborted,panicked,interrupted + State string `json:"state"` + + // The test identifier + TestID *Identifier `json:"testID,omitempty"` + + // The JUnit test text. + TestText string `json:"testText"` +} + // Root A test-network-function claim is an attestation of the tests performed, the results and the various configurations. Since a claim must be reproducible, it also includes an overview of the systems under test and their physical configurations. type Root struct { Claim *Claim `json:"claim"` @@ -397,6 +431,245 @@ func (strct *Metadata) UnmarshalJSON(b []byte) error { return nil } +func (strct *Result) MarshalJSON() ([]byte, error) { + buf := bytes.NewBuffer(make([]byte, 0)) + buf.WriteString("{") + comma := false + // "CapturedTestOutput" field is required + // only required object types supported for marshal checking (for now) + // Marshal the "CapturedTestOutput" field + if comma { + buf.WriteString(",") + } + buf.WriteString("\"CapturedTestOutput\": ") + if tmp, err := json.Marshal(strct.CapturedTestOutput); err != nil { + return nil, err + } else { + buf.Write(tmp) + } + comma = true + // "Duration" field is required + // only required object types supported for marshal checking (for now) + // Marshal the "duration" field + if comma { + buf.WriteString(",") + } + buf.WriteString("\"duration\": ") + if tmp, err := json.Marshal(strct.Duration); err != nil { + return nil, err + } else { + buf.Write(tmp) + } + comma = true + // Marshal the "endTime" field + if comma { + buf.WriteString(",") + } + buf.WriteString("\"endTime\": ") + if tmp, err := json.Marshal(strct.EndTime); err != nil { + return nil, err + } else { + buf.Write(tmp) + } + comma = true + // "FailureLineContent" field is required + // only required object types supported for marshal checking (for now) + // Marshal the "failureLineContent" field + if comma { + buf.WriteString(",") + } + buf.WriteString("\"failureLineContent\": ") + if tmp, err := json.Marshal(strct.FailureLineContent); err != nil { + return nil, err + } else { + buf.Write(tmp) + } + comma = true + // "FailureLocation" field is required + // only required object types supported for marshal checking (for now) + // Marshal the "failureLocation" field + if comma { + buf.WriteString(",") + } + buf.WriteString("\"failureLocation\": ") + if tmp, err := json.Marshal(strct.FailureLocation); err != nil { + return nil, err + } else { + buf.Write(tmp) + } + comma = true + // "FailureReason" field is required + // only required object types supported for marshal checking (for now) + // Marshal the "failureReason" field + if comma { + buf.WriteString(",") + } + buf.WriteString("\"failureReason\": ") + if tmp, err := json.Marshal(strct.FailureReason); err != nil { + return nil, err + } else { + buf.Write(tmp) + } + comma = true + // "StartTime" field is required + // only required object types supported for marshal checking (for now) + // Marshal the "startTime" field + if comma { + buf.WriteString(",") + } + buf.WriteString("\"startTime\": ") + if tmp, err := json.Marshal(strct.StartTime); err != nil { + return nil, err + } else { + buf.Write(tmp) + } + comma = true + // "State" field is required + // only required object types supported for marshal checking (for now) + // Marshal the "state" field + if comma { + buf.WriteString(",") + } + buf.WriteString("\"state\": ") + if tmp, err := json.Marshal(strct.State); err != nil { + return nil, err + } else { + buf.Write(tmp) + } + comma = true + // Marshal the "testID" field + if comma { + buf.WriteString(",") + } + buf.WriteString("\"testID\": ") + if tmp, err := json.Marshal(strct.TestID); err != nil { + return nil, err + } else { + buf.Write(tmp) + } + comma = true + // "TestText" field is required + // only required object types supported for marshal checking (for now) + // Marshal the "testText" field + if comma { + buf.WriteString(",") + } + buf.WriteString("\"testText\": ") + if tmp, err := json.Marshal(strct.TestText); err != nil { + return nil, err + } else { + buf.Write(tmp) + } + comma = true + + buf.WriteString("}") + rv := buf.Bytes() + return rv, nil +} + +func (strct *Result) UnmarshalJSON(b []byte) error { + CapturedTestOutputReceived := false + durationReceived := false + failureLineContentReceived := false + failureLocationReceived := false + failureReasonReceived := false + startTimeReceived := false + stateReceived := false + testTextReceived := false + var jsonMap map[string]json.RawMessage + if err := json.Unmarshal(b, &jsonMap); err != nil { + return err + } + // parse all the defined properties + for k, v := range jsonMap { + switch k { + case "CapturedTestOutput": + if err := json.Unmarshal([]byte(v), &strct.CapturedTestOutput); err != nil { + return err + } + CapturedTestOutputReceived = true + case "duration": + if err := json.Unmarshal([]byte(v), &strct.Duration); err != nil { + return err + } + durationReceived = true + case "endTime": + if err := json.Unmarshal([]byte(v), &strct.EndTime); err != nil { + return err + } + case "failureLineContent": + if err := json.Unmarshal([]byte(v), &strct.FailureLineContent); err != nil { + return err + } + failureLineContentReceived = true + case "failureLocation": + if err := json.Unmarshal([]byte(v), &strct.FailureLocation); err != nil { + return err + } + failureLocationReceived = true + case "failureReason": + if err := json.Unmarshal([]byte(v), &strct.FailureReason); err != nil { + return err + } + failureReasonReceived = true + case "startTime": + if err := json.Unmarshal([]byte(v), &strct.StartTime); err != nil { + return err + } + startTimeReceived = true + case "state": + if err := json.Unmarshal([]byte(v), &strct.State); err != nil { + return err + } + stateReceived = true + case "testID": + if err := json.Unmarshal([]byte(v), &strct.TestID); err != nil { + return err + } + case "testText": + if err := json.Unmarshal([]byte(v), &strct.TestText); err != nil { + return err + } + testTextReceived = true + default: + return fmt.Errorf("additional property not allowed: \"" + k + "\"") + } + } + // check if CapturedTestOutput (a required property) was received + if !CapturedTestOutputReceived { + return errors.New("\"CapturedTestOutput\" is required but was not present") + } + // check if duration (a required property) was received + if !durationReceived { + return errors.New("\"duration\" is required but was not present") + } + // check if failureLineContent (a required property) was received + if !failureLineContentReceived { + return errors.New("\"failureLineContent\" is required but was not present") + } + // check if failureLocation (a required property) was received + if !failureLocationReceived { + return errors.New("\"failureLocation\" is required but was not present") + } + // check if failureReason (a required property) was received + if !failureReasonReceived { + return errors.New("\"failureReason\" is required but was not present") + } + // check if startTime (a required property) was received + if !startTimeReceived { + return errors.New("\"startTime\" is required but was not present") + } + // check if state (a required property) was received + if !stateReceived { + return errors.New("\"state\" is required but was not present") + } + // check if testText (a required property) was received + if !testTextReceived { + return errors.New("\"testText\" is required but was not present") + } + return nil +} + func (strct *Root) MarshalJSON() ([]byte, error) { buf := bytes.NewBuffer(make([]byte, 0)) buf.WriteString("{") diff --git a/schemas/claim.schema.json b/schemas/claim.schema.json index 03c2325..eca5376 100644 --- a/schemas/claim.schema.json +++ b/schemas/claim.schema.json @@ -64,9 +64,9 @@ "type": "string", "description": "Ginkgo writer output during the test run." }, - "testId": { - "type": "identifier", - "description": "The test identifier" + "testID": { + "description": "The test identifier", + "$ref": "#/definitions/identifier" } },