Skip to content

Commit

Permalink
Modifying tests to check for updated serialization of time
Browse files Browse the repository at this point in the history
Signed-off-by: MaryamTaj <[email protected]>
  • Loading branch information
MaryamTaj committed Mar 21, 2024
1 parent 13958b6 commit d0a560f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions test/integration/http/direct_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"time"

cloudevents "github.com/cloudevents/sdk-go/v2"
"github.com/cloudevents/sdk-go/v2/types"
// "github.com/cloudevents/sdk-go/v2/types"
)

func TestSenderReceiver_binary_v1(t *testing.T) {
Expand Down Expand Up @@ -100,8 +100,9 @@ func TestSenderReceiver_binary_v1(t *testing.T) {
}

func TestSenderReceiver_structured_v1(t *testing.T) {
// TODO: Format that to RFC3339.
now := time.Now()

// TODO: Use now.Truncate or another similar function like .Round to remove the milliseconds.
testCases := DirectTapTestCases{
"Structured v1.0": {
now: now,
Expand All @@ -118,7 +119,7 @@ func TestSenderReceiver_structured_v1(t *testing.T) {
Context: cloudevents.EventContextV1{
ID: "ABC-123",
Type: "unit.test.client.sent",
Time: &cloudevents.Timestamp{Time: now},
Time: &cloudevents.Timestamp{Time: now.Truncate(time.Second)},
Source: *cloudevents.ParseURIRef("/unit/test/client"),
Subject: strptr("resource"),
DataContentType: cloudevents.StringOfApplicationJSON(),
Expand All @@ -131,7 +132,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"}`, types.FormatTime(now.UTC())),
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)),
ContentLength: 182,
},
},
Expand Down Expand Up @@ -164,7 +165,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},
Time: &cloudevents.Timestamp{Time: now.Truncate(time.Second)},
Source: *cloudevents.ParseURIRef("/unit/test/client"),
Subject: strptr("resource"),
DataContentType: cloudevents.StringOfTextPlain(),
Expand All @@ -177,7 +178,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.UTC().Format(time.RFC3339Nano)),
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) ),
ContentLength: 191,
},
},
Expand Down
1 change: 1 addition & 0 deletions v2/event/event_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"io"
"strings"
"time"

jsoniter "github.com/json-iterator/go"
)
Expand Down

0 comments on commit d0a560f

Please sign in to comment.