Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace time.Time.String() with time.Time.Format() #1017

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why comment out and not remove?

)

func TestSenderReceiver_binary_v1(t *testing.T) {
Expand Down Expand Up @@ -101,7 +101,6 @@ func TestSenderReceiver_binary_v1(t *testing.T) {

func TestSenderReceiver_structured_v1(t *testing.T) {
now := time.Now()

testCases := DirectTapTestCases{
"Structured v1.0": {
now: now,
Expand Down Expand Up @@ -131,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"}`, 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.Format(time.RFC3339)),
ContentLength: 182,
},
},
Expand Down Expand Up @@ -177,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.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.Format(time.RFC3339)),
ContentLength: 191,
},
},
Expand Down
5 changes: 3 additions & 2 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 Expand Up @@ -76,7 +77,7 @@ func WriteJson(in *Event, writer io.Writer) error {
if eventContext.Time != nil {
stream.WriteMore()
stream.WriteObjectField("time")
stream.WriteString(eventContext.Time.String())
stream.WriteString(eventContext.Time.Format(time.RFC3339Nano))
}
case *EventContextV1:
// Set a bunch of variables we need later
Expand Down Expand Up @@ -120,7 +121,7 @@ func WriteJson(in *Event, writer io.Writer) error {
if eventContext.Time != nil {
stream.WriteMore()
stream.WriteObjectField("time")
stream.WriteString(eventContext.Time.String())
stream.WriteString(eventContext.Time.Format(time.RFC3339Nano))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using Nano here, and the tests don't?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm remembering correctly, it was because there were some tests that needed more precision than just "seconds".

}
default:
return fmt.Errorf("missing event context")
Expand Down