From 937c4670b7b714d9a4b04a30201174640b3c111c Mon Sep 17 00:00:00 2001 From: Ayush Rangwala Date: Mon, 20 Nov 2023 20:47:36 +0530 Subject: [PATCH] fix: lint issues Signed-off-by: Ayush Rangwala --- go.mod | 1 + go.sum | 5 +---- test/e2e/gateways/create_test.go | 14 ++++++++------ test/e2e/gateways/delete_test.go | 8 +++++--- test/helper/helper.go | 7 ++++--- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index a1c6cc24..8bed1f21 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/manifoldco/promptui v0.9.0 github.com/olekukonko/tablewriter v0.0.5 github.com/packethost/packngo v0.30.0 + github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.17.0 diff --git a/go.sum b/go.sum index 9d4da4c8..c983254f 100644 --- a/go.sum +++ b/go.sum @@ -159,6 +159,7 @@ github.com/packethost/packngo v0.30.0 h1:JVeTwbXXETsLTDQncUbYwIFpkOp/xevXrffM2Hr github.com/packethost/packngo v0.30.0/go.mod h1:BT/XcdwLVmeMtGPbovnxCpnI1s9ylSE1cs/7pq007NE= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -257,8 +258,6 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -412,8 +411,6 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/test/e2e/gateways/create_test.go b/test/e2e/gateways/create_test.go index 0e93316c..c144d4fd 100644 --- a/test/e2e/gateways/create_test.go +++ b/test/e2e/gateways/create_test.go @@ -27,7 +27,8 @@ func TestGateways_Create(t *testing.T) { device := helper.SetupProjectAndDevice(t, &projectId, &deviceId) t.Cleanup(func() { - if err := helper.CleanupProjectAndDevice(deviceId, projectId); err != nil { + if err := helper.CleanupProjectAndDevice(deviceId, projectId); err != nil && + !strings.Contains(err.Error(), "Not Found") { t.Error(err) } }) @@ -37,7 +38,8 @@ func TestGateways_Create(t *testing.T) { vlan, err := helper.CreateTestVLAN(projectId) t.Cleanup(func() { - if err := helper.CleanTestVlan(vlan.GetId()); err != nil { + if err := helper.CleanTestVlan(vlan.GetId()); err != nil && + !strings.Contains(err.Error(), "Not Found") { t.Error(err) } }) @@ -100,18 +102,18 @@ func TestGateways_Create(t *testing.T) { func assertGatewaysCmdOutput(t *testing.T, out, gatewayId, metro, vxlan string) { if !strings.Contains(out, gatewayId) { - t.Errorf("cmd output should contain ID of the gateway: %s", gatewayId) + t.Errorf("cmd output should contain ID of the gateway: [%s] \n output:\n%s", gatewayId, out) } if !strings.Contains(out, metro) { - t.Errorf("cmd output should contain metro same as device: %s", metro) + t.Errorf("cmd output should contain metro same as device: [%s] \n output:\n%s", metro, out) } if !strings.Contains(out, vxlan) { - t.Errorf("cmd output should contain vxlan, gateway is attached with: %s", vxlan) + t.Errorf("cmd output should contain vxlan, gateway is attached with: [%s] \n output:\n%s", vxlan, out) } if !strings.Contains(out, "ready") { - t.Errorf("cmd output should contain 'ready' state of the gateway") + t.Errorf("cmd output should contain 'ready' state of the gateway, output:\n%s", out) } } diff --git a/test/e2e/gateways/delete_test.go b/test/e2e/gateways/delete_test.go index f02822fe..eb17b862 100644 --- a/test/e2e/gateways/delete_test.go +++ b/test/e2e/gateways/delete_test.go @@ -31,7 +31,8 @@ func TestGateways_Delete(t *testing.T) { }() device := helper.SetupProjectAndDevice(t, &projectId, &deviceId) t.Cleanup(func() { - if err := helper.CleanupProjectAndDevice(deviceId, projectId); err != nil { + if err := helper.CleanupProjectAndDevice(deviceId, projectId); err != nil && + !strings.Contains(err.Error(), "Not Found") { t.Error(err) } }) @@ -41,8 +42,9 @@ func TestGateways_Delete(t *testing.T) { vlan, err := helper.CreateTestVLAN(projectId) t.Cleanup(func() { - if err := helper.CleanTestVlan(vlan.GetId()); err != nil { - t.Error(err) + if err := helper.CleanTestVlan(vlan.GetId()); err != nil && + !strings.Contains(err.Error(), "Not Found") { + t.Error("Error while cleaning up vLan", err) } }) if err != nil { diff --git a/test/helper/helper.go b/test/helper/helper.go index 85b10d2d..ad39935b 100644 --- a/test/helper/helper.go +++ b/test/helper/helper.go @@ -8,6 +8,7 @@ import ( "time" openapiclient "github.com/equinix-labs/metal-go/metal/v1" + "github.com/pkg/errors" ) func TestClient() *openapiclient.APIClient { @@ -159,7 +160,7 @@ func WaitForAttachVlanToPort(portId string, attach bool) error { case <-ticker.C: port, err := GetPortById(portId) if err != nil { - return err + return errors.Wrapf(err, "Error while fetching the port using ID: %s", portId) } vlans := port.GetVirtualNetworks() @@ -327,7 +328,7 @@ func SetupProjectAndDevice(t *testing.T, projectId, deviceId *string) *openapicl return nil } if !active { - t.Fatal("Timeout while waiting for device: %s to be active", *deviceId) + t.Fatalf("Timeout while waiting for device: %s to be active", *deviceId) return nil } @@ -337,7 +338,7 @@ func SetupProjectAndDevice(t *testing.T, projectId, deviceId *string) *openapicl return nil } if len(device.NetworkPorts) < 3 { - t.Fatal("All 3 ports doesnot exist for the created device: %s", device.GetId()) + t.Fatalf("All 3 ports doesnot exist for the created device: %s", device.GetId()) return nil }