From b54937fb4faed44bf26eef2d0818bc6af56b497a Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Mon, 9 Sep 2024 12:18:27 +0200 Subject: [PATCH] fix tests --- internal/cmd/firewall/validation_test.go | 37 ++++++++++++------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/internal/cmd/firewall/validation_test.go b/internal/cmd/firewall/validation_test.go index 99037b3f..1e56695e 100644 --- a/internal/cmd/firewall/validation_test.go +++ b/internal/cmd/firewall/validation_test.go @@ -1,7 +1,6 @@ package firewall_test import ( - "fmt" "testing" "github.com/stretchr/testify/assert" @@ -12,9 +11,9 @@ import ( func TestValidateFirewallIP(t *testing.T) { tests := []struct { - name string - ip string - err error + name string + ip string + errMsg string }{ { name: "Valid CIDR (IPv4)", @@ -25,38 +24,38 @@ func TestValidateFirewallIP(t *testing.T) { ip: "fe80::/128", }, { - name: "Invalid IP", - ip: "test", - err: fmt.Errorf("invalid CIDR address: test"), + name: "Invalid IP", + ip: "test", + errMsg: "invalid CIDR address: test", }, { - name: "Missing CIDR notation (IPv4)", - ip: "10.0.0.0", - err: fmt.Errorf("invalid CIDR address: 10.0.0.0"), + name: "Missing CIDR notation (IPv4)", + ip: "10.0.0.0", + errMsg: "invalid CIDR address: 10.0.0.0", }, { name: "Missing CIDR notation (IPv6)", ip: "fe80::", //nolint:revive - err: fmt.Errorf("invalid CIDR address: fe80::"), + errMsg: "invalid CIDR address: fe80::", }, { - name: "Host bit set (IPv4)", - ip: "10.0.0.5/8", - err: fmt.Errorf("10.0.0.5/8 is not the start of the cidr block 10.0.0.0/8"), + name: "Host bit set (IPv4)", + ip: "10.0.0.5/8", + errMsg: "10.0.0.5/8 is not the start of the cidr block 10.0.0.0/8", }, { - name: "Host bit set (IPv6)", - ip: "fe80::1337/64", - err: fmt.Errorf("fe80::1337/64 is not the start of the cidr block fe80::/64"), + name: "Host bit set (IPv6)", + ip: "fe80::1337/64", + errMsg: "fe80::1337/64 is not the start of the cidr block fe80::/64", }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { net, err := firewall.ValidateFirewallIP(test.ip) - if test.err != nil { - assert.Equal(t, err, test.err) + if test.errMsg != "" { + require.EqualError(t, err, test.errMsg) assert.Nil(t, net) return }