Skip to content

Commit

Permalink
Default to use CloudEvents v1.0 for encoding. (#297)
Browse files Browse the repository at this point in the history
* Defaulting to V 1.0

Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>

* fix unit tests

Signed-off-by: Scott Nichols <snichols@vmware.com>

Co-authored-by: Matthias Wessendorf <mwessend@redhat.com>
  • Loading branch information
n3wscott and matzew committed Jan 30, 2020
1 parent 6a583ac commit 3673e23
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
6 changes: 3 additions & 3 deletions pkg/binding/example_using_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func Example_using() {
// Output:
// Validation: valid
// Context Attributes,
// specversion: 0.2
// specversion: 1.0
// type: example.com/event
// source: example.com/source
// id: 0
Expand All @@ -108,7 +108,7 @@ func Example_using() {
//
// Validation: valid
// Context Attributes,
// specversion: 0.2
// specversion: 1.0
// type: example.com/event
// source: example.com/source
// id: 1
Expand All @@ -117,7 +117,7 @@ func Example_using() {
//
// Validation: valid
// Context Attributes,
// specversion: 0.2
// specversion: 1.0
// type: example.com/event
// source: example.com/source
// id: 2
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudevents/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Event struct {
}

const (
defaultEventVersion = CloudEventsVersionV02
defaultEventVersion = CloudEventsVersionV1
)

func (e *Event) fieldError(field string, err error) {
Expand Down
27 changes: 22 additions & 5 deletions pkg/cloudevents/event_reader_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,27 @@ func TestEventRW_SpecVersion(t *testing.T) {
testCases := map[string]ReadWriteTest{
"empty v01": {
event: ce.New(),
want: "0.2",
want: "1.0",
set: "0.1",
wantErr: "invalid version",
},
"empty v02": {
event: ce.New(),
want: "0.2",
set: "0.2",
event: ce.New(),
want: "1.0",
set: "0.2",
wantErr: "invalid version",
},
"empty v03": {
event: ce.New(),
want: "0.2",
want: "1.0",
set: "0.3",
wantErr: "invalid version",
},
"empty v1": {
event: ce.New(),
set: "1.0",
want: "1.0",
},
"v01": {
event: ce.New("0.1"),
set: "0.1",
Expand All @@ -51,6 +57,11 @@ func TestEventRW_SpecVersion(t *testing.T) {
set: "0.3",
want: "0.3",
},
"v1": {
event: ce.New("1.0"),
set: "1.0",
want: "1.0",
},
"invalid v01": {
event: ce.New("0.1"),
want: "0.1",
Expand All @@ -69,6 +80,12 @@ func TestEventRW_SpecVersion(t *testing.T) {
set: "1.3",
wantErr: "invalid version",
},
"invalid v1": {
event: ce.New("1.0"),
want: "1.0",
set: "1.3",
wantErr: "invalid version",
},
}
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import (
"github.com/cloudevents/sdk-go"
)

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

testCases := ConversionTestCases{
"Conversion v0.2": {
"Conversion v1.0": {
now: now,
convertFn: UnitTestConvert,
data: map[string]string{"hello": "unittest"},
want: &cloudevents.Event{
Context: cloudevents.EventContextV02{
Context: cloudevents.EventContextV1{
ID: "321-CBA",
Type: "io.cloudevents.conversion.http.post",
Source: *cloudevents.ParseURLRef("github.com/cloudevents/test/http/conversion"),
}.AsV02(),
Source: *cloudevents.ParseURIRef("github.com/cloudevents/test/http/conversion"),
}.AsV1(),
Data: map[string]string{"hello": "unittest"},
},
asSent: &TapValidation{
Expand Down

0 comments on commit 3673e23

Please sign in to comment.