Skip to content

Commit

Permalink
Fix a bad merge. (#72)
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Nichols <nicholss@google.com>
  • Loading branch information
n3wscott authored and markpeek committed Mar 12, 2019
1 parent c8b1fd4 commit c1a6fb0
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 43 deletions.
1 change: 1 addition & 0 deletions pkg/cloudevents/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ func TestClientReceive(t *testing.T) {
if !strings.Contains(got, want) {
t.Fatalf("failed to return expected error, got %q, want %q", err, want)
}
cancel()
return
} else {
if err != nil {
Expand Down
43 changes: 0 additions & 43 deletions pkg/cloudevents/context/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (
"testing"
)

func TestContext(t *testing.T) {
// TODO: add a test. This makes coverage count this dir.
}

func TestTargetContext(t *testing.T) {
exampleDotCom, _ := url.Parse("http://example.com")

Expand Down Expand Up @@ -53,42 +49,3 @@ func TestTargetContext(t *testing.T) {
})
}
}

func TestTransportContext(t *testing.T) {
testCases := map[string]struct {
transport interface{}
ctx context.Context
want interface{}
}{
"nil context": {},
"nil context, set transport context": {
transport: map[string]string{"hi": "unit test"},
want: map[string]string{"hi": "unit test"},
},
"todo context, set transport context": {
ctx: context.TODO(),
transport: map[string]string{"hi": "unit test"},
want: map[string]string{"hi": "unit test"},
},
"bad transport context": {
ctx: context.TODO(),
},
"already set transport context": {
ctx: cecontext.WithTransportContext(context.TODO(), map[string]string{"bye": "unit test"}),
transport: map[string]string{"hi": "unit test"},
want: map[string]string{"hi": "unit test"},
},
}
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {

ctx := cecontext.WithTransportContext(tc.ctx, tc.transport)

got := cecontext.TransportContextFrom(ctx)

if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("unexpected (-want, +got) = %v", diff)
}
})
}
}
69 changes: 69 additions & 0 deletions pkg/cloudevents/transport/http/context_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package http_test

import (
"context"
"github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http"
"github.com/google/go-cmp/cmp"
"testing"
)

func TestTransportContext(t *testing.T) {
testCases := map[string]struct {
t http.TransportContext
ctx context.Context
want http.TransportContext
}{
"nil context": {},
"nil context, set transport context": {
t: http.TransportContext{
Host: "unit test",
Method: "unit test",
},
want: http.TransportContext{
Host: "unit test",
Method: "unit test",
},
},
"todo context, set transport context": {
ctx: context.TODO(),
t: http.TransportContext{
Host: "unit test",
Method: "unit test",
},
want: http.TransportContext{
Host: "unit test",
Method: "unit test",
},
},
"bad transport context": {
ctx: context.TODO(),
},
"already set transport context": {
ctx: http.WithTransportContext(context.TODO(),
http.TransportContext{
Host: "existing test",
Method: "exiting test",
}),
t: http.TransportContext{
Host: "unit test",
Method: "unit test",
},
want: http.TransportContext{
Host: "unit test",
Method: "unit test",
},
},
}
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {

ctx := http.WithTransportContext(tc.ctx, tc.t)

got := http.TransportContextFrom(ctx)

if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("unexpected (-want, +got) = %v", diff)
}
})
}
}

0 comments on commit c1a6fb0

Please sign in to comment.