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

Libs(Go): unestting nullable array fields via PATCH request #1496

Draft
wants to merge 1 commit 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
42 changes: 41 additions & 1 deletion go/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
25 changes: 24 additions & 1 deletion go/svix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})

Expand All @@ -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())
}
}
Loading