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

fix: do not send primary IPs ID opts to the API (#552) #554

Merged
merged 1 commit into from
Nov 11, 2024
Merged
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
6 changes: 3 additions & 3 deletions hcloud/primary_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type PrimaryIPUpdateOpts struct {
// PrimaryIPAssignOpts defines the request to
// assign a Primary IP to an assignee (usually a server).
type PrimaryIPAssignOpts struct {
ID int
ID int `json:"-"`
AssigneeID int `json:"assignee_id"`
AssigneeType string `json:"assignee_type"`
}
Expand All @@ -133,7 +133,7 @@ type PrimaryIPAssignResult struct {
// PrimaryIPChangeDNSPtrOpts defines the request to
// change a DNS PTR entry from a Primary IP.
type PrimaryIPChangeDNSPtrOpts struct {
ID int
ID int `json:"-"`
DNSPtr string `json:"dns_ptr"`
IP string `json:"ip"`
}
Expand All @@ -147,7 +147,7 @@ type PrimaryIPChangeDNSPtrResult struct {
// PrimaryIPChangeProtectionOpts defines the request to
// change protection configuration of a Primary IP.
type PrimaryIPChangeProtectionOpts struct {
ID int
ID int `json:"-"`
Delete bool `json:"delete"`
}

Expand Down
44 changes: 19 additions & 25 deletions hcloud/primary_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,18 +368,15 @@ func TestPrimaryIPClient(t *testing.T) {
t.Error("expected POST")
}
w.Header().Set("Content-Type", "application/json")
expectedReqBody := PrimaryIPAssignOpts{
AssigneeType: "server",
AssigneeID: 1,
ID: 1,
}

if err := json.NewDecoder(r.Body).Decode(&reqBody); err != nil {
t.Fatal(err)
}
if !cmp.Equal(expectedReqBody, reqBody) {
t.Log(cmp.Diff(expectedReqBody, reqBody))
t.Error("unexpected request body")
}

assert.Equal(t, int(1), reqBody.AssigneeID)
assert.Equal(t, "server", reqBody.AssigneeType)
assert.Equal(t, int(0), reqBody.ID)

json.NewEncoder(w).Encode(PrimaryIPAssignResult{
Action: schema.Action{ID: 1},
})
Expand Down Expand Up @@ -428,24 +425,25 @@ func TestPrimaryIPClient(t *testing.T) {
t.Error("expected POST")
}
w.Header().Set("Content-Type", "application/json")
expectedReqBody := PrimaryIPChangeDNSPtrOpts{
ID: 1,
}

if err := json.NewDecoder(r.Body).Decode(&reqBody); err != nil {
t.Fatal(err)
}
if !cmp.Equal(expectedReqBody, reqBody) {
t.Log(cmp.Diff(expectedReqBody, reqBody))
t.Error("unexpected request body")
}

assert.Equal(t, "value", reqBody.DNSPtr)
assert.Equal(t, "127.0.0.1", reqBody.IP)
assert.Equal(t, int(0), reqBody.ID)

json.NewEncoder(w).Encode(PrimaryIPChangeDNSPtrResult{
Action: schema.Action{ID: 1},
})
})

ctx := context.Background()
opts := PrimaryIPChangeDNSPtrOpts{
ID: 1,
ID: 1,
DNSPtr: "value",
IP: "127.0.0.1",
}

action, resp, err := env.Client.PrimaryIP.ChangeDNSPtr(ctx, opts)
Expand All @@ -463,17 +461,13 @@ func TestPrimaryIPClient(t *testing.T) {
t.Error("expected POST")
}
w.Header().Set("Content-Type", "application/json")
expectedReqBody := PrimaryIPChangeProtectionOpts{
ID: 1,
Delete: true,
}
if err := json.NewDecoder(r.Body).Decode(&reqBody); err != nil {
t.Fatal(err)
}
if !cmp.Equal(expectedReqBody, reqBody) {
t.Log(cmp.Diff(expectedReqBody, reqBody))
t.Error("unexpected request body")
}

assert.True(t, reqBody.Delete)
assert.Equal(t, int(0), reqBody.ID)

json.NewEncoder(w).Encode(PrimaryIPChangeProtectionResult{
Action: schema.Action{ID: 1},
})
Expand Down
Loading