1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
package primaryip
import (
"context"
"testing"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/hetznercloud/cli/internal/testutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
func TestCreate(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()
cmd := CreateCmd.CobraCommand(context.Background(), fx.Client, fx.TokenEnsurer, fx.ActionWaiter)
fx.ExpectEnsureToken()
fx.Client.PrimaryIPClient.EXPECT().
Create(
gomock.Any(),
hcloud.PrimaryIPCreateOpts{
Name: "my-ip",
Type: "ipv4",
Datacenter: "fsn1-dc14",
AssigneeType: "server",
},
).
Return(
&hcloud.PrimaryIPCreateResult{
PrimaryIP: &hcloud.PrimaryIP{ID: 1},
},
&hcloud.Response{},
nil,
)
out, err := fx.Run(cmd, []string{"--name=my-ip", "--type=ipv4", "--datacenter=fsn1-dc14"})
expOut := "Primary IP 1 created\n"
assert.NoError(t, err)
assert.Equal(t, expOut, out)
}
|