From e886d3432ca3310b5383a7ea8de2738ef0bc7541 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:37:31 +0200 Subject: [PATCH] fix lint --- e2e_test/combined_test.go | 19 ++++---- e2e_test/datacenter_test.go | 11 ++--- e2e_test/firewall_test.go | 75 ++++++++++++++++---------------- e2e_test/floatingip_test.go | 55 +++++++++++------------ e2e_test/network_test.go | 67 ++++++++++++++-------------- e2e_test/placement_group_test.go | 25 ++++++----- 6 files changed, 129 insertions(+), 123 deletions(-) diff --git a/e2e_test/combined_test.go b/e2e_test/combined_test.go index 55dd16f5..d9c56944 100644 --- a/e2e_test/combined_test.go +++ b/e2e_test/combined_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestCombined(t *testing.T) { @@ -18,7 +19,7 @@ func TestCombined(t *testing.T) { } out, err := runCommand(t, "firewall", "apply-to-resource", "--type", "server", "--server", "test-server", strconv.Itoa(firewallID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Firewall %d applied to resource\n", firewallID), out) out, err = runCommand(t, "firewall", "delete", strconv.Itoa(firewallID)) @@ -26,11 +27,11 @@ func TestCombined(t *testing.T) { assert.Empty(t, out) out, err = runCommand(t, "firewall", "remove-from-resource", "--type", "server", "--server", "test-server", strconv.Itoa(firewallID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Firewall %d removed from resource\n", firewallID), out) out, err = runCommand(t, "firewall", "delete", strconv.Itoa(firewallID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("firewall %d deleted\n", firewallID), out) floatingIP, err := createFloatingIP(t, "ipv4", "--server", strconv.Itoa(serverID)) @@ -39,15 +40,15 @@ func TestCombined(t *testing.T) { } out, err = runCommand(t, "floating-ip", "unassign", strconv.Itoa(floatingIP)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Floating IP %d unassigned\n", floatingIP), out) out, err = runCommand(t, "floating-ip", "assign", strconv.Itoa(floatingIP), strconv.Itoa(serverID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Floating IP %d assigned to server %d\n", floatingIP, serverID), out) out, err = runCommand(t, "floating-ip", "describe", strconv.Itoa(floatingIP)) - assert.NoError(t, err) + require.NoError(t, err) assert.Regexp(t, `ID:\s+[0-9]+ Type:\s+ipv4 Name:\s+test-floating-ip @@ -68,14 +69,14 @@ Labels: `, out) out, err = runCommand(t, "floating-ip", "list", "-o", "columns=server", "-o", "noheader") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "test-server\n", out) out, err = runCommand(t, "floating-ip", "delete", strconv.Itoa(floatingIP)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Floating IP %d deleted\n", floatingIP), out) out, err = runCommand(t, "server", "delete", strconv.Itoa(serverID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Server %d deleted\n", serverID), out) } diff --git a/e2e_test/datacenter_test.go b/e2e_test/datacenter_test.go index 04f6bbe6..d3dcdf3b 100644 --- a/e2e_test/datacenter_test.go +++ b/e2e_test/datacenter_test.go @@ -5,26 +5,27 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestDatacenter(t *testing.T) { t.Parallel() out, err := runCommand(t, "datacenter", "list") - assert.NoError(t, err) + require.NoError(t, err) assert.Regexp(t, `ID +NAME +DESCRIPTION +LOCATION ([0-9]+ +[a-z0-9\-]+ +[a-zA-Z0-9\- ]+ +[a-z0-9\-]+\n)+`, out) out, err = runCommand(t, "datacenter", "list", "-o=json") - assert.NoError(t, err) - assert.NoError(t, json.Unmarshal([]byte(out), new([]any))) + require.NoError(t, err) + require.NoError(t, json.Unmarshal([]byte(out), new([]any))) out, err = runCommand(t, "datacenter", "describe", "123456") - assert.EqualError(t, err, "datacenter not found: 123456") + require.EqualError(t, err, "datacenter not found: 123456") assert.Empty(t, out) out, err = runCommand(t, "datacenter", "describe", "2") - assert.NoError(t, err) + require.NoError(t, err) assert.Regexp(t, `ID:\s+[0-9]+ Name:\s+[a-z0-9\-]+ Description:\s+[a-zA-Z0-9\- ]+ diff --git a/e2e_test/firewall_test.go b/e2e_test/firewall_test.go index f3239677..3ac36d99 100644 --- a/e2e_test/firewall_test.go +++ b/e2e_test/firewall_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestFirewall(t *testing.T) { @@ -17,83 +18,83 @@ func TestFirewall(t *testing.T) { } out, err := runCommand(t, "firewall", "add-label", "non-existing-firewall", "foo=bar") - assert.EqualError(t, err, "firewall not found: non-existing-firewall") + require.EqualError(t, err, "firewall not found: non-existing-firewall") assert.Empty(t, out) out, err = runCommand(t, "firewall", "add-label", strconv.Itoa(firewallID), "foo=bar") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Label(s) foo added to firewall %d\n", firewallID), out) out, err = runCommand(t, "firewall", "add-label", strconv.Itoa(firewallID), "baz=qux") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Label(s) baz added to firewall %d\n", firewallID), out) out, err = runCommand(t, "firewall", "update", strconv.Itoa(firewallID), "--name", "new-test-firewall") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Firewall %d updated\n", firewallID), out) out, err = runCommand(t, "firewall", "remove-label", "new-test-firewall", "baz") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Label(s) baz removed from firewall %d\n", firewallID), out) t.Run("add-rule", func(t *testing.T) { t.Run("missing-args", func(t *testing.T) { out, err := runCommand(t, "firewall", "add-rule", strconv.Itoa(firewallID)) - assert.EqualError(t, err, `required flag(s) "direction", "protocol" not set`) + require.EqualError(t, err, `required flag(s) "direction", "protocol" not set`) assert.Empty(t, out) }) t.Run("unknown-firewall", func(t *testing.T) { out, err := runCommand(t, "firewall", "add-rule", "non-existing-firewall", "--direction", "in", "--source-ips", "10.0.0.0/24", "--protocol", "tcp", "--port", "9100") - assert.EqualError(t, err, "Firewall not found: non-existing-firewall") + require.EqualError(t, err, "Firewall not found: non-existing-firewall") assert.Empty(t, out) }) t.Run("missing-port", func(t *testing.T) { out, err := runCommand(t, "firewall", "add-rule", strconv.Itoa(firewallID), "--direction", "in", "--source-ips", "10.0.0.0/24", "--protocol", "tcp", "--description", "Some random description") - assert.EqualError(t, err, "port is required (--port)") + require.EqualError(t, err, "port is required (--port)") assert.Empty(t, out) }) t.Run("port-not-allowed", func(t *testing.T) { out, err := runCommand(t, "firewall", "add-rule", strconv.Itoa(firewallID), "--direction", "out", "--destination-ips", "192.168.1.0/24", "--protocol", "icmp", "--port", "12345") - assert.EqualError(t, err, "port is not allowed for this protocol") + require.EqualError(t, err, "port is not allowed for this protocol") assert.Empty(t, out) }) t.Run("invalid-direction", func(t *testing.T) { out, err := runCommand(t, "firewall", "add-rule", strconv.Itoa(firewallID), "--direction", "foo", "--destination-ips", "192.168.1.0/24", "--protocol", "tcp", "--port", "12345") - assert.EqualError(t, err, "invalid direction: foo") + require.EqualError(t, err, "invalid direction: foo") assert.Empty(t, out) }) t.Run("invalid-protocol", func(t *testing.T) { out, err := runCommand(t, "firewall", "add-rule", strconv.Itoa(firewallID), "--direction", "out", "--destination-ips", "192.168.1.0/24", "--protocol", "abc", "--port", "12345") - assert.EqualError(t, err, "invalid protocol: abc") + require.EqualError(t, err, "invalid protocol: abc") assert.Empty(t, out) }) t.Run("tcp-in", func(t *testing.T) { out, err := runCommand(t, "firewall", "add-rule", strconv.Itoa(firewallID), "--direction", "in", "--source-ips", "10.0.0.0/24", "--protocol", "tcp", "--port", "9100", "--description", "Some random description") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Firewall Rules for Firewall %d updated\n", firewallID), out) }) t.Run("icmp-out", func(t *testing.T) { out, err := runCommand(t, "firewall", "add-rule", strconv.Itoa(firewallID), "--direction", "out", "--destination-ips", "192.168.1.0/24", "--protocol", "icmp") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Firewall Rules for Firewall %d updated\n", firewallID), out) }) t.Run("invalid-ip-out", func(t *testing.T) { out, err := runCommand(t, "firewall", "add-rule", strconv.Itoa(firewallID), "--direction", "out", "--destination-ips", "invalid-ip", "--protocol", "tcp", "--port", "9100") - assert.EqualError(t, err, "destination error on index 0: invalid CIDR address: invalid-ip") + require.EqualError(t, err, "destination error on index 0: invalid CIDR address: invalid-ip") assert.Empty(t, out) }) t.Run("invalid-ip-range-out", func(t *testing.T) { out, err := runCommand(t, "firewall", "add-rule", strconv.Itoa(firewallID), "--direction", "in", "--source-ips", "10.1.2.3/8", "--protocol", "tcp", "--port", "9100") - assert.EqualError(t, err, "source ips error on index 0: 10.1.2.3/8 is not the start of the cidr block 10.0.0.0/8") + require.EqualError(t, err, "source ips error on index 0: 10.1.2.3/8 is not the start of the cidr block 10.0.0.0/8") assert.Empty(t, out) }) }) @@ -101,38 +102,38 @@ func TestFirewall(t *testing.T) { t.Run("apply-to-resource", func(t *testing.T) { t.Run("unknown-type", func(t *testing.T) { out, err := runCommand(t, "firewall", "apply-to-resource", "--type", "non-existing-type", strconv.Itoa(firewallID)) - assert.EqualError(t, err, "unknown type non-existing-type") + require.EqualError(t, err, "unknown type non-existing-type") assert.Empty(t, out) }) t.Run("missing-server", func(t *testing.T) { out, err := runCommand(t, "firewall", "apply-to-resource", "--type", "server", strconv.Itoa(firewallID)) - assert.EqualError(t, err, "type server need a --server specific") + require.EqualError(t, err, "type server need a --server specific") assert.Empty(t, out) }) t.Run("missing-label-selector", func(t *testing.T) { out, err := runCommand(t, "firewall", "apply-to-resource", "--type", "label_selector", strconv.Itoa(firewallID)) - assert.EqualError(t, err, "type label_selector need a --label-selector specific") + require.EqualError(t, err, "type label_selector need a --label-selector specific") assert.Empty(t, out) }) t.Run("unknown-firewall", func(t *testing.T) { out, err := runCommand(t, "firewall", "apply-to-resource", "--type", "server", "--server", "non-existing-server", "non-existing-firewall") - assert.EqualError(t, err, "Firewall not found: non-existing-firewall") + require.EqualError(t, err, "Firewall not found: non-existing-firewall") assert.Empty(t, out) }) t.Run("unknown-server", func(t *testing.T) { out, err := runCommand(t, "firewall", "apply-to-resource", "--type", "server", "--server", "non-existing-server", strconv.Itoa(firewallID)) - assert.EqualError(t, err, "Server not found: non-existing-server") + require.EqualError(t, err, "Server not found: non-existing-server") assert.Empty(t, out) }) t.Run("label-selector", func(t *testing.T) { out, err := runCommand(t, "firewall", "apply-to-resource", "--type", "label_selector", "--label-selector", "foo=bar", strconv.Itoa(firewallID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Firewall %d applied to resource\n", firewallID), out) }) }) out, err = runCommand(t, "firewall", "describe", strconv.Itoa(firewallID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Regexp(t, `ID:\s+[0-9]+ Name:\s+new-test-firewall Created:\s+.*? @@ -179,32 +180,32 @@ Applied To: t.Run("remove-from-resource", func(t *testing.T) { t.Run("unknown-type", func(t *testing.T) { out, err := runCommand(t, "firewall", "remove-from-resource", "--type", "non-existing-type", strconv.Itoa(firewallID)) - assert.EqualError(t, err, "unknown type non-existing-type") + require.EqualError(t, err, "unknown type non-existing-type") assert.Empty(t, out) }) t.Run("missing-server", func(t *testing.T) { out, err := runCommand(t, "firewall", "remove-from-resource", "--type", "server", strconv.Itoa(firewallID)) - assert.EqualError(t, err, "type server need a --server specific") + require.EqualError(t, err, "type server need a --server specific") assert.Empty(t, out) }) t.Run("missing-label-selector", func(t *testing.T) { out, err := runCommand(t, "firewall", "remove-from-resource", "--type", "label_selector", strconv.Itoa(firewallID)) - assert.EqualError(t, err, "type label_selector need a --label-selector specific") + require.EqualError(t, err, "type label_selector need a --label-selector specific") assert.Empty(t, out) }) t.Run("unknown-firewall", func(t *testing.T) { out, err := runCommand(t, "firewall", "remove-from-resource", "--type", "server", "--server", "non-existing-server", "non-existing-firewall") - assert.EqualError(t, err, "Firewall not found: non-existing-firewall") + require.EqualError(t, err, "Firewall not found: non-existing-firewall") assert.Empty(t, out) }) t.Run("unknown-server", func(t *testing.T) { out, err := runCommand(t, "firewall", "remove-from-resource", "--type", "server", "--server", "non-existing-server", strconv.Itoa(firewallID)) - assert.EqualError(t, err, "Server not found: non-existing-server") + require.EqualError(t, err, "Server not found: non-existing-server") assert.Empty(t, out) }) t.Run("label-selector", func(t *testing.T) { out, err := runCommand(t, "firewall", "remove-from-resource", "--type", "label_selector", "--label-selector", "foo=bar", strconv.Itoa(firewallID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Firewall %d removed from resource\n", firewallID), out) }) }) @@ -212,51 +213,51 @@ Applied To: t.Run("delete-rule", func(t *testing.T) { t.Run("unknown-firewall", func(t *testing.T) { out, err := runCommand(t, "firewall", "delete-rule", "non-existing-firewall", "--direction", "in", "--source-ips", "10.0.0.0/24", "--protocol", "tcp", "--port", "9100") - assert.EqualError(t, err, "Firewall not found: non-existing-firewall") + require.EqualError(t, err, "Firewall not found: non-existing-firewall") assert.Empty(t, out) }) t.Run("missing-port", func(t *testing.T) { out, err := runCommand(t, "firewall", "delete-rule", strconv.Itoa(firewallID), "--direction", "in", "--source-ips", "10.0.0.0/24", "--protocol", "tcp") - assert.EqualError(t, err, "port is required (--port)") + require.EqualError(t, err, "port is required (--port)") assert.Empty(t, out) }) t.Run("port-not-allowed", func(t *testing.T) { out, err := runCommand(t, "firewall", "delete-rule", strconv.Itoa(firewallID), "--direction", "out", "--destination-ips", "192.168.1.0/24", "--protocol", "icmp", "--port", "12345") - assert.EqualError(t, err, "port is not allowed for this protocol") + require.EqualError(t, err, "port is not allowed for this protocol") assert.Empty(t, out) }) t.Run("tcp-in", func(t *testing.T) { out, err := runCommand(t, "firewall", "delete-rule", strconv.Itoa(firewallID), "--direction", "in", "--source-ips", "10.0.0.0/24", "--protocol", "tcp", "--port", "9100", "--description", "Some random description") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Firewall Rules for Firewall %d updated\n", firewallID), out) }) t.Run("icmp-out", func(t *testing.T) { out, err := runCommand(t, "firewall", "delete-rule", strconv.Itoa(firewallID), "--direction", "out", "--destination-ips", "192.168.1.0/24", "--protocol", "icmp") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Firewall Rules for Firewall %d updated\n", firewallID), out) }) t.Run("non-existing-rule", func(t *testing.T) { out, err := runCommand(t, "firewall", "delete-rule", strconv.Itoa(firewallID), "--direction", "in", "--source-ips", "123.123.123.123/32", "--port", "1234", "--protocol", "tcp") - assert.EqualError(t, err, fmt.Sprintf("the specified rule was not found in the ruleset of Firewall %d", firewallID)) + require.EqualError(t, err, fmt.Sprintf("the specified rule was not found in the ruleset of Firewall %d", firewallID)) assert.Empty(t, out) }) }) out, err = runCommand(t, "firewall", "replace-rules", "non-existing-firewall", "--rules-file", "rules_file.json") - assert.EqualError(t, err, "Firewall not found: non-existing-firewall") + require.EqualError(t, err, "Firewall not found: non-existing-firewall") assert.Empty(t, out) out, err = runCommand(t, "firewall", "replace-rules", strconv.Itoa(firewallID), "--rules-file", "rules_file.json") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Firewall Rules for Firewall %d updated\n", firewallID), out) out, err = runCommand(t, "firewall", "delete", strconv.Itoa(firewallID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("firewall %d deleted\n", firewallID), out) } diff --git a/e2e_test/floatingip_test.go b/e2e_test/floatingip_test.go index 429720a1..63dcde24 100644 --- a/e2e_test/floatingip_test.go +++ b/e2e_test/floatingip_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/swaggest/assertjson" ) @@ -15,13 +16,13 @@ func TestFloatingIP(t *testing.T) { t.Parallel() _, err := createFloatingIP(t, "") - assert.EqualError(t, err, "type is required") + require.EqualError(t, err, "type is required") _, err = createFloatingIP(t, "ipv4") - assert.EqualError(t, err, "one of --home-location or --server is required") + require.EqualError(t, err, "one of --home-location or --server is required") _, err = createFloatingIP(t, "ipv4", "--server", "non-existing-server") - assert.EqualError(t, err, "server not found: non-existing-server") + require.EqualError(t, err, "server not found: non-existing-server") floatingIPId, err := createFloatingIP(t, "ipv4", "--home-location", "fsn1") if err != nil { @@ -31,64 +32,64 @@ func TestFloatingIP(t *testing.T) { t.Run("labels", func(t *testing.T) { t.Run("add-label-non-existing-floating-ip", func(t *testing.T) { out, err := runCommand(t, "floating-ip", "add-label", "non-existing-floating-ip", "foo=bar") - assert.EqualError(t, err, "floating IP not found: non-existing-floating-ip") + require.EqualError(t, err, "floating IP not found: non-existing-floating-ip") assert.Empty(t, out) }) t.Run("add-label", func(t *testing.T) { out, err := runCommand(t, "floating-ip", "add-label", strconv.Itoa(floatingIPId), "foo=bar") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Label(s) foo added to Floating IP %d\n", floatingIPId), out) }) }) out, err := runCommand(t, "floating-ip", "update", strconv.Itoa(floatingIPId), "--name", "new-test-floating-ip", "--description", "Some description") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Floating IP %d updated\n", floatingIPId), out) out, err = runCommand(t, "floating-ip", "set-rdns", strconv.Itoa(floatingIPId), "--hostname", "s1.example.com") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Reverse DNS of Floating IP %d changed\n", floatingIPId), out) out, err = runCommand(t, "floating-ip", "unassign", "non-existing-floating-ip") - assert.EqualError(t, err, "Floating IP not found: non-existing-floating-ip") + require.EqualError(t, err, "Floating IP not found: non-existing-floating-ip") assert.Empty(t, out) out, err = runCommand(t, "floating-ip", "assign", "non-existing-floating-ip", "non-existing-server") - assert.EqualError(t, err, "Floating IP not found: non-existing-floating-ip") + require.EqualError(t, err, "Floating IP not found: non-existing-floating-ip") assert.Empty(t, out) out, err = runCommand(t, "floating-ip", "assign", strconv.Itoa(floatingIPId), "non-existing-server") - assert.EqualError(t, err, "server not found: non-existing-server") + require.EqualError(t, err, "server not found: non-existing-server") assert.Empty(t, out) t.Run("enable-protection", func(t *testing.T) { t.Run("unknown-protection-level", func(t *testing.T) { out, err := runCommand(t, "floating-ip", "enable-protection", strconv.Itoa(floatingIPId), "unknown-protection-level") - assert.EqualError(t, err, "unknown protection level: unknown-protection-level") + require.EqualError(t, err, "unknown protection level: unknown-protection-level") assert.Empty(t, out) }) t.Run("non-existing-floating-ip", func(t *testing.T) { out, err := runCommand(t, "floating-ip", "enable-protection", "non-existing-floating-ip", "delete") - assert.EqualError(t, err, "Floating IP not found: non-existing-floating-ip") + require.EqualError(t, err, "Floating IP not found: non-existing-floating-ip") assert.Empty(t, out) }) t.Run("enable-delete-protection", func(t *testing.T) { out, err := runCommand(t, "floating-ip", "enable-protection", strconv.Itoa(floatingIPId), "delete") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Resource protection enabled for floating IP %d\n", floatingIPId), out) }) }) ipStr, err := runCommand(t, "floating-ip", "describe", strconv.Itoa(floatingIPId), "--output", "format={{.IP}}") - assert.NoError(t, err) + require.NoError(t, err) ipStr = strings.TrimSpace(ipStr) assert.Regexp(t, `^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$`, ipStr) out, err = runCommand(t, "floating-ip", "describe", strconv.Itoa(floatingIPId)) - assert.NoError(t, err) + require.NoError(t, err) assert.Regexp(t, `ID:\s+[0-9]+ Type:\s+ipv4 Name:\s+new-test-floating-ip @@ -108,13 +109,13 @@ Labels: `, out) out, err = runCommand(t, "floating-ip", "list", "--output", "columns=id,name,type,ip,dns,server,home,blocked,protection,labels,created,age") - assert.NoError(t, err) + require.NoError(t, err) assert.Regexp(t, `^ID +NAME +TYPE +IP +DNS +SERVER +HOME +BLOCKED +PROTECTION +LABELS +CREATED +AGE [0-9]+ +new-test-floating-ip +ipv4 +(?:[0-9]{1,3}\.){3}[0-9]{1,3} +s1\.example\.com +- +fsn1 +no +delete +foo=bar.*? $`, out) out, err = runCommand(t, "floating-ip", "list", "-o=json") - assert.NoError(t, err) + require.NoError(t, err) assertjson.Equal(t, []byte(fmt.Sprintf(` [ { @@ -159,25 +160,25 @@ $`, out) t.Run("disable-protection", func(t *testing.T) { t.Run("non-existing-floating-ip", func(t *testing.T) { out, err := runCommand(t, "floating-ip", "disable-protection", "non-existing-floating-ip", "delete") - assert.EqualError(t, err, "Floating IP not found: non-existing-floating-ip") + require.EqualError(t, err, "Floating IP not found: non-existing-floating-ip") assert.Empty(t, out) }) t.Run("unknown-protection-level", func(t *testing.T) { out, err := runCommand(t, "floating-ip", "disable-protection", strconv.Itoa(floatingIPId), "unknown-protection-level") - assert.EqualError(t, err, "unknown protection level: unknown-protection-level") + require.EqualError(t, err, "unknown protection level: unknown-protection-level") assert.Empty(t, out) }) t.Run("disable-delete-protection", func(t *testing.T) { out, err = runCommand(t, "floating-ip", "disable-protection", strconv.Itoa(floatingIPId), "delete") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Resource protection disabled for floating IP %d\n", floatingIPId), out) }) }) out, err = runCommand(t, "floating-ip", "delete", strconv.Itoa(floatingIPId)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Floating IP %d deleted\n", floatingIPId), out) floatingIPId, err = createFloatingIP(t, "ipv6", "--home-location", "fsn1") @@ -186,7 +187,7 @@ $`, out) } out, err = runCommand(t, "floating-ip", "describe", strconv.Itoa(floatingIPId)) - assert.NoError(t, err) + require.NoError(t, err) assert.Regexp(t, `ID:\s+[0-9]+ Type:\s+ipv6 Name:\s+test-floating-ip @@ -206,29 +207,29 @@ Labels: `, out) out, err = runCommand(t, "floating-ip", "describe", strconv.Itoa(floatingIPId), "--output", "format={{.IP}}") - assert.NoError(t, err) + require.NoError(t, err) out = strings.TrimSpace(out) ipv6 := net.ParseIP(out) if ipv6 != nil { out, err = runCommand(t, "floating-ip", "set-rdns", strconv.Itoa(floatingIPId), "--ip", ipv6.String()+"1", "--hostname", "s1.example.com") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Reverse DNS of Floating IP %d changed\n", floatingIPId), out) out, err = runCommand(t, "floating-ip", "set-rdns", strconv.Itoa(floatingIPId), "--ip", ipv6.String()+"2", "--hostname", "s2.example.com") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Reverse DNS of Floating IP %d changed\n", floatingIPId), out) } else { t.Errorf("invalid IPv6 address: %s", out) } out, err = runCommand(t, "floating-ip", "list", "-o", "columns=ip,dns") - assert.NoError(t, err) + require.NoError(t, err) assert.Regexp(t, fmt.Sprintf(`^IP +DNS %s\/64 +2 entries `, ipv6), out) out, err = runCommand(t, "floating-ip", "delete", strconv.Itoa(floatingIPId)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Floating IP %d deleted\n", floatingIPId), out) } diff --git a/e2e_test/network_test.go b/e2e_test/network_test.go index b47f21d7..ae0229ed 100644 --- a/e2e_test/network_test.go +++ b/e2e_test/network_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/swaggest/assertjson" ) @@ -14,67 +15,67 @@ func TestNetwork(t *testing.T) { out, err := runCommand(t, "network", "create") assert.Empty(t, out) - assert.EqualError(t, err, `required flag(s) "ip-range", "name" not set`) + require.EqualError(t, err, `required flag(s) "ip-range", "name" not set`) out, err = runCommand(t, "network", "create", "--name", "test-network", "--ip-range", "10.0.0.0/24") - assert.NoError(t, err) + require.NoError(t, err) if !assert.Regexp(t, `^Network [0-9]+ created\n$`, out) { // network was not created (properly), so there's no need to test it return } networkID, err := strconv.Atoi(out[8 : len(out)-9]) - assert.NoError(t, err) + require.NoError(t, err) out, err = runCommand(t, "network", "create", "--name", "test-network", "--ip-range", "10.0.1.0/24") assert.Empty(t, out) - assert.Error(t, err) + require.Error(t, err) assert.Regexp(t, `^name is already used \(uniqueness_error, [0-9a-f]+\)$`, err.Error()) out, err = runCommand(t, "network", "enable-protection", strconv.Itoa(networkID), "non-existing-protection") - assert.EqualError(t, err, "unknown protection level: non-existing-protection") + require.EqualError(t, err, "unknown protection level: non-existing-protection") assert.Empty(t, out) out, err = runCommand(t, "network", "enable-protection", "non-existing-network", "delete") - assert.EqualError(t, err, "network not found: non-existing-network") + require.EqualError(t, err, "network not found: non-existing-network") assert.Empty(t, out) out, err = runCommand(t, "network", "enable-protection", strconv.Itoa(networkID), "delete") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Resource protection enabled for network %d\n", networkID), out) out, err = runCommand(t, "network", "list", "-o=columns=servers,ip_range,labels,protection,created,age") - assert.NoError(t, err) + require.NoError(t, err) assert.Regexp(t, `SERVERS +IP RANGE +LABELS +PROTECTION +CREATED +AGE 0 servers +10\.0\.0\.0/24 +delete .*? (?:just now|[0-9]+s) `, out) out, err = runCommand(t, "network", "change-ip-range", "--ip-range", "10.0.2.0/16", "non-existing-network") - assert.EqualError(t, err, "network not found: non-existing-network") + require.EqualError(t, err, "network not found: non-existing-network") assert.Empty(t, out) out, err = runCommand(t, "network", "change-ip-range", "--ip-range", "10.0.2.0/16", "test-network") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("IP range of network %d changed\n", networkID), out) out, err = runCommand(t, "network", "add-label", "non-existing-network", "foo=bar") - assert.EqualError(t, err, "network not found: non-existing-network") + require.EqualError(t, err, "network not found: non-existing-network") assert.Empty(t, out) out, err = runCommand(t, "network", "add-label", "test-network", "foo=bar") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Label(s) foo added to Network %d\n", networkID), out) out, err = runCommand(t, "network", "add-label", "test-network", "baz=qux") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Label(s) baz added to Network %d\n", networkID), out) out, err = runCommand(t, "network", "remove-label", "test-network", "baz") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Label(s) baz removed from Network %d\n", networkID), out) out, err = runCommand(t, "network", "update", "test-network", "--name", "new-test-network") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "Network test-network updated\n", out) out, err = runCommand(t, "network", "delete", strconv.Itoa(networkID)) @@ -82,7 +83,7 @@ func TestNetwork(t *testing.T) { assert.Regexp(t, `^network is delete protected \(protected, [0-9a-f]+\)$`, err.Error()) out, err = runCommand(t, "network", "add-subnet", "--type", "cloud", "--network-zone", "eu-central", "--ip-range", "10.0.16.0/24", "non-existing-network") - assert.EqualError(t, err, "network not found: non-existing-network") + require.EqualError(t, err, "network not found: non-existing-network") assert.Empty(t, out) out, err = runCommand(t, "network", "add-subnet", "--type", "vswitch", "--vswitch-id", "42", "--network-zone", "eu-central", "--ip-range", "10.0.17.0/24", strconv.Itoa(networkID)) @@ -90,27 +91,27 @@ func TestNetwork(t *testing.T) { assert.Regexp(t, `^vswitch not found \(service_error, [0-9a-f]+\)$`, err.Error()) out, err = runCommand(t, "network", "add-subnet", "--type", "cloud", "--network-zone", "eu-central", "--ip-range", "10.0.16.0/24", strconv.Itoa(networkID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Subnet added to network %d\n", networkID), out) out, err = runCommand(t, "network", "add-route", "--destination", "10.100.1.0/24", "--gateway", "10.0.1.1", "non-existing-network") - assert.EqualError(t, err, "network not found: non-existing-network") + require.EqualError(t, err, "network not found: non-existing-network") assert.Empty(t, out) out, err = runCommand(t, "network", "add-route", "--destination", "10.100.1.0/24", "--gateway", "10.0.1.1", strconv.Itoa(networkID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Route added to network %d\n", networkID), out) out, err = runCommand(t, "network", "expose-routes-to-vswitch", "non-existing-network") - assert.EqualError(t, err, "network not found: non-existing-network") + require.EqualError(t, err, "network not found: non-existing-network") assert.Empty(t, out) out, err = runCommand(t, "network", "expose-routes-to-vswitch", strconv.Itoa(networkID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "Exposing routes to connected vSwitch of network new-test-network enabled\n", out) out, err = runCommand(t, "network", "describe", strconv.Itoa(networkID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Regexp(t, `^ID:\s+[0-9]+ Name:\s+new-test-network Created:\s+.*? @@ -131,7 +132,7 @@ Labels: $`, out) out, err = runCommand(t, "network", "list", "-o=json") - assert.NoError(t, err) + require.NoError(t, err) assertjson.Equal(t, []byte(fmt.Sprintf(` [ { @@ -166,39 +167,39 @@ $`, out) `, networkID)), []byte(out)) out, err = runCommand(t, "network", "remove-route", "--destination", "10.100.1.0/24", "--gateway", "10.0.1.1", "non-existing-network") - assert.EqualError(t, err, "network not found: non-existing-network") + require.EqualError(t, err, "network not found: non-existing-network") assert.Empty(t, out) out, err = runCommand(t, "network", "remove-route", "--destination", "10.100.1.0/24", "--gateway", "10.0.1.1", strconv.Itoa(networkID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Route removed from network %d\n", networkID), out) out, err = runCommand(t, "network", "remove-subnet", "--ip-range", "10.0.16.0/24", "non-existing-network") - assert.EqualError(t, err, "network not found: non-existing-network") + require.EqualError(t, err, "network not found: non-existing-network") assert.Empty(t, out) out, err = runCommand(t, "network", "remove-subnet", "--ip-range", "10.0.16.0/24", strconv.Itoa(networkID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Subnet 10.0.16.0/24 removed from network %d\n", networkID), out) out, err = runCommand(t, "network", "disable-protection", "non-existing-network", "delete") - assert.EqualError(t, err, "network not found: non-existing-network") + require.EqualError(t, err, "network not found: non-existing-network") assert.Empty(t, out) out, err = runCommand(t, "network", "disable-protection", strconv.Itoa(networkID), "delete") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Resource protection disabled for network %d\n", networkID), out) out, err = runCommand(t, "network", "remove-label", strconv.Itoa(networkID), "foo") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Label(s) foo removed from Network %d\n", networkID), out) out, err = runCommand(t, "network", "expose-routes-to-vswitch", "--disable", strconv.Itoa(networkID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "Exposing routes to connected vSwitch of network new-test-network disabled\n", out) out, err = runCommand(t, "network", "describe", strconv.Itoa(networkID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Regexp(t, `^ID:\s+[0-9]+ Name:\s+new-test-network Created:\s+.*? @@ -215,6 +216,6 @@ Labels: $`, out) out, err = runCommand(t, "network", "delete", strconv.Itoa(networkID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Network %d deleted\n", networkID), out) } diff --git a/e2e_test/placement_group_test.go b/e2e_test/placement_group_test.go index 714b6515..3858f6f8 100644 --- a/e2e_test/placement_group_test.go +++ b/e2e_test/placement_group_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/swaggest/assertjson" ) @@ -14,41 +15,41 @@ func TestPlacementGroup(t *testing.T) { out, err := runCommand(t, "placement-group", "create") assert.Empty(t, out) - assert.EqualError(t, err, `required flag(s) "name", "type" not set`) + require.EqualError(t, err, `required flag(s) "name", "type" not set`) out, err = runCommand(t, "placement-group", "create", "--name", "test-placement-group", "--type", "spread") - assert.NoError(t, err) + require.NoError(t, err) if !assert.Regexp(t, `^Placement group [0-9]+ created\n$`, out) { return } pgID, err := strconv.Atoi(out[16 : len(out)-9]) - assert.NoError(t, err) + require.NoError(t, err) out, err = runCommand(t, "placement-group", "add-label", "non-existing-placement-group", "foo=bar") - assert.EqualError(t, err, "placement group not found: non-existing-placement-group") + require.EqualError(t, err, "placement group not found: non-existing-placement-group") assert.Empty(t, out) out, err = runCommand(t, "placement-group", "add-label", "test-placement-group", "foo=bar") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Label(s) foo added to placement group %d\n", pgID), out) out, err = runCommand(t, "placement-group", "add-label", "test-placement-group", "baz=qux") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Label(s) baz added to placement group %d\n", pgID), out) out, err = runCommand(t, "placement-group", "update", "test-placement-group", "--name", "new-test-placement-group") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "placement group test-placement-group updated\n", out) out, err = runCommand(t, "placement-group", "list", "-o=columns=id,name,servers,type,created,age") - assert.NoError(t, err) + require.NoError(t, err) assert.Regexp(t, `ID +NAME +SERVERS +TYPE +CREATED +AGE [0-9]+ +new-test-placement-group +0 servers +spread .*? (?:just now|[0-9]+s) `, out) out, err = runCommand(t, "placement-group", "describe", strconv.Itoa(pgID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Regexp(t, `^ID:\s+[0-9]+ Name:\s+new-test-placement-group Created:\s+.*? @@ -60,7 +61,7 @@ Type:\s+spread $`, out) out, err = runCommand(t, "placement-group", "list", "-o=json") - assert.NoError(t, err) + require.NoError(t, err) assertjson.Equal(t, []byte(fmt.Sprintf(` [ { @@ -77,10 +78,10 @@ $`, out) ]`, pgID)), []byte(out)) out, err = runCommand(t, "placement-group", "remove-label", "new-test-placement-group", "baz") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Label(s) baz removed from placement group %d\n", pgID), out) out, err = runCommand(t, "placement-group", "delete", strconv.Itoa(pgID)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("placement group %d deleted\n", pgID), out) }