Skip to content

Commit

Permalink
don't truncate to seconds
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Davis <duglin@gmail.com>
  • Loading branch information
duglin committed Oct 23, 2024
1 parent b39d268 commit fcc4f16
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions test/integration/http/direct_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestSenderReceiver_structured_v1(t *testing.T) {
Context: cloudevents.EventContextV1{
ID: "ABC-123",
Type: "unit.test.client.sent",
Time: &cloudevents.Timestamp{Time: now.Truncate(time.Second)},
Time: &cloudevents.Timestamp{Time: now},
Source: *cloudevents.ParseURIRef("/unit/test/client"),
Subject: strptr("resource"),
DataContentType: cloudevents.StringOfApplicationJSON(),
Expand All @@ -130,7 +130,7 @@ func TestSenderReceiver_structured_v1(t *testing.T) {
Header: map[string][]string{
"content-type": {"application/cloudevents+json"},
},
Body: fmt.Sprintf(`{"data":{"hello":"unittest"},"id":"ABC-123","source":"/unit/test/client","specversion":"1.0","subject":"resource","time":%q,"type":"unit.test.client.sent"}`, now.Truncate(time.Second).Format(time.RFC3339)),
Body: fmt.Sprintf(`{"data":{"hello":"unittest"},"id":"ABC-123","source":"/unit/test/client","specversion":"1.0","subject":"resource","time":%q,"type":"unit.test.client.sent"}`, now.Format(time.RFC3339)),
ContentLength: 182,
},
},
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestSenderReceiver_data_base64_v1(t *testing.T) {
Context: cloudevents.EventContextV1{
ID: "ABC-123",
Type: "unit.test.client.sent",
Time: &cloudevents.Timestamp{Time: now.Truncate(time.Second)},
Time: &cloudevents.Timestamp{Time: now},
Source: *cloudevents.ParseURIRef("/unit/test/client"),
Subject: strptr("resource"),
DataContentType: cloudevents.StringOfTextPlain(),
Expand All @@ -176,7 +176,7 @@ func TestSenderReceiver_data_base64_v1(t *testing.T) {
Header: map[string][]string{
"content-type": {"application/cloudevents+json"},
},
Body: fmt.Sprintf(`{"data_base64":"aGVsbG86IHVuaXR0ZXN0","id":"ABC-123","source":"/unit/test/client","specversion":"1.0","subject":"resource","time":%q,"type":"unit.test.client.sent"}`, now.Truncate(time.Second).Format(time.RFC3339)),
Body: fmt.Sprintf(`{"data_base64":"aGVsbG86IHVuaXR0ZXN0","id":"ABC-123","source":"/unit/test/client","specversion":"1.0","subject":"resource","time":%q,"type":"unit.test.client.sent"}`, now.Format(time.RFC3339)),
ContentLength: 191,
},
},
Expand Down
4 changes: 2 additions & 2 deletions v2/event/event_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func WriteJson(in *Event, writer io.Writer) error {
if eventContext.Time != nil {
stream.WriteMore()
stream.WriteObjectField("time")
stream.WriteString(eventContext.Time.Format(time.RFC3339))
stream.WriteString(eventContext.Time.Format(time.RFC3339Nano))
}
case *EventContextV1:
// Set a bunch of variables we need later
Expand Down Expand Up @@ -121,7 +121,7 @@ func WriteJson(in *Event, writer io.Writer) error {
if eventContext.Time != nil {
stream.WriteMore()
stream.WriteObjectField("time")
stream.WriteString(eventContext.Time.Format(time.RFC3339))
stream.WriteString(eventContext.Time.Format(time.RFC3339Nano))
}
default:
return fmt.Errorf("missing event context")
Expand Down

0 comments on commit fcc4f16

Please sign in to comment.