Skip to content

Commit d0a560f

Browse files
committed
Modifying tests to check for updated serialization of time
Signed-off-by: MaryamTaj <[email protected]>
1 parent 13958b6 commit d0a560f

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

test/integration/http/direct_v1_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"time"
1414

1515
cloudevents "github.com/cloudevents/sdk-go/v2"
16-
"github.com/cloudevents/sdk-go/v2/types"
16+
// "github.com/cloudevents/sdk-go/v2/types"
1717
)
1818

1919
func TestSenderReceiver_binary_v1(t *testing.T) {
@@ -100,8 +100,9 @@ func TestSenderReceiver_binary_v1(t *testing.T) {
100100
}
101101

102102
func TestSenderReceiver_structured_v1(t *testing.T) {
103+
// TODO: Format that to RFC3339.
103104
now := time.Now()
104-
105+
// TODO: Use now.Truncate or another similar function like .Round to remove the milliseconds.
105106
testCases := DirectTapTestCases{
106107
"Structured v1.0": {
107108
now: now,
@@ -118,7 +119,7 @@ func TestSenderReceiver_structured_v1(t *testing.T) {
118119
Context: cloudevents.EventContextV1{
119120
ID: "ABC-123",
120121
Type: "unit.test.client.sent",
121-
Time: &cloudevents.Timestamp{Time: now},
122+
Time: &cloudevents.Timestamp{Time: now.Truncate(time.Second)},
122123
Source: *cloudevents.ParseURIRef("/unit/test/client"),
123124
Subject: strptr("resource"),
124125
DataContentType: cloudevents.StringOfApplicationJSON(),
@@ -131,7 +132,7 @@ func TestSenderReceiver_structured_v1(t *testing.T) {
131132
Header: map[string][]string{
132133
"content-type": {"application/cloudevents+json"},
133134
},
134-
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"}`, types.FormatTime(now.UTC())),
135+
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)),
135136
ContentLength: 182,
136137
},
137138
},
@@ -164,7 +165,7 @@ func TestSenderReceiver_data_base64_v1(t *testing.T) {
164165
Context: cloudevents.EventContextV1{
165166
ID: "ABC-123",
166167
Type: "unit.test.client.sent",
167-
Time: &cloudevents.Timestamp{Time: now},
168+
Time: &cloudevents.Timestamp{Time: now.Truncate(time.Second)},
168169
Source: *cloudevents.ParseURIRef("/unit/test/client"),
169170
Subject: strptr("resource"),
170171
DataContentType: cloudevents.StringOfTextPlain(),
@@ -177,7 +178,7 @@ func TestSenderReceiver_data_base64_v1(t *testing.T) {
177178
Header: map[string][]string{
178179
"content-type": {"application/cloudevents+json"},
179180
},
180-
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.UTC().Format(time.RFC3339Nano)),
181+
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) ),
181182
ContentLength: 191,
182183
},
183184
},

v2/event/event_marshal.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"io"
1313
"strings"
14+
"time"
1415

1516
jsoniter "github.com/json-iterator/go"
1617
)

0 commit comments

Comments
 (0)