-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional code review observations on Attach() functionality from #623…
… (#628) * support multiple calls to the Attach() function from a single step * run_progress_test.go changed so it's not sensitive to the name of the clone target directory * applied code review comments also added _example/attachments * applied code review comments also added _example/attachments * applied code review comments also added _example/attachments
- Loading branch information
Showing
13 changed files
with
177 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# An example of Making attachments to the reports | ||
|
||
The JSON (and in future NDJSON) report formats allow the inclusion of data attachments. | ||
|
||
These attachments could be console logs or file data or images for instance. | ||
|
||
The example in this directory shows how the godog API is used to add attachments to the JSON report. | ||
|
||
|
||
## Run the example | ||
|
||
You must use the '-v' flag or you will not see the cucumber JSON output. | ||
|
||
go test -v atttachment_test.go | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package attachments_test | ||
|
||
// This example shows how to set up test suite runner with Go subtests and godog command line parameters. | ||
// Sample commands: | ||
// * run all scenarios from default directory (features): go test -test.run "^TestFeatures/" | ||
// * run all scenarios and list subtest names: go test -test.v -test.run "^TestFeatures/" | ||
// * run all scenarios from one feature file: go test -test.v -godog.paths features/nodogs.feature -test.run "^TestFeatures/" | ||
// * run all scenarios from multiple feature files: go test -test.v -godog.paths features/nodogs.feature,features/godogs.feature -test.run "^TestFeatures/" | ||
// * run single scenario as a subtest: go test -test.v -test.run "^TestFeatures/Eat_5_out_of_12$" | ||
// * show usage help: go test -godog.help | ||
// * show usage help if there were other test files in directory: go test -godog.help godogs_test.go | ||
// * run scenarios with multiple formatters: go test -test.v -godog.format cucumber:cuc.json,pretty -test.run "^TestFeatures/" | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/cucumber/godog" | ||
"github.com/cucumber/godog/colors" | ||
) | ||
|
||
var opts = godog.Options{ | ||
Output: colors.Colored(os.Stdout), | ||
Format: "cucumber", // cucumber json format | ||
} | ||
|
||
func TestFeatures(t *testing.T) { | ||
o := opts | ||
o.TestingT = t | ||
|
||
status := godog.TestSuite{ | ||
Name: "attachments", | ||
Options: &o, | ||
ScenarioInitializer: InitializeScenario, | ||
}.Run() | ||
|
||
if status == 2 { | ||
t.SkipNow() | ||
} | ||
|
||
if status != 0 { | ||
t.Fatalf("zero status code expected, %d received", status) | ||
} | ||
} | ||
|
||
func InitializeScenario(ctx *godog.ScenarioContext) { | ||
|
||
ctx.Step(`^I have attached two documents in sequence$`, func(ctx context.Context) (context.Context, error) { | ||
// the attached bytes will be base64 encoded by the framework and placed in the embeddings section of the cuke report | ||
ctx = godog.Attach(ctx, | ||
godog.Attachment{Body: []byte("TheData1"), FileName: "Data Attachment", MediaType: "text/plain"}, | ||
) | ||
ctx = godog.Attach(ctx, | ||
godog.Attachment{Body: []byte("{ \"a\" : 1 }"), FileName: "Json Attachment", MediaType: "application/json"}, | ||
) | ||
|
||
return ctx, nil | ||
}) | ||
ctx.Step(`^I have attached two documents at once$`, func(ctx context.Context) (context.Context, error) { | ||
ctx = godog.Attach(ctx, | ||
godog.Attachment{Body: []byte("TheData1"), FileName: "Data Attachment 1", MediaType: "text/plain"}, | ||
godog.Attachment{Body: []byte("TheData2"), FileName: "Data Attachment 2", MediaType: "text/plain"}, | ||
) | ||
|
||
return ctx, nil | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Feature: Attaching content to the cucumber report | ||
The cucumber JSON and NDJSON support the inclusion of attachments. | ||
These can be text or images or any data really. | ||
|
||
Scenario: Attaching files to the report | ||
Given I have attached two documents in sequence | ||
And I have attached two documents at once |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
internal/formatters/formatter-tests/events/scenario_with_attachment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
{"event":"TestRunStarted","version":"0.1.0","timestamp":-6795364578871,"suite":"events"} | ||
{"event":"TestSource","location":"formatter-tests/features/scenario_with_attachment.feature:1","source":"Feature: scenario with attachment\n describes\n an attachment\n feature\n\n Scenario: step with attachment\n Given a step with attachment\n"} | ||
{"event":"TestSource","location":"formatter-tests/features/scenario_with_attachment.feature:1","source":"Feature: scenario with attachment\n describes\n an attachment\n feature\n\n Scenario: step with attachment\n Given a step with a single attachment call for multiple attachments\n And a step with multiple attachment calls\n"} | ||
{"event":"TestCaseStarted","location":"formatter-tests/features/scenario_with_attachment.feature:6","timestamp":-6795364578871} | ||
{"event":"StepDefinitionFound","location":"formatter-tests/features/scenario_with_attachment.feature:7","definition_id":"fmt_output_test.go:XXX -\u003e github.com/cucumber/godog/internal/formatters_test.stepWithAttachment","arguments":[]} | ||
{"event":"StepDefinitionFound","location":"formatter-tests/features/scenario_with_attachment.feature:7","definition_id":"fmt_output_test.go:XXX -\u003e github.com/cucumber/godog/internal/formatters_test.stepWithSingleAttachmentCall","arguments":[]} | ||
{"event":"TestStepStarted","location":"formatter-tests/features/scenario_with_attachment.feature:7","timestamp":-6795364578871} | ||
{"event":"Attachment","location":"formatter-tests/features/scenario_with_attachment.feature:7","timestamp":-6795364578871,"contentEncoding":"BASE64","fileName":"TheFilename1","mimeType":"text/plain","body":"TheData1"} | ||
{"event":"Attachment","location":"formatter-tests/features/scenario_with_attachment.feature:7","timestamp":-6795364578871,"contentEncoding":"BASE64","fileName":"TheFilename2","mimeType":"text/plain","body":"TheData2"} | ||
{"event":"TestStepFinished","location":"formatter-tests/features/scenario_with_attachment.feature:7","timestamp":-6795364578871,"status":"passed"} | ||
{"event":"StepDefinitionFound","location":"formatter-tests/features/scenario_with_attachment.feature:8","definition_id":"fmt_output_test.go:XXX -\u003e github.com/cucumber/godog/internal/formatters_test.stepWithMultipleAttachmentCalls","arguments":[]} | ||
{"event":"TestStepStarted","location":"formatter-tests/features/scenario_with_attachment.feature:8","timestamp":-6795364578871} | ||
{"event":"Attachment","location":"formatter-tests/features/scenario_with_attachment.feature:8","timestamp":-6795364578871,"contentEncoding":"BASE64","fileName":"TheFilename1","mimeType":"text/plain","body":"TheData1"} | ||
{"event":"Attachment","location":"formatter-tests/features/scenario_with_attachment.feature:8","timestamp":-6795364578871,"contentEncoding":"BASE64","fileName":"TheFilename2","mimeType":"text/plain","body":"TheData2"} | ||
{"event":"TestStepFinished","location":"formatter-tests/features/scenario_with_attachment.feature:8","timestamp":-6795364578871,"status":"passed"} | ||
{"event":"TestCaseFinished","location":"formatter-tests/features/scenario_with_attachment.feature:6","timestamp":-6795364578871,"status":"passed"} | ||
{"event":"TestRunFinished","status":"passed","timestamp":-6795364578871,"snippets":"","memory":""} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters