ns1 / ns1-go

Golang API client for NS1
Apache License 2.0
34 stars 59 forks source link

INBOX-2702: Fixes #224 by omitting empty tags #231

Closed fformica closed 7 months ago

fformica commented 7 months ago

This PR sets tags and blocked_tags as omitempty, which fixes the issue in #224 on the client side: however, this has a side effect of not allowing to empty out existing tags in an update, because an empty array is omitted just like null is.

fformica commented 7 months ago

I tested with the following (on prod0) that we can now update tags independently:

    client.Records.Delete("fformica.com", "my.test.a.fformica.com", "A")

    record := dns.NewRecord("fformica.com", "my.test.a.fformica.com", "A", map[string]string{"one": "two"}, nil)
    resp, err := client.Records.Create(record)
    require.NoError(t, err)
    require.Equal(t, 200, resp.StatusCode)

    record, resp, err = client.Records.Get("fformica.com", "my.test.a.fformica.com", "A")
    require.NoError(t, err)
    require.Equal(t, 200, resp.StatusCode)
    require.Equal(t, map[string]string{"one": "two"}, record.Tags)

    record.Tags = map[string]string{"three": "four"}
    resp, err = client.Records.Update(record)
    require.NoError(t, err)
    require.Equal(t, 200, resp.StatusCode)

    record, resp, err = client.Records.Get("fformica.com", "my.test.a.fformica.com", "A")
    require.NoError(t, err)
    require.Equal(t, 200, resp.StatusCode)
    require.Equal(t, map[string]string{"three": "four"}, record.Tags)