diff --git a/pkg/cloudevents/client/client_test.go b/pkg/cloudevents/client/client_test.go index b8bb3fdd2..1681ee10f 100644 --- a/pkg/cloudevents/client/client_test.go +++ b/pkg/cloudevents/client/client_test.go @@ -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 { diff --git a/pkg/cloudevents/context/context_test.go b/pkg/cloudevents/context/context_test.go index fcc2e502f..397b4b8d3 100644 --- a/pkg/cloudevents/context/context_test.go +++ b/pkg/cloudevents/context/context_test.go @@ -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") @@ -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) - } - }) - } -} diff --git a/pkg/cloudevents/transport/http/context_test.go b/pkg/cloudevents/transport/http/context_test.go new file mode 100644 index 000000000..fdd31a20f --- /dev/null +++ b/pkg/cloudevents/transport/http/context_test.go @@ -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) + } + }) + } +}