Skip to content

Commit

Permalink
feat: print out IPs after they were created (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
phm07 committed Oct 26, 2023
1 parent 1c0e50a commit 0e0eaa8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
7 changes: 6 additions & 1 deletion internal/cmd/floatingip/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ var CreateCmd = base.Cmd{

fmt.Printf("Floating IP %d created\n", result.FloatingIP.ID)

return changeProtection(ctx, client, waiter, result.FloatingIP, true, protectionOps)
if err := changeProtection(ctx, client, waiter, result.FloatingIP, true, protectionOps); err != nil {
return err
}

fmt.Printf("IP%s: %s\n", result.FloatingIP.Type[2:], result.FloatingIP.IP)
return nil
},
}
1 change: 1 addition & 0 deletions internal/cmd/primaryip/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ var CreateCmd = base.Cmd{
}
}

fmt.Printf("IP%s: %s\n", result.PrimaryIP.Type[2:], result.PrimaryIP.IP)
return nil
},
}
13 changes: 10 additions & 3 deletions internal/cmd/primaryip/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package primaryip

import (
"context"
"net"
"testing"

"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -29,8 +30,12 @@ func TestCreate(t *testing.T) {
).
Return(
&hcloud.PrimaryIPCreateResult{
PrimaryIP: &hcloud.PrimaryIP{ID: 1},
Action: &hcloud.Action{ID: 321},
PrimaryIP: &hcloud.PrimaryIP{
ID: 1,
IP: net.ParseIP("192.168.2.1"),
Type: hcloud.PrimaryIPTypeIPv4,
},
Action: &hcloud.Action{ID: 321},
},
&hcloud.Response{},
nil,
Expand All @@ -41,7 +46,9 @@ func TestCreate(t *testing.T) {

out, err := fx.Run(cmd, []string{"--name=my-ip", "--type=ipv4", "--datacenter=fsn1-dc14"})

expOut := "Primary IP 1 created\n"
expOut := `Primary IP 1 created
IPv4: 192.168.2.1
`

assert.NoError(t, err)
assert.Equal(t, expOut, out)
Expand Down

0 comments on commit 0e0eaa8

Please sign in to comment.