diff --git a/go/endpoint_test.go b/go/endpoint_test.go index 294dc3c0a..4081df851 100644 --- a/go/endpoint_test.go +++ b/go/endpoint_test.go @@ -7,7 +7,7 @@ import ( "testing" ) -func TestEndpoint_Serialization(t *testing.T) { +func TestEndpointIn_Serialization(t *testing.T) { testCases := []struct { name string testEndpoint *svix.EndpointIn @@ -74,3 +74,43 @@ func TestEndpoint_Serialization(t *testing.T) { } } } + +func TestEndpointPatch_Serialization(t *testing.T) { + testCases := []struct { + name string + testEndpoint *svix.EndpointPatch + wantChannels bool + wantFilterTypes bool + }{ + { + name: "explicitly setting channels to null", + testEndpoint: &svix.EndpointPatch{ + Channels: nil, + }, + wantChannels: true, + wantFilterTypes: false, + }, + } + + for _, tc := range testCases { + b, _ := json.Marshal(tc.testEndpoint) + s := string(b) + + gotChannels := strings.Contains(s, "channels") + gotFilterTypes := strings.Contains(s, "filterTypes") + + if tc.wantChannels && !gotChannels { + t.Errorf("case `%s`: expected EndpointPatch to have a channels field", tc.name) + } + if !tc.wantChannels && gotChannels { + t.Errorf("case `%s`: expected EndpointPatch to NOT have a channels field", tc.name) + } + + if tc.wantFilterTypes && !gotFilterTypes { + t.Errorf("case `%s`: expected EndpointPatch to have a filterTypes field", tc.name) + } + if !tc.wantFilterTypes && gotFilterTypes { + t.Errorf("case `%s`: expected EndpointPatch to NOT have a filterTypes field", tc.name) + } + } +} diff --git a/go/svix_test.go b/go/svix_test.go index 8bef5415e..3c0c34f4e 100644 --- a/go/svix_test.go +++ b/go/svix_test.go @@ -74,12 +74,19 @@ func TestKitchenSink(t *testing.T) { } endp, err := client.Endpoint.Create(ctx, app.Id, &svix.EndpointIn{ - Url: "https://example.svix.com/", + Url: "https://example.svix.com/", + Channels: []string{"ch0", "ch1"}, }) if err != nil { t.Fatal(err) } + if len(endp.GetChannels()) != 2 { + t.Errorf("got %d channels, want 2", len(endp.Channels)) + } + if len(endp.GetFilterTypes()) != 0 { + t.Errorf("got %d filter types, want 0", len(endp.GetFilterTypes())) + } endpPatch := svix.EndpointPatch{} endpPatch.SetFilterTypes([]string{"event.started", "event.ended"}) @@ -93,4 +100,20 @@ func TestKitchenSink(t *testing.T) { t.Fatalf("unexpected filter type: `%s`", typ) } } + + endpPatch2 := svix.EndpointPatch{ + Channels: nil, + } + patched2, err := client.Endpoint.Patch(ctx, app.Id, endp.Id, &endpPatch2) + if err != nil { + t.Fatal(err) + } + if len(patched2.Channels) > 0 { + t.Fatalf("expected patched channels to be empty: %v", patched2.Channels) + } + + err = client.Endpoint.Delete(ctx, app.Id, endp.Id) + if err != nil { + t.Fatalf("unexpected error on delete: %s", err.Error()) + } }