-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
740 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package certificate | ||
|
||
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 TestLabelAdd(t *testing.T) { | ||
fx := testutil.NewFixture(t) | ||
defer fx.Finish() | ||
|
||
cmd := LabelCmds.AddCobraCommand( | ||
context.Background(), | ||
fx.Client, | ||
fx.TokenEnsurer) | ||
fx.ExpectEnsureToken() | ||
|
||
fx.Client.CertificateClient.EXPECT(). | ||
Get(gomock.Any(), "123"). | ||
Return(&hcloud.Certificate{ID: 123}, nil, nil) | ||
fx.Client.CertificateClient.EXPECT(). | ||
Update(gomock.Any(), &hcloud.Certificate{ID: 123}, hcloud.CertificateUpdateOpts{ | ||
Labels: map[string]string{ | ||
"key": "value", | ||
}, | ||
}) | ||
|
||
out, err := fx.Run(cmd, []string{"123", "key=value"}) | ||
|
||
expOut := "Label key added to certificate 123\n" | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, expOut, out) | ||
} | ||
|
||
func TestLabelRemove(t *testing.T) { | ||
fx := testutil.NewFixture(t) | ||
defer fx.Finish() | ||
|
||
cmd := LabelCmds.RemoveCobraCommand( | ||
context.Background(), | ||
fx.Client, | ||
fx.TokenEnsurer) | ||
fx.ExpectEnsureToken() | ||
|
||
fx.Client.CertificateClient.EXPECT(). | ||
Get(gomock.Any(), "123"). | ||
Return(&hcloud.Certificate{ | ||
ID: 123, | ||
Labels: map[string]string{ | ||
"key": "value", | ||
}, | ||
}, nil, nil) | ||
fx.Client.CertificateClient.EXPECT(). | ||
Update(gomock.Any(), &hcloud.Certificate{ID: 123}, hcloud.CertificateUpdateOpts{ | ||
Labels: make(map[string]string), | ||
}) | ||
|
||
out, err := fx.Run(cmd, []string{"123", "key"}) | ||
|
||
expOut := "Label key removed from certificate 123\n" | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, expOut, out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package firewall | ||
|
||
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 TestLabelAdd(t *testing.T) { | ||
fx := testutil.NewFixture(t) | ||
defer fx.Finish() | ||
|
||
cmd := LabelCmds.AddCobraCommand( | ||
context.Background(), | ||
fx.Client, | ||
fx.TokenEnsurer) | ||
fx.ExpectEnsureToken() | ||
|
||
fx.Client.FirewallClient.EXPECT(). | ||
Get(gomock.Any(), "123"). | ||
Return(&hcloud.Firewall{ID: 123}, nil, nil) | ||
fx.Client.FirewallClient.EXPECT(). | ||
Update(gomock.Any(), &hcloud.Firewall{ID: 123}, hcloud.FirewallUpdateOpts{ | ||
Labels: map[string]string{ | ||
"key": "value", | ||
}, | ||
}) | ||
|
||
out, err := fx.Run(cmd, []string{"123", "key=value"}) | ||
|
||
expOut := "Label key added to firewall 123\n" | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, expOut, out) | ||
} | ||
|
||
func TestLabelRemove(t *testing.T) { | ||
fx := testutil.NewFixture(t) | ||
defer fx.Finish() | ||
|
||
cmd := LabelCmds.RemoveCobraCommand( | ||
context.Background(), | ||
fx.Client, | ||
fx.TokenEnsurer) | ||
fx.ExpectEnsureToken() | ||
|
||
fx.Client.FirewallClient.EXPECT(). | ||
Get(gomock.Any(), "123"). | ||
Return(&hcloud.Firewall{ | ||
ID: 123, | ||
Labels: map[string]string{ | ||
"key": "value", | ||
}, | ||
}, nil, nil) | ||
fx.Client.FirewallClient.EXPECT(). | ||
Update(gomock.Any(), &hcloud.Firewall{ID: 123}, hcloud.FirewallUpdateOpts{ | ||
Labels: make(map[string]string), | ||
}) | ||
|
||
out, err := fx.Run(cmd, []string{"123", "key"}) | ||
|
||
expOut := "Label key removed from firewall 123\n" | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, expOut, out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package floatingip | ||
|
||
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 TestLabelAdd(t *testing.T) { | ||
fx := testutil.NewFixture(t) | ||
defer fx.Finish() | ||
|
||
cmd := LabelCmds.AddCobraCommand( | ||
context.Background(), | ||
fx.Client, | ||
fx.TokenEnsurer) | ||
fx.ExpectEnsureToken() | ||
|
||
fx.Client.FloatingIPClient.EXPECT(). | ||
Get(gomock.Any(), "123"). | ||
Return(&hcloud.FloatingIP{ID: 123}, nil, nil) | ||
fx.Client.FloatingIPClient.EXPECT(). | ||
Update(gomock.Any(), &hcloud.FloatingIP{ID: 123}, hcloud.FloatingIPUpdateOpts{ | ||
Labels: map[string]string{ | ||
"key": "value", | ||
}, | ||
}) | ||
|
||
out, err := fx.Run(cmd, []string{"123", "key=value"}) | ||
|
||
expOut := "Label key added to Floating IP 123\n" | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, expOut, out) | ||
} | ||
|
||
func TestLabelRemove(t *testing.T) { | ||
fx := testutil.NewFixture(t) | ||
defer fx.Finish() | ||
|
||
cmd := LabelCmds.RemoveCobraCommand( | ||
context.Background(), | ||
fx.Client, | ||
fx.TokenEnsurer) | ||
fx.ExpectEnsureToken() | ||
|
||
fx.Client.FloatingIPClient.EXPECT(). | ||
Get(gomock.Any(), "123"). | ||
Return(&hcloud.FloatingIP{ | ||
ID: 123, | ||
Labels: map[string]string{ | ||
"key": "value", | ||
}, | ||
}, nil, nil) | ||
fx.Client.FloatingIPClient.EXPECT(). | ||
Update(gomock.Any(), &hcloud.FloatingIP{ID: 123}, hcloud.FloatingIPUpdateOpts{ | ||
Labels: make(map[string]string), | ||
}) | ||
|
||
out, err := fx.Run(cmd, []string{"123", "key"}) | ||
|
||
expOut := "Label key removed from Floating IP 123\n" | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, expOut, out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package image | ||
|
||
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 TestLabelAdd(t *testing.T) { | ||
fx := testutil.NewFixture(t) | ||
defer fx.Finish() | ||
|
||
cmd := LabelCmds.AddCobraCommand( | ||
context.Background(), | ||
fx.Client, | ||
fx.TokenEnsurer) | ||
fx.ExpectEnsureToken() | ||
|
||
fx.Client.ImageClient.EXPECT(). | ||
Get(gomock.Any(), "123"). | ||
Return(&hcloud.Image{ID: 123}, nil, nil) | ||
fx.Client.ImageClient.EXPECT(). | ||
Update(gomock.Any(), &hcloud.Image{ID: 123}, hcloud.ImageUpdateOpts{ | ||
Labels: map[string]string{ | ||
"key": "value", | ||
}, | ||
}) | ||
|
||
out, err := fx.Run(cmd, []string{"123", "key=value"}) | ||
|
||
expOut := "Label key added to image 123\n" | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, expOut, out) | ||
} | ||
|
||
func TestLabelRemove(t *testing.T) { | ||
fx := testutil.NewFixture(t) | ||
defer fx.Finish() | ||
|
||
cmd := LabelCmds.RemoveCobraCommand( | ||
context.Background(), | ||
fx.Client, | ||
fx.TokenEnsurer) | ||
fx.ExpectEnsureToken() | ||
|
||
fx.Client.ImageClient.EXPECT(). | ||
Get(gomock.Any(), "123"). | ||
Return(&hcloud.Image{ | ||
ID: 123, | ||
Labels: map[string]string{ | ||
"key": "value", | ||
}, | ||
}, nil, nil) | ||
fx.Client.ImageClient.EXPECT(). | ||
Update(gomock.Any(), &hcloud.Image{ID: 123}, hcloud.ImageUpdateOpts{ | ||
Labels: make(map[string]string), | ||
}) | ||
|
||
out, err := fx.Run(cmd, []string{"123", "key"}) | ||
|
||
expOut := "Label key removed from image 123\n" | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, expOut, out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package loadbalancer | ||
|
||
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 TestLabelAdd(t *testing.T) { | ||
fx := testutil.NewFixture(t) | ||
defer fx.Finish() | ||
|
||
cmd := LabelCmds.AddCobraCommand( | ||
context.Background(), | ||
fx.Client, | ||
fx.TokenEnsurer) | ||
fx.ExpectEnsureToken() | ||
|
||
fx.Client.LoadBalancerClient.EXPECT(). | ||
Get(gomock.Any(), "123"). | ||
Return(&hcloud.LoadBalancer{ID: 123}, nil, nil) | ||
fx.Client.LoadBalancerClient.EXPECT(). | ||
Update(gomock.Any(), &hcloud.LoadBalancer{ID: 123}, hcloud.LoadBalancerUpdateOpts{ | ||
Labels: map[string]string{ | ||
"key": "value", | ||
}, | ||
}) | ||
|
||
out, err := fx.Run(cmd, []string{"123", "key=value"}) | ||
|
||
expOut := "Label key added to Load Balancer 123\n" | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, expOut, out) | ||
} | ||
|
||
func TestLabelRemove(t *testing.T) { | ||
fx := testutil.NewFixture(t) | ||
defer fx.Finish() | ||
|
||
cmd := LabelCmds.RemoveCobraCommand( | ||
context.Background(), | ||
fx.Client, | ||
fx.TokenEnsurer) | ||
fx.ExpectEnsureToken() | ||
|
||
fx.Client.LoadBalancerClient.EXPECT(). | ||
Get(gomock.Any(), "123"). | ||
Return(&hcloud.LoadBalancer{ | ||
ID: 123, | ||
Labels: map[string]string{ | ||
"key": "value", | ||
}, | ||
}, nil, nil) | ||
fx.Client.LoadBalancerClient.EXPECT(). | ||
Update(gomock.Any(), &hcloud.LoadBalancer{ID: 123}, hcloud.LoadBalancerUpdateOpts{ | ||
Labels: make(map[string]string), | ||
}) | ||
|
||
out, err := fx.Run(cmd, []string{"123", "key"}) | ||
|
||
expOut := "Label key removed from Load Balancer 123\n" | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, expOut, out) | ||
} |
Oops, something went wrong.