Skip to content

Commit 843ce7b

Browse files
authored
Add timestamp to Attachment (#305)
Fixes #304. > During test and step executions the execution might produce multiple attachments. For longer steps the exact timing of when the attachments were captured might be important. Currently the Attachment envelop[e] type does not have a timestamp and therefore this information cannot be captured and used. It makes sense to do this now because we already have the signature change for Attachment in #301 which isn't released yet.
1 parent 78ce1d3 commit 843ce7b

File tree

15 files changed

+83
-9
lines changed

15 files changed

+83
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased]
99
### Added
1010
- Add `Attachment.testRunHookStartedId` for traceability of attachments to test run hooks ([#301](https://github.com/cucumber/messages/pull/301))
11+
- Add `Attachment.timestamp` ([#305](https://github.com/cucumber/messages/pull/305))
1112

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

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# The order is significant - ajv needs referenced schemas to be preceded by referencing schemas
22
schemas = \
33
./jsonschema/Source.json \
4-
./jsonschema/Attachment.json \
54
./jsonschema/Location.json \
65
./jsonschema/Exception.json \
76
./jsonschema/SourceReference.json \
@@ -14,6 +13,7 @@ schemas = \
1413
./jsonschema/StepDefinition.json \
1514
./jsonschema/TestCase.json \
1615
./jsonschema/Timestamp.json \
16+
./jsonschema/Attachment.json \
1717
./jsonschema/TestCaseFinished.json \
1818
./jsonschema/TestCaseStarted.json \
1919
./jsonschema/TestRunFinished.json \

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <cucumber/messages/attachment_content_encoding.hpp>
1010
#include <cucumber/messages/source.hpp>
11+
#include <cucumber/messages/timestamp.hpp>
1112

1213
namespace cucumber::messages {
1314

@@ -43,6 +44,7 @@ struct attachment
4344
std::optional<std::string> url;
4445
std::optional<std::string> test_run_started_id;
4546
std::optional<std::string> test_run_hook_started_id;
47+
std::optional<cucumber::messages::timestamp> timestamp;
4648

4749
std::string to_string() const;
4850

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ attachment::to_string() const
2020
cucumber::messages::to_string(oss, ", url=", url);
2121
cucumber::messages::to_string(oss, ", test_run_started_id=", test_run_started_id);
2222
cucumber::messages::to_string(oss, ", test_run_hook_started_id=", test_run_hook_started_id);
23+
cucumber::messages::to_string(oss, ", timestamp=", timestamp);
2324

2425
return oss.str();
2526
}
@@ -37,6 +38,7 @@ attachment::to_json(json& j) const
3738
cucumber::messages::to_json(j, camelize("url"), url);
3839
cucumber::messages::to_json(j, camelize("test_run_started_id"), test_run_started_id);
3940
cucumber::messages::to_json(j, camelize("test_run_hook_started_id"), test_run_hook_started_id);
41+
cucumber::messages::to_json(j, camelize("timestamp"), timestamp);
4042
}
4143

4244
std::string

dotnet/Cucumber.Messages/generated/Attachment.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public sealed class Attachment
8787
* The identifier of the test run hook execution if the attachment was created during the execution of a test run hook
8888
*/
8989
public string TestRunHookStartedId { get; private set; }
90+
/**
91+
* When the attachment was created
92+
*/
93+
public Timestamp Timestamp { get; private set; }
9094

9195

9296
public Attachment(
@@ -99,7 +103,8 @@ public Attachment(
99103
string testStepId,
100104
string url,
101105
string testRunStartedId,
102-
string testRunHookStartedId
106+
string testRunHookStartedId,
107+
Timestamp timestamp
103108
)
104109
{
105110
RequireNonNull<string>(body, "Body", "Attachment.Body cannot be null");
@@ -115,6 +120,7 @@ string testRunHookStartedId
115120
this.Url = url;
116121
this.TestRunStartedId = testRunStartedId;
117122
this.TestRunHookStartedId = testRunHookStartedId;
123+
this.Timestamp = timestamp;
118124
}
119125

120126
public override bool Equals(Object o)
@@ -132,7 +138,8 @@ public override bool Equals(Object o)
132138
Object.Equals(TestStepId, that.TestStepId) &&
133139
Object.Equals(Url, that.Url) &&
134140
Object.Equals(TestRunStartedId, that.TestRunStartedId) &&
135-
Object.Equals(TestRunHookStartedId, that.TestRunHookStartedId);
141+
Object.Equals(TestRunHookStartedId, that.TestRunHookStartedId) &&
142+
Object.Equals(Timestamp, that.Timestamp);
136143
}
137144

138145
public override int GetHashCode()
@@ -157,6 +164,8 @@ public override int GetHashCode()
157164
hash = hash * 31 + TestRunStartedId.GetHashCode();
158165
if (TestRunHookStartedId != null)
159166
hash = hash * 31 + TestRunHookStartedId.GetHashCode();
167+
if (Timestamp != null)
168+
hash = hash * 31 + Timestamp.GetHashCode();
160169
return hash;
161170
}
162171

@@ -173,6 +182,7 @@ public override string ToString()
173182
", url=" + Url +
174183
", testRunStartedId=" + TestRunStartedId +
175184
", testRunHookStartedId=" + TestRunHookStartedId +
185+
", timestamp=" + Timestamp +
176186
'}';
177187
}
178188

go/messages.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Attachment struct {
1111
Url string `json:"url,omitempty"`
1212
TestRunStartedId string `json:"testRunStartedId,omitempty"`
1313
TestRunHookStartedId string `json:"testRunHookStartedId,omitempty"`
14+
Timestamp *Timestamp `json:"timestamp,omitempty"`
1415
}
1516

1617
type Duration struct {

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public final class Attachment {
3636
private final String url;
3737
private final String testRunStartedId;
3838
private final String testRunHookStartedId;
39+
private final Timestamp timestamp;
3940

4041
public Attachment(
4142
String body,
@@ -47,7 +48,8 @@ public Attachment(
4748
String testStepId,
4849
String url,
4950
String testRunStartedId,
50-
String testRunHookStartedId
51+
String testRunHookStartedId,
52+
Timestamp timestamp
5153
) {
5254
this.body = requireNonNull(body, "Attachment.body cannot be null");
5355
this.contentEncoding = requireNonNull(contentEncoding, "Attachment.contentEncoding cannot be null");
@@ -59,6 +61,7 @@ public Attachment(
5961
this.url = url;
6062
this.testRunStartedId = testRunStartedId;
6163
this.testRunHookStartedId = testRunHookStartedId;
64+
this.timestamp = timestamp;
6265
}
6366

6467
/**
@@ -150,6 +153,13 @@ public Optional<String> getTestRunHookStartedId() {
150153
return Optional.ofNullable(testRunHookStartedId);
151154
}
152155

156+
/**
157+
* When the attachment was created
158+
*/
159+
public Optional<Timestamp> getTimestamp() {
160+
return Optional.ofNullable(timestamp);
161+
}
162+
153163
@Override
154164
public boolean equals(Object o) {
155165
if (this == o) return true;
@@ -165,7 +175,8 @@ public boolean equals(Object o) {
165175
Objects.equals(testStepId, that.testStepId) &&
166176
Objects.equals(url, that.url) &&
167177
Objects.equals(testRunStartedId, that.testRunStartedId) &&
168-
Objects.equals(testRunHookStartedId, that.testRunHookStartedId);
178+
Objects.equals(testRunHookStartedId, that.testRunHookStartedId) &&
179+
Objects.equals(timestamp, that.timestamp);
169180
}
170181

171182
@Override
@@ -180,7 +191,8 @@ public int hashCode() {
180191
testStepId,
181192
url,
182193
testRunStartedId,
183-
testRunHookStartedId
194+
testRunHookStartedId,
195+
timestamp
184196
);
185197
}
186198

@@ -197,6 +209,7 @@ public String toString() {
197209
", url=" + url +
198210
", testRunStartedId=" + testRunStartedId +
199211
", testRunHookStartedId=" + testRunHookStartedId +
212+
", timestamp=" + timestamp +
200213
'}';
201214
}
202215
}

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, null);
13+
new Attachment(null, null, null, null, null, null, null, null, null, null, null);
1414
}, "Attachment.body cannot be null");
1515
}
1616

javascript/src/messages.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export class Attachment {
2323
testRunStartedId?: string
2424

2525
testRunHookStartedId?: string
26+
27+
@Type(() => Timestamp)
28+
timestamp?: Timestamp
2629
}
2730

2831
export class Duration {

jsonschema/Attachment.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
"testRunHookStartedId": {
5353
"description": "The identifier of the test run hook execution if the attachment was created during the execution of a test run hook",
5454
"type": "string"
55+
},
56+
"timestamp": {
57+
"description": "When the attachment was created",
58+
"$ref": "./Timestamp.json"
5559
}
5660
},
5761
"type": "object"

0 commit comments

Comments
 (0)