From 63c0ae53f6c7a01092a315b7a6db88ac76f1e09a Mon Sep 17 00:00:00 2001 From: Henri Heimann Date: Wed, 16 Jun 2021 15:50:47 +0200 Subject: [PATCH 1/2] add before and after scenario and step hook messages Signed-off-by: Henri Heimann --- generate.go | 88 ++++++++++++++++++++++++++++++++--------------------- schema.json | 32 +++++++++++++++++++ 2 files changed, 86 insertions(+), 34 deletions(-) diff --git a/generate.go b/generate.go index 151cc10..d078ec0 100644 --- a/generate.go +++ b/generate.go @@ -67,27 +67,31 @@ type spec struct { } type scenario struct { - Heading string `json:"scenarioHeading"` - Tags []string `json:"tags"` - ExecutionTime int64 `json:"executionTime"` - ExecutionStatus status `json:"executionStatus"` - Contexts []item `json:"contexts"` - Teardowns []item `json:"teardowns"` - Items []item `json:"items"` - BeforeScenarioHookFailure *hookFailure `json:"beforeScenarioHookFailure"` - AfterScenarioHookFailure *hookFailure `json:"afterScenarioHookFailure"` - SkipErrors []string `json:"skipErrors"` - TableRowIndex int `json:"tableRowIndex"` + Heading string `json:"scenarioHeading"` + Tags []string `json:"tags"` + ExecutionTime int64 `json:"executionTime"` + ExecutionStatus status `json:"executionStatus"` + Contexts []item `json:"contexts"` + Teardowns []item `json:"teardowns"` + Items []item `json:"items"` + BeforeScenarioHookFailure *hookFailure `json:"beforeScenarioHookFailure"` + BeforeScenarioHookMessages []string `json:"beforeScenarioHookMessages"` + AfterScenarioHookFailure *hookFailure `json:"afterScenarioHookFailure"` + AfterScenarioHookMessages []string `json:"afterScenarioHookMessages"` + SkipErrors []string `json:"skipErrors"` + TableRowIndex int `json:"tableRowIndex"` } type step struct { - ItemType tokenKind `json:"itemType"` - StepText string `json:"stepText"` - Parameters []Parameter `json:"parameters"` - Table *table `json:"table"` - BeforeStepHookFailure *hookFailure `json:"beforeStepHookFailure"` - AfterStepHookFailure *hookFailure `json:"afterStepHookFailure"` - Result *result `json:"result"` + ItemType tokenKind `json:"itemType"` + StepText string `json:"stepText"` + Parameters []Parameter `json:"parameters"` + Table *table `json:"table"` + BeforeStepHookFailure *hookFailure `json:"beforeStepHookFailure"` + BeforeStepHookMessages []string `json:"beforeStepHookMessages"` + AfterStepHookFailure *hookFailure `json:"afterStepHookFailure"` + AfterStepHookMessages []string `json:"afterStepHookMessages"` + Result *result `json:"result"` } func (s *step) kind() tokenKind { @@ -201,17 +205,25 @@ func toSpec(psr *gauge_messages.ProtoSpecResult) spec { func toScenario(protoSce *gauge_messages.ProtoScenario, tableRowIndex int) scenario { sce := scenario{ - Heading: protoSce.GetScenarioHeading(), - ExecutionTime: protoSce.GetExecutionTime(), - Tags: make([]string, 0), - ExecutionStatus: getScenarioStatus(protoSce), - Contexts: make([]item, 0), - Items: make([]item, 0), - Teardowns: make([]item, 0), - BeforeScenarioHookFailure: toHookFailure(protoSce.GetPreHookFailure()), - AfterScenarioHookFailure: toHookFailure(protoSce.GetPostHookFailure()), - TableRowIndex: tableRowIndex, - SkipErrors: make([]string, 0), + Heading: protoSce.GetScenarioHeading(), + ExecutionTime: protoSce.GetExecutionTime(), + Tags: make([]string, 0), + ExecutionStatus: getScenarioStatus(protoSce), + Contexts: make([]item, 0), + Items: make([]item, 0), + Teardowns: make([]item, 0), + BeforeScenarioHookFailure: toHookFailure(protoSce.GetPreHookFailure()), + BeforeScenarioHookMessages: make([]string, 0), + AfterScenarioHookFailure: toHookFailure(protoSce.GetPostHookFailure()), + AfterScenarioHookMessages: make([]string, 0), + TableRowIndex: tableRowIndex, + SkipErrors: make([]string, 0), + } + if protoSce.GetPreHookMessages() != nil { + sce.BeforeScenarioHookMessages = protoSce.GetPreHookMessages() + } + if protoSce.GetPostHookMessages() != nil { + sce.AfterScenarioHookMessages = protoSce.GetPostHookMessages() } if protoSce.GetSkipErrors() != nil { sce.SkipErrors = protoSce.GetSkipErrors() @@ -290,11 +302,19 @@ func toStep(protoStep *gauge_messages.ProtoStep) *step { result.Messages = res.GetMessage() } step := &step{ - ItemType: stepKind, - StepText: protoStep.GetActualText(), - Result: result, - BeforeStepHookFailure: toHookFailure(protoStep.GetStepExecutionResult().GetPreHookFailure()), - AfterStepHookFailure: toHookFailure(protoStep.GetStepExecutionResult().GetPostHookFailure()), + ItemType: stepKind, + StepText: protoStep.GetActualText(), + Result: result, + BeforeStepHookFailure: toHookFailure(protoStep.GetStepExecutionResult().GetPreHookFailure()), + BeforeStepHookMessages: make([]string, 0), + AfterStepHookFailure: toHookFailure(protoStep.GetStepExecutionResult().GetPostHookFailure()), + AfterStepHookMessages: make([]string, 0), + } + if protoStep.GetPreHookMessages() != nil { + step.BeforeStepHookMessages = protoStep.GetPreHookMessages() + } + if protoStep.GetPostHookMessages() != nil { + step.AfterStepHookMessages = protoStep.GetPostHookMessages() } params := make([]Parameter, 0) diff --git a/schema.json b/schema.json index d251967..b483776 100644 --- a/schema.json +++ b/schema.json @@ -171,10 +171,24 @@ "description": "Before scenario hook failure", "$ref": "#/definitions/hookFailure" }, + "beforeScenarioHookMessages": { + "description": "Custom messages written in before scenario hooks", + "type": "array", + "items": { + "type": "string" + } + }, "afterScenarioHookFailure": { "description": "After scenario hook failure", "$ref": "#/definitions/hookFailure" }, + "afterScenarioHookMessages": { + "description": "Custom messages written in after scenario hooks", + "type": "array", + "items": { + "type": "string" + } + }, "skipErrors": { "description": "Reasons if scenario is skipped", "type": "array", @@ -196,7 +210,9 @@ "teardowns", "items", "beforeScenarioHookFailure", + "beforeScenarioHookMessages", "afterScenarioHookFailure", + "afterScenarioHookMessages", "skipErrors", "tableRowIndex" ] @@ -345,10 +361,24 @@ "description": "Before step hook failure information", "$ref": "#/definitions/hookFailure" }, + "beforeStepHookMessages": { + "description": "Custom messages written in before step hooks", + "type": "array", + "items": { + "type": "string" + } + }, "afterStepHookFailure": { "description": "After step hook failure information", "$ref": "#/definitions/hookFailure" }, + "afterStepHookMessages": { + "description": "Custom messages written in after step hooks", + "type": "array", + "items": { + "type": "string" + } + }, "result": { "description": "Execution result", "$ref": "#/definitions/result" @@ -358,7 +388,9 @@ "itemType", "stepText", "beforeStepHookFailure", + "beforeStepHookMessages", "afterStepHookFailure", + "afterStepHookMessages", "result", "parameters" ] From d391c7e7430dd0c849836bd660ac1fe307db95be Mon Sep 17 00:00:00 2001 From: Henri Heimann Date: Wed, 16 Jun 2021 16:58:01 +0200 Subject: [PATCH 2/2] add before and after suite and spec hook messages Signed-off-by: Henri Heimann --- _testdata/sample.json | 16 ++++++ generate.go | 124 ++++++++++++++++++++++++------------------ schema.json | 32 +++++++++++ 3 files changed, 120 insertions(+), 52 deletions(-) diff --git a/_testdata/sample.json b/_testdata/sample.json index abb430e..a442245 100644 --- a/_testdata/sample.json +++ b/_testdata/sample.json @@ -35,7 +35,9 @@ ], "table": null, "beforeStepHookFailure": null, + "beforeStepHookMessages": [], "afterStepHookFailure": null, + "afterStepHookMessages": [], "result": { "status": "pass", "stackTrace": "", @@ -69,7 +71,9 @@ ], "table": null, "beforeStepHookFailure": null, + "beforeStepHookMessages": [], "afterStepHookFailure": null, + "afterStepHookMessages": [], "result": { "status": "pass", "stackTrace": "", @@ -83,7 +87,9 @@ } ], "beforeScenarioHookFailure": null, + "beforeScenarioHookMessages": [], "afterScenarioHookFailure": null, + "afterScenarioHookMessages": [], "skipErrors": [], "tableRowIndex": -1 }, @@ -106,7 +112,9 @@ ], "table": null, "beforeStepHookFailure": null, + "beforeStepHookMessages": [], "afterStepHookFailure": null, + "afterStepHookMessages": [], "result": { "status": "pass", "stackTrace": "", @@ -208,7 +216,9 @@ ] }, "beforeStepHookFailure": null, + "beforeStepHookMessages": [], "afterStepHookFailure": null, + "afterStepHookMessages": [], "result": { "status": "pass", "stackTrace": "", @@ -222,7 +232,9 @@ } ], "beforeScenarioHookFailure": null, + "beforeScenarioHookMessages": [], "afterScenarioHookFailure": null, + "afterScenarioHookMessages": [], "skipErrors": [], "tableRowIndex": -1 } @@ -230,14 +242,18 @@ "isTableDriven": false, "datatable": null, "beforeSpecHookFailure": null, + "beforeSpecHookMessages": [], "afterSpecHookFailure": null, + "afterSpecHookMessages": [], "passedScenarioCount": 2, "failedScenarioCount": 0, "skippedScenarioCount": 0 } ], "beforeSuiteHookFailure": null, + "beforeSuiteHookMessages": [], "afterSuiteHookFailure": null, + "afterSuiteHookMessages": [], "passedSpecsCount": 1, "failedSpecsCount": 0, "skippedSpecsCount": 0, diff --git a/generate.go b/generate.go index d078ec0..05d2cb9 100644 --- a/generate.go +++ b/generate.go @@ -32,38 +32,42 @@ type item interface { } type suiteResult struct { - ProjectName string `json:"projectName"` - Timestamp string `json:"timestamp"` - SuccessRate int `json:"successRate"` - Environment string `json:"environment"` - Tags string `json:"tags"` - ExecutionTime int64 `json:"executionTime"` - ExecutionStatus status `json:"executionStatus"` - SpecResults []spec `json:"specResults"` - BeforeSuiteHookFailure *hookFailure `json:"beforeSuiteHookFailure"` - AfterSuiteHookFailure *hookFailure `json:"afterSuiteHookFailure"` - PassedSpecsCount int `json:"passedSpecsCount"` - FailedSpecsCount int `json:"failedSpecsCount"` - SkippedSpecsCount int `json:"skippedSpecsCount"` - PassedScenariosCount int `json:"passedScenariosCount"` - FailedScenariosCount int `json:"failedScenariosCount"` - SkippedScenariosCount int `json:"skippedScenariosCount"` + ProjectName string `json:"projectName"` + Timestamp string `json:"timestamp"` + SuccessRate int `json:"successRate"` + Environment string `json:"environment"` + Tags string `json:"tags"` + ExecutionTime int64 `json:"executionTime"` + ExecutionStatus status `json:"executionStatus"` + SpecResults []spec `json:"specResults"` + BeforeSuiteHookFailure *hookFailure `json:"beforeSuiteHookFailure"` + BeforeSuiteHookMessages []string `json:"beforeSuiteHookMessages"` + AfterSuiteHookFailure *hookFailure `json:"afterSuiteHookFailure"` + AfterSuiteHookMessages []string `json:"afterSuiteHookMessages"` + PassedSpecsCount int `json:"passedSpecsCount"` + FailedSpecsCount int `json:"failedSpecsCount"` + SkippedSpecsCount int `json:"skippedSpecsCount"` + PassedScenariosCount int `json:"passedScenariosCount"` + FailedScenariosCount int `json:"failedScenariosCount"` + SkippedScenariosCount int `json:"skippedScenariosCount"` } type spec struct { - SpecHeading string `json:"specHeading"` - FileName string `json:"fileName"` - Tags []string `json:"tags"` - ExecutionTime int64 `json:"executionTime"` - ExecutionStatus status `json:"executionStatus"` - Scenarios []scenario `json:"scenarios"` - IsTableDriven bool `json:"isTableDriven"` - Datatable *table `json:"datatable"` - BeforeSpecHookFailure *hookFailure `json:"beforeSpecHookFailure"` - AfterSpecHookFailure *hookFailure `json:"afterSpecHookFailure"` - PassedScenarioCount int `json:"passedScenarioCount"` - FailedScenarioCount int `json:"failedScenarioCount"` - SkippedScenarioCount int `json:"skippedScenarioCount"` + SpecHeading string `json:"specHeading"` + FileName string `json:"fileName"` + Tags []string `json:"tags"` + ExecutionTime int64 `json:"executionTime"` + ExecutionStatus status `json:"executionStatus"` + Scenarios []scenario `json:"scenarios"` + IsTableDriven bool `json:"isTableDriven"` + Datatable *table `json:"datatable"` + BeforeSpecHookFailure *hookFailure `json:"beforeSpecHookFailure"` + BeforeSpecHookMessages []string `json:"beforeSpecHookMessages"` + AfterSpecHookFailure *hookFailure `json:"afterSpecHookFailure"` + AfterSpecHookMessages []string `json:"afterSpecHookMessages"` + PassedScenarioCount int `json:"passedScenarioCount"` + FailedScenarioCount int `json:"failedScenarioCount"` + SkippedScenarioCount int `json:"skippedScenarioCount"` } type scenario struct { @@ -145,18 +149,26 @@ type row struct { func toSuiteResult(psr *gauge_messages.ProtoSuiteResult) suiteResult { suiteResult := suiteResult{ - ProjectName: psr.GetProjectName(), - Environment: psr.GetEnvironment(), - Tags: psr.GetTags(), - ExecutionTime: psr.GetExecutionTime(), - PassedSpecsCount: len(psr.GetSpecResults()) - int(psr.GetSpecsFailedCount()) - int(psr.GetSpecsSkippedCount()), - FailedSpecsCount: int(psr.GetSpecsFailedCount()), - SkippedSpecsCount: int(psr.GetSpecsSkippedCount()), - BeforeSuiteHookFailure: toHookFailure(psr.GetPreHookFailure()), - AfterSuiteHookFailure: toHookFailure(psr.GetPostHookFailure()), - SuccessRate: int(psr.GetSuccessRate()), - Timestamp: psr.GetTimestamp(), - ExecutionStatus: pass, + ProjectName: psr.GetProjectName(), + Environment: psr.GetEnvironment(), + Tags: psr.GetTags(), + ExecutionTime: psr.GetExecutionTime(), + PassedSpecsCount: len(psr.GetSpecResults()) - int(psr.GetSpecsFailedCount()) - int(psr.GetSpecsSkippedCount()), + FailedSpecsCount: int(psr.GetSpecsFailedCount()), + SkippedSpecsCount: int(psr.GetSpecsSkippedCount()), + BeforeSuiteHookFailure: toHookFailure(psr.GetPreHookFailure()), + BeforeSuiteHookMessages: make([]string, 0), + AfterSuiteHookFailure: toHookFailure(psr.GetPostHookFailure()), + AfterSuiteHookMessages: make([]string, 0), + SuccessRate: int(psr.GetSuccessRate()), + Timestamp: psr.GetTimestamp(), + ExecutionStatus: pass, + } + if psr.GetPreHookMessages() != nil { + suiteResult.BeforeSuiteHookMessages = psr.GetPreHookMessages() + } + if psr.GetPostHookMessages() != nil { + suiteResult.AfterSuiteHookMessages = psr.GetPostHookMessages() } if psr.GetFailed() { suiteResult.ExecutionStatus = fail @@ -174,17 +186,25 @@ func toSuiteResult(psr *gauge_messages.ProtoSuiteResult) suiteResult { func toSpec(psr *gauge_messages.ProtoSpecResult) spec { spec := spec{ - SpecHeading: psr.GetProtoSpec().GetSpecHeading(), - IsTableDriven: psr.GetProtoSpec().GetIsTableDriven(), - FileName: psr.GetProtoSpec().GetFileName(), - Tags: make([]string, 0), - FailedScenarioCount: int(psr.GetScenarioFailedCount()), - SkippedScenarioCount: int(psr.GetScenarioSkippedCount()), - PassedScenarioCount: int(psr.GetScenarioCount() - psr.GetScenarioFailedCount() - psr.GetScenarioSkippedCount()), - ExecutionTime: psr.GetExecutionTime(), - ExecutionStatus: getStatus(psr.GetFailed(), psr.GetSkipped()), - BeforeSpecHookFailure: toSpecHookFailure(psr.GetProtoSpec().GetPreHookFailures()), - AfterSpecHookFailure: toSpecHookFailure(psr.GetProtoSpec().GetPostHookFailures()), + SpecHeading: psr.GetProtoSpec().GetSpecHeading(), + IsTableDriven: psr.GetProtoSpec().GetIsTableDriven(), + FileName: psr.GetProtoSpec().GetFileName(), + Tags: make([]string, 0), + FailedScenarioCount: int(psr.GetScenarioFailedCount()), + SkippedScenarioCount: int(psr.GetScenarioSkippedCount()), + PassedScenarioCount: int(psr.GetScenarioCount() - psr.GetScenarioFailedCount() - psr.GetScenarioSkippedCount()), + ExecutionTime: psr.GetExecutionTime(), + ExecutionStatus: getStatus(psr.GetFailed(), psr.GetSkipped()), + BeforeSpecHookFailure: toSpecHookFailure(psr.GetProtoSpec().GetPreHookFailures()), + BeforeSpecHookMessages: make([]string, 0), + AfterSpecHookFailure: toSpecHookFailure(psr.GetProtoSpec().GetPostHookFailures()), + AfterSpecHookMessages: make([]string, 0), + } + if psr.GetProtoSpec().GetPreHookMessages() != nil { + spec.BeforeSpecHookMessages = psr.GetProtoSpec().GetPreHookMessages() + } + if psr.GetProtoSpec().GetPostHookMessages() != nil { + spec.AfterSpecHookMessages = psr.GetProtoSpec().GetPostHookMessages() } if psr.GetProtoSpec().GetTags() != nil { spec.Tags = psr.GetProtoSpec().GetTags() diff --git a/schema.json b/schema.json index b483776..fc59f6a 100644 --- a/schema.json +++ b/schema.json @@ -42,10 +42,24 @@ "description": "Before suite hook failure information", "$ref": "#/definitions/hookFailure" }, + "beforeSuiteHookMessages": { + "description": "Custom messages written in before suite hooks", + "type": "array", + "items": { + "type": "string" + } + }, "afterSuiteHookFailure": { "description": "After suite hook failure information", "$ref": "#/definitions/hookFailure" }, + "afterSuiteHookMessages": { + "description": "Custom messages written in after suite hooks", + "type": "array", + "items": { + "type": "string" + } + }, "passedSpecsCount": { "description": "Number of passed specifications", "type": "integer" @@ -81,7 +95,9 @@ "executionStatus", "specResults", "beforeSuiteHookFailure", + "beforeSuiteHookMessages", "afterSuiteHookFailure", + "afterSuiteHookMessages", "passedSpecsCount", "failedSpecsCount", "skippedSpecsCount", @@ -230,10 +246,24 @@ "description": "Before spec hook failure information", "$ref": "#/definitions/hookFailure" }, + "beforeSpecHookMessages": { + "description": "Custom messages written in before spec hooks", + "type": "array", + "items": { + "type": "string" + } + }, "afterSpecHookFailure": { "description": "After spec hook failure information", "$ref": "#/definitions/hookFailure" }, + "afterSpecHookMessages": { + "description": "Custom messages written in after spec hooks", + "type": "array", + "items": { + "type": "string" + } + }, "passedScenarioCount": { "description": "Number of passed scenarios in specification", "type": "integer" @@ -257,7 +287,9 @@ "isTableDriven", "datatable", "beforeSpecHookFailure", + "beforeSpecHookMessages", "afterSpecHookFailure", + "afterSpecHookMessages", "passedScenarioCount", "failedScenarioCount", "skippedScenarioCount"