Skip to content

Commit 217a79c

Browse files
authored
Fix wrong reference for global attachments (#301)
1 parent 62c6ab2 commit 217a79c

File tree

14 files changed

+139
-23
lines changed

14 files changed

+139
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
9+
### Added
10+
- Add `Attachment.testRunHookStartedId` for traceability of attachments to test run hooks ([#301](https://github.com/cucumber/messages/pull/301))
911

1012
### Fixed
1113
- [python] Add a LICENSE file for Python ([#278](https://github.com/cucumber/messages/pull/278))

cpp/include/messages/cucumber/messages/attachment.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct attachment
4242
std::optional<std::string> test_step_id;
4343
std::optional<std::string> url;
4444
std::optional<std::string> test_run_started_id;
45+
std::optional<std::string> test_run_hook_started_id;
4546

4647
std::string to_string() const;
4748

cpp/src/lib/messages/cucumber/messages/attachment.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ attachment::to_string() const
1919
cucumber::messages::to_string(oss, ", test_step_id=", test_step_id);
2020
cucumber::messages::to_string(oss, ", url=", url);
2121
cucumber::messages::to_string(oss, ", test_run_started_id=", test_run_started_id);
22+
cucumber::messages::to_string(oss, ", test_run_hook_started_id=", test_run_hook_started_id);
2223

2324
return oss.str();
2425
}
@@ -35,6 +36,7 @@ attachment::to_json(json& j) const
3536
cucumber::messages::to_json(j, camelize("test_step_id"), test_step_id);
3637
cucumber::messages::to_json(j, camelize("url"), url);
3738
cucumber::messages::to_json(j, camelize("test_run_started_id"), test_run_started_id);
39+
cucumber::messages::to_json(j, camelize("test_run_hook_started_id"), test_run_hook_started_id);
3840
}
3941

4042
std::string

dotnet/Cucumber.Messages/generated/Attachment.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ public sealed class Attachment
5757
*/
5858
public string MediaType { get; private set; }
5959
public Source Source { get; private set; }
60+
/**
61+
* The identifier of the test case attempt if the attachment was created during the execution of a test step
62+
*/
6063
public string TestCaseStartedId { get; private set; }
64+
/**
65+
* The identifier of the test step if the attachment was created during the execution of a test step
66+
*/
6167
public string TestStepId { get; private set; }
6268
/**
6369
* A URL where the attachment can be retrieved. This field should not be set by Cucumber.
@@ -73,7 +79,14 @@ public sealed class Attachment
7379
* separately from reports.
7480
*/
7581
public string Url { get; private set; }
82+
/**
83+
* Not used; implementers should instead populate `testRunHookStartedId` if an attachment was created during the execution of a test run hook
84+
*/
7685
public string TestRunStartedId { get; private set; }
86+
/**
87+
* The identifier of the test run hook execution if the attachment was created during the execution of a test run hook
88+
*/
89+
public string TestRunHookStartedId { get; private set; }
7790

7891

7992
public Attachment(
@@ -85,7 +98,8 @@ public Attachment(
8598
string testCaseStartedId,
8699
string testStepId,
87100
string url,
88-
string testRunStartedId
101+
string testRunStartedId,
102+
string testRunHookStartedId
89103
)
90104
{
91105
RequireNonNull<string>(body, "Body", "Attachment.Body cannot be null");
@@ -100,6 +114,7 @@ string testRunStartedId
100114
this.TestStepId = testStepId;
101115
this.Url = url;
102116
this.TestRunStartedId = testRunStartedId;
117+
this.TestRunHookStartedId = testRunHookStartedId;
103118
}
104119

105120
public override bool Equals(Object o)
@@ -116,7 +131,8 @@ public override bool Equals(Object o)
116131
Object.Equals(TestCaseStartedId, that.TestCaseStartedId) &&
117132
Object.Equals(TestStepId, that.TestStepId) &&
118133
Object.Equals(Url, that.Url) &&
119-
Object.Equals(TestRunStartedId, that.TestRunStartedId);
134+
Object.Equals(TestRunStartedId, that.TestRunStartedId) &&
135+
Object.Equals(TestRunHookStartedId, that.TestRunHookStartedId);
120136
}
121137

122138
public override int GetHashCode()
@@ -139,6 +155,8 @@ public override int GetHashCode()
139155
hash = hash * 31 + Url.GetHashCode();
140156
if (TestRunStartedId != null)
141157
hash = hash * 31 + TestRunStartedId.GetHashCode();
158+
if (TestRunHookStartedId != null)
159+
hash = hash * 31 + TestRunHookStartedId.GetHashCode();
142160
return hash;
143161
}
144162

@@ -154,6 +172,7 @@ public override string ToString()
154172
", testStepId=" + TestStepId +
155173
", url=" + Url +
156174
", testRunStartedId=" + TestRunStartedId +
175+
", testRunHookStartedId=" + TestRunHookStartedId +
157176
'}';
158177
}
159178

go/messages.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package messages
22

33
type Attachment struct {
4-
Body string `json:"body"`
5-
ContentEncoding AttachmentContentEncoding `json:"contentEncoding"`
6-
FileName string `json:"fileName,omitempty"`
7-
MediaType string `json:"mediaType"`
8-
Source *Source `json:"source,omitempty"`
9-
TestCaseStartedId string `json:"testCaseStartedId,omitempty"`
10-
TestStepId string `json:"testStepId,omitempty"`
11-
Url string `json:"url,omitempty"`
12-
TestRunStartedId string `json:"testRunStartedId,omitempty"`
4+
Body string `json:"body"`
5+
ContentEncoding AttachmentContentEncoding `json:"contentEncoding"`
6+
FileName string `json:"fileName,omitempty"`
7+
MediaType string `json:"mediaType"`
8+
Source *Source `json:"source,omitempty"`
9+
TestCaseStartedId string `json:"testCaseStartedId,omitempty"`
10+
TestStepId string `json:"testStepId,omitempty"`
11+
Url string `json:"url,omitempty"`
12+
TestRunStartedId string `json:"testRunStartedId,omitempty"`
13+
TestRunHookStartedId string `json:"testRunHookStartedId,omitempty"`
1314
}
1415

1516
type Duration struct {

java/src/generated/java/io/cucumber/messages/types/Attachment.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public final class Attachment {
3535
private final String testStepId;
3636
private final String url;
3737
private final String testRunStartedId;
38+
private final String testRunHookStartedId;
3839

3940
public Attachment(
4041
String body,
@@ -45,7 +46,8 @@ public Attachment(
4546
String testCaseStartedId,
4647
String testStepId,
4748
String url,
48-
String testRunStartedId
49+
String testRunStartedId,
50+
String testRunHookStartedId
4951
) {
5052
this.body = requireNonNull(body, "Attachment.body cannot be null");
5153
this.contentEncoding = requireNonNull(contentEncoding, "Attachment.contentEncoding cannot be null");
@@ -56,6 +58,7 @@ public Attachment(
5658
this.testStepId = testStepId;
5759
this.url = url;
5860
this.testRunStartedId = testRunStartedId;
61+
this.testRunHookStartedId = testRunHookStartedId;
5962
}
6063

6164
/**
@@ -102,10 +105,16 @@ public Optional<Source> getSource() {
102105
return Optional.ofNullable(source);
103106
}
104107

108+
/**
109+
* The identifier of the test case attempt if the attachment was created during the execution of a test step
110+
*/
105111
public Optional<String> getTestCaseStartedId() {
106112
return Optional.ofNullable(testCaseStartedId);
107113
}
108114

115+
/**
116+
* The identifier of the test step if the attachment was created during the execution of a test step
117+
*/
109118
public Optional<String> getTestStepId() {
110119
return Optional.ofNullable(testStepId);
111120
}
@@ -127,10 +136,20 @@ public Optional<String> getUrl() {
127136
return Optional.ofNullable(url);
128137
}
129138

139+
/**
140+
* Not used; implementers should instead populate `testRunHookStartedId` if an attachment was created during the execution of a test run hook
141+
*/
130142
public Optional<String> getTestRunStartedId() {
131143
return Optional.ofNullable(testRunStartedId);
132144
}
133145

146+
/**
147+
* The identifier of the test run hook execution if the attachment was created during the execution of a test run hook
148+
*/
149+
public Optional<String> getTestRunHookStartedId() {
150+
return Optional.ofNullable(testRunHookStartedId);
151+
}
152+
134153
@Override
135154
public boolean equals(Object o) {
136155
if (this == o) return true;
@@ -145,7 +164,8 @@ public boolean equals(Object o) {
145164
Objects.equals(testCaseStartedId, that.testCaseStartedId) &&
146165
Objects.equals(testStepId, that.testStepId) &&
147166
Objects.equals(url, that.url) &&
148-
Objects.equals(testRunStartedId, that.testRunStartedId);
167+
Objects.equals(testRunStartedId, that.testRunStartedId) &&
168+
Objects.equals(testRunHookStartedId, that.testRunHookStartedId);
149169
}
150170

151171
@Override
@@ -159,7 +179,8 @@ public int hashCode() {
159179
testCaseStartedId,
160180
testStepId,
161181
url,
162-
testRunStartedId
182+
testRunStartedId,
183+
testRunHookStartedId
163184
);
164185
}
165186

@@ -175,6 +196,7 @@ public String toString() {
175196
", testStepId=" + testStepId +
176197
", url=" + url +
177198
", testRunStartedId=" + testRunStartedId +
199+
", testRunHookStartedId=" + testRunHookStartedId +
178200
'}';
179201
}
180202
}

java/src/test/java/io/cucumber/messages/MessagesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class MessagesTest {
1010
@Test
1111
void is_invalid_when_required_fields_are_missing() {
1212
assertThrows(NullPointerException.class, () -> {
13-
new Attachment(null, null, null, null, null, null, null, null, null);
13+
new Attachment(null, null, null, null, null, null, null, null, null, null);
1414
}, "Attachment.body cannot be null");
1515
}
1616

javascript/src/messages.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export class Attachment {
2121
url?: string
2222

2323
testRunStartedId?: string
24+
25+
testRunHookStartedId?: string
2426
}
2527

2628
export class Duration {

jsonschema/Attachment.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,24 @@
3333
"$ref": "./Source.json"
3434
},
3535
"testCaseStartedId": {
36+
"description": "The identifier of the test case attempt if the attachment was created during the execution of a test step",
3637
"type": "string"
3738
},
3839
"testStepId": {
40+
"description": "The identifier of the test step if the attachment was created during the execution of a test step",
3941
"type": "string"
4042
},
4143
"url": {
4244
"description": "*\n A URL where the attachment can be retrieved. This field should not be set by Cucumber.\n It should be set by a program that reads a message stream and does the following for\n each Attachment message:\n\n - Writes the body (after base64 decoding if necessary) to a new file.\n - Sets `body` and `contentEncoding` to `null`\n - Writes out the new attachment message\n\n This will result in a smaller message stream, which can improve performance and\n reduce bandwidth of message consumers. It also makes it easier to process and download attachments\n separately from reports.",
4345
"type": "string"
4446
},
4547
"testRunStartedId": {
48+
"description": "Not used; implementers should instead populate `testRunHookStartedId` if an attachment was created during the execution of a test run hook",
49+
"type": "string",
50+
"deprecated": true
51+
},
52+
"testRunHookStartedId": {
53+
"description": "The identifier of the test run hook execution if the attachment was created during the execution of a test run hook",
4654
"type": "string"
4755
}
4856
},

messages.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ will only have one of its fields set, which indicates the payload of the message
1616
| `testStepId` | string | no | |
1717
| `url` | string | no | |
1818
| `testRunStartedId` | string | no | |
19+
| `testRunHookStartedId` | string | no | |
1920

2021
## Duration
2122

0 commit comments

Comments
 (0)