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

Zone Record Regions #47

Merged
merged 3 commits into from
Nov 17, 2016
Merged

Zone Record Regions #47

merged 3 commits into from
Nov 17, 2016

Conversation

jodosha
Copy link
Contributor

@jodosha jodosha commented Oct 7, 2016

@weppos @aeden Please review. Thanks!

@jodosha jodosha added the ready-for-review Pull requests that are ready to be reviewed by other team members. label Oct 7, 2016
@jodosha jodosha self-assigned this Oct 7, 2016
@@ -90,28 +93,37 @@ func TestZonesService_CreateRecord(t *testing.T) {
testMethod(t, r, "POST")
testHeaders(t, r)

want := map[string]interface{}{"name": "foo", "content": "192.168.0.10", "type": "A"}
testRequestJSON(t, r, want)
// --- FAIL: TestZonesService_CreateRecord (0.00s)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weppos I declared Region.Name as omitempty, but it still forced as key in the request payload for create/update.

I commented out this assertion because there is something magical ✨ happening here. Can you please check? Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me download and try it locally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jodosha it's a type issue. I was able to reproduce it

➜  dnsimple-go git:(zone-record-regions) go test ./...
--- FAIL: TestZonesService_CreateRecord (0.00s)
    dnsimple_test.go:68: Request parameters = map[type:MX name: content:mxa.example.com regions:[SV1 IAD]], want map[content:mxa.example.com type:MX regions:[SV1 IAD]]
FAIL
FAIL    github.com/dnsimple/dnsimple-go/dnsimple    0.072s
ok      github.com/dnsimple/dnsimple-go/dnsimple/webhook    0.020s

changing the format of the response from %v to %#v revealed the issue

--- FAIL: TestZonesService_CreateRecord (0.00s)
    dnsimple_test.go:68: Request parameters = map[string]interface {}{"type":"MX", "name":"", "content":"mxa.example.com", "regions":[]interface {}{"SV1", "IAD"}}, want map[string]interface {}{"content":"mxa.example.com", "type":"MX", "regions":[]string{"SV1", "IAD"}}
FAIL
FAIL    github.com/dnsimple/dnsimple-go/dnsimple    0.064s
ok      github.com/dnsimple/dnsimple-go/dnsimple/webhook    0.015s

@jodosha jodosha added the enhancement New feature, enhancement or code changes, not related to defects label Oct 7, 2016
@jodosha jodosha mentioned this pull request Oct 7, 2016
3 tasks
ZoneID string `json:"zone_id,omitempty"`
ParentID int `json:"parent_id,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name",omitempty`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jodosha why did you change name to add omitempty?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note the sintax is incorrect, it should be

`json:"name,omitempty"`

not

`json:"name",omitempty`

However, that should not be changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is mandatory for record creation, but not for its update.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, we have no way to specify this different today. It's an open bug #33

Note that if you set omitempty, it will cause more issues as "" is the zero string value in Go, but it's also a valid value for a root domain.

There is no easy solution today, if not switching to pointers. But it will require a larger refactoring.

I also split the region tests from the main test, and copied the same
specs to both create and update.

I prefer to have duplicates tests, than testing different cases in
different methods (e.g. "global" in update and array in created,
because it is very fragile. if we refactor a single endpoint we risk to
lose half the tests).
@weppos
Copy link
Member

weppos commented Oct 13, 2016

@jodosha I've fixed the issue. I'll deal with #33 in a different PR.

@jodosha
Copy link
Contributor Author

jodosha commented Oct 13, 2016

@weppos cool, thank you.

@weppos weppos merged commit 7a9f297 into master Nov 17, 2016
@weppos weppos deleted the zone-record-regions branch December 12, 2016 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, enhancement or code changes, not related to defects ready-for-review Pull requests that are ready to be reviewed by other team members.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants