-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathdelete_rule_test.go
53 lines (43 loc) · 1.62 KB
/
delete_rule_test.go
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
45
46
47
48
49
50
51
52
53
package firewall_test
import (
"net"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"github.com/hetznercloud/cli/internal/cmd/firewall"
"github.com/hetznercloud/cli/internal/testutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
func TestDeleteRule(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()
cmd := firewall.DeleteRuleCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()
fw := &hcloud.Firewall{
ID: 123,
Name: "test",
Rules: []hcloud.FirewallRule{{
Direction: hcloud.FirewallRuleDirectionIn,
SourceIPs: []net.IPNet{{IP: net.IP{0, 0, 0, 0}, Mask: net.IPMask{0, 0, 0, 0}}, {IP: net.IP{127, 0, 0, 1}, Mask: net.IPMask{255, 255, 255, 255}}},
DestinationIPs: []net.IPNet{},
Protocol: hcloud.FirewallRuleProtocolTCP,
Port: hcloud.Ptr("80"),
Description: hcloud.Ptr("http"),
}},
}
fx.Client.FirewallClient.EXPECT().
Get(gomock.Any(), "test").
Return(fw, nil, nil)
fx.Client.FirewallClient.EXPECT().
SetRules(gomock.Any(), fw, hcloud.FirewallSetRulesOpts{Rules: []hcloud.FirewallRule{}}).
Return([]*hcloud.Action{{ID: 123}, {ID: 321}}, nil, nil)
fx.ActionWaiter.EXPECT().
WaitForActions(gomock.Any(), gomock.Any(), []*hcloud.Action{{ID: 123}, {ID: 321}}).
Return(nil)
out, errOut, err := fx.Run(cmd, []string{"--direction", "in", "--protocol", "tcp", "--source-ips", "0.0.0.0/0,127.0.0.1/32", "--port", "80", "--description", "http", "test"})
expOut := "Firewall Rules for Firewall 123 updated\n"
require.NoError(t, err)
assert.Empty(t, errOut)
assert.Equal(t, expOut, out)
}