diff --git a/.golangci.yml b/.golangci.yml index 116750dd..e7eb89a4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,86 +1,40 @@ ---- +linters: + presets: + - bugs + - error + - import + - metalinter + - module + - unused + + enable: + - testifylint + + disable: + # preset error + - err113 # Very annoying to define static errors everywhere + - wrapcheck # Very annoying to wrap errors everywhere + # preset import + - depguard + linters-settings: gci: sections: - standard - default - prefix(github.com/hetznercloud) + + gosec: + excludes: + # As of golangci-lint v1.60.3, this rule is still enabled by default, which causes problems. + # We disable it manually for now until a new golangci-lint version is released which fixes this. + # See https://github.com/securego/gosec/issues/1185 + - G115 + exhaustive: + # Switch cases with a default case should be exhaustive. default-signifies-exhaustive: true - gomodguard: - blocked: - modules: - - github.com/tj/assert: - recommendations: - - github.com/stretchr/testify/assert - reason: | - One assertion library is enough and we use testify/assert - everywhere. - - gotest.tools/assert: - recommendations: - - github.com/stretchr/testify/assert - reason: | - One assertion library is enough and we use testify/assert - everywhere. - - github.com/magiconair/properties: - recommendations: - - github.com/stretchr/testify/assert - reason: > - We do not currently need to parse properties files. At the same - time this module has an assert package which tends to get - imported by accident. It is therefore blocked. - - github.com/gogo/protobuf: - recommendations: - - google.golang.org/protobuf - reason: > - This is not the protobuf module that we want to import. - - github.com/golang/protobuf: - recommendations: - - google.golang.org/protobuf - reason: > - This is the legacy import location of Google's protobuf module. - Use the new one instead. - misspell: - locale: "US" - revive: - exported: true - import-shadowing: true - indent-error-flow: true - -linters: - disable-all: true - # Some of these are temporarily disabled until we fix the numerous issues we have. - enable: - - bodyclose - # - dupl - - errcheck - - exhaustive - - gocritic - # - golint - - gci - - gomodguard - - gosec - - gosimple - - govet - - ineffassign - - misspell - - revive - - rowserrcheck - # - scopelint - # - staticcheck - - typecheck - - unparam - - unused - - whitespace -issues: - include: - - EXC0002 # disable excluding of issues about comments from golint - exclude-rules: - - path: _test\.go - linters: - - dupl - - gosec - - linters: - - gosec - text: "G204:" + gosmopolitan: + # We want to allow the use of time.Local() + allow-time-local: true \ No newline at end of file diff --git a/internal/cmd/all/list_test.go b/internal/cmd/all/list_test.go index 501d8293..3357a827 100644 --- a/internal/cmd/all/list_test.go +++ b/internal/cmd/all/list_test.go @@ -8,6 +8,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/all" "github.com/hetznercloud/cli/internal/testutil" @@ -237,7 +238,7 @@ ID NAME FINGERPRINT AGE ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -286,7 +287,7 @@ func TestListAllPaidJSON(t *testing.T) { jsonOut, errOut, err := fx.Run(cmd, []string{"--paid", "-o=json"}) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.JSONEq(t, allListResponseJSON, jsonOut) } diff --git a/internal/cmd/base/update.go b/internal/cmd/base/update.go index 3090bfd4..502b6b24 100644 --- a/internal/cmd/base/update.go +++ b/internal/cmd/base/update.go @@ -66,7 +66,7 @@ func (uc *UpdateCmd) Run(s state.State, cmd *cobra.Command, args []string) error }) if err := uc.Update(s, cmd, resource, flags); err != nil { - return fmt.Errorf("updating %s %s failed: %s", uc.ResourceNameSingular, idOrName, err) + return fmt.Errorf("updating %s %s failed: %w", uc.ResourceNameSingular, idOrName, err) } cmd.Printf("%s %v updated\n", uc.ResourceNameSingular, idOrName) diff --git a/internal/cmd/certificate/create_test.go b/internal/cmd/certificate/create_test.go index fd7c0ecb..2e291feb 100644 --- a/internal/cmd/certificate/create_test.go +++ b/internal/cmd/certificate/create_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/certificate" "github.com/hetznercloud/cli/internal/testutil" @@ -56,7 +57,7 @@ func TestCreateManaged(t *testing.T) { expOut := "Certificate 123 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -124,7 +125,7 @@ func TestCreateManagedJSON(t *testing.T) { expOut := "Certificate 123 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.JSONEq(t, managedCreateResponseJSON, jsonOut) @@ -154,7 +155,7 @@ func TestCreateUploaded(t *testing.T) { expOut := "Certificate 123 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -192,7 +193,7 @@ func TestCreateUploadedJSON(t *testing.T) { expOut := "Certificate 123 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.JSONEq(t, uploadedCreateResponseJSON, jsonOut) } diff --git a/internal/cmd/certificate/delete_test.go b/internal/cmd/certificate/delete_test.go index b48a2cc0..4a651d9a 100644 --- a/internal/cmd/certificate/delete_test.go +++ b/internal/cmd/certificate/delete_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/certificate" "github.com/hetznercloud/cli/internal/testutil" @@ -34,7 +35,7 @@ func TestDelete(t *testing.T) { expOut := "certificate test deleted\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -74,7 +75,7 @@ func TestDeleteMultiple(t *testing.T) { out, errOut, err := fx.Run(cmd, names) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "certificates test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/certificate/describe_test.go b/internal/cmd/certificate/describe_test.go index 59a0e10f..29265201 100644 --- a/internal/cmd/certificate/describe_test.go +++ b/internal/cmd/certificate/describe_test.go @@ -8,6 +8,7 @@ import ( "github.com/dustin/go-humanize" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/certificate" "github.com/hetznercloud/cli/internal/cmd/util" @@ -79,7 +80,7 @@ Used By: util.Datetime(cert.NotValidBefore), humanize.Time(cert.NotValidBefore), util.Datetime(cert.NotValidAfter), humanize.Time(cert.NotValidAfter)) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/certificate/labels_test.go b/internal/cmd/certificate/labels_test.go index bef48546..a66db357 100644 --- a/internal/cmd/certificate/labels_test.go +++ b/internal/cmd/certificate/labels_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/certificate" "github.com/hetznercloud/cli/internal/testutil" @@ -32,7 +33,7 @@ func TestLabelAdd(t *testing.T) { expOut := "Label(s) key added to certificate 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -61,7 +62,7 @@ func TestLabelRemove(t *testing.T) { expOut := "Label(s) key removed from certificate 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/certificate/list_test.go b/internal/cmd/certificate/list_test.go index b117c9af..4d7c0806 100644 --- a/internal/cmd/certificate/list_test.go +++ b/internal/cmd/certificate/list_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/certificate" "github.com/hetznercloud/cli/internal/testutil" @@ -46,7 +47,7 @@ func TestList(t *testing.T) { 123 test managed example.com Wed Aug 20 12:00:00 UTC 2036 20m ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/certificate/retry_test.go b/internal/cmd/certificate/retry_test.go index 58be61d5..00691e60 100644 --- a/internal/cmd/certificate/retry_test.go +++ b/internal/cmd/certificate/retry_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/certificate" "github.com/hetznercloud/cli/internal/testutil" @@ -38,7 +39,7 @@ func TestRetry(t *testing.T) { out, errOut, err := fx.Run(cmd, []string{"123"}) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Retried issuance of certificate my-test-cert\n", out) } diff --git a/internal/cmd/certificate/update_test.go b/internal/cmd/certificate/update_test.go index 4d7c9b5a..12749b7e 100644 --- a/internal/cmd/certificate/update_test.go +++ b/internal/cmd/certificate/update_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/certificate" "github.com/hetznercloud/cli/internal/testutil" @@ -30,7 +31,7 @@ func TestUpdateName(t *testing.T) { expOut := "certificate 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/config/add_test.go b/internal/cmd/config/add_test.go index 8dfece70..3cb0b397 100644 --- a/internal/cmd/config/add_test.go +++ b/internal/cmd/config/add_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" configCmd "github.com/hetznercloud/cli/internal/cmd/config" "github.com/hetznercloud/cli/internal/state/config" @@ -234,7 +235,7 @@ active_context = "test_context" out, errOut, err := fx.Run(cmd, tt.args) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, tt.expErr, errOut) assert.Equal(t, tt.expOut, out) }) diff --git a/internal/cmd/config/get_test.go b/internal/cmd/config/get_test.go index 71d53bbf..6e8ff071 100644 --- a/internal/cmd/config/get_test.go +++ b/internal/cmd/config/get_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" configCmd "github.com/hetznercloud/cli/internal/cmd/config" "github.com/hetznercloud/cli/internal/state/config" @@ -104,9 +105,9 @@ func TestGet(t *testing.T) { out, errOut, err := fx.Run(cmd, append(tt.args, tt.key)) if tt.err == "" { - assert.NoError(t, err) + require.NoError(t, err) } else { - assert.EqualError(t, err, tt.err) + require.EqualError(t, err, tt.err) } assert.Equal(t, tt.expErr, errOut) assert.Equal(t, tt.expOut, out) diff --git a/internal/cmd/config/list_test.go b/internal/cmd/config/list_test.go index 5508637c..da619e35 100644 --- a/internal/cmd/config/list_test.go +++ b/internal/cmd/config/list_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" configCmd "github.com/hetznercloud/cli/internal/cmd/config" "github.com/hetznercloud/cli/internal/state/config" @@ -154,7 +155,7 @@ token super secret token setTestValues(fx.Config) out, errOut, err := fx.Run(cmd, tt.args) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, tt.expErr, errOut) assert.Equal(t, tt.expOut, out) }) diff --git a/internal/cmd/config/remove_test.go b/internal/cmd/config/remove_test.go index ca8baf36..133b3ee0 100644 --- a/internal/cmd/config/remove_test.go +++ b/internal/cmd/config/remove_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" configCmd "github.com/hetznercloud/cli/internal/cmd/config" "github.com/hetznercloud/cli/internal/state/config" @@ -209,9 +210,9 @@ active_context = "test_context" out, errOut, err := fx.Run(cmd, tt.args) if tt.err == "" { - assert.NoError(t, err) + require.NoError(t, err) } else { - assert.EqualError(t, err, tt.err) + require.EqualError(t, err, tt.err) } assert.Equal(t, tt.expErr, errOut) assert.Equal(t, tt.expOut, out) diff --git a/internal/cmd/config/set_test.go b/internal/cmd/config/set_test.go index 9f63774d..76faf501 100644 --- a/internal/cmd/config/set_test.go +++ b/internal/cmd/config/set_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" configCmd "github.com/hetznercloud/cli/internal/cmd/config" "github.com/hetznercloud/cli/internal/state/config" @@ -282,9 +283,9 @@ active_context = "" out, errOut, err := fx.Run(cmd, tt.args) if tt.err == "" { - assert.NoError(t, err) + require.NoError(t, err) } else { - assert.EqualError(t, err, tt.err) + require.EqualError(t, err, tt.err) } assert.Equal(t, tt.expErr, errOut) assert.Equal(t, tt.expOut, out) diff --git a/internal/cmd/config/unset_test.go b/internal/cmd/config/unset_test.go index ff5cbbb6..b85e7eb7 100644 --- a/internal/cmd/config/unset_test.go +++ b/internal/cmd/config/unset_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" configCmd "github.com/hetznercloud/cli/internal/cmd/config" "github.com/hetznercloud/cli/internal/state/config" @@ -275,9 +276,9 @@ active_context = "test_context" out, errOut, err := fx.Run(cmd, tt.args) if tt.err == "" { - assert.NoError(t, err) + require.NoError(t, err) } else { - assert.EqualError(t, err, tt.err) + require.EqualError(t, err, tt.err) } assert.Equal(t, tt.expErr, errOut) assert.Equal(t, tt.expOut, out) diff --git a/internal/cmd/context/active_test.go b/internal/cmd/context/active_test.go index 61caa046..db312be5 100644 --- a/internal/cmd/context/active_test.go +++ b/internal/cmd/context/active_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/context" "github.com/hetznercloud/cli/internal/testutil" @@ -79,9 +80,9 @@ token = "super secret token" out, errOut, err := fx.Run(cmd, tt.args) if tt.err == "" { - assert.NoError(t, err) + require.NoError(t, err) } else { - assert.EqualError(t, err, tt.err) + require.EqualError(t, err, tt.err) } assert.Equal(t, tt.expErr, errOut) assert.Equal(t, tt.expOut, out) diff --git a/internal/cmd/context/create_test.go b/internal/cmd/context/create_test.go index f3467dd5..68795ef7 100644 --- a/internal/cmd/context/create_test.go +++ b/internal/cmd/context/create_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/context" "github.com/hetznercloud/cli/internal/testutil" @@ -109,9 +110,9 @@ Context new-context created and activated out, errOut, err := fx.Run(cmd, tt.args) if tt.err == "" { - assert.NoError(t, err) + require.NoError(t, err) } else { - assert.EqualError(t, err, tt.err) + require.EqualError(t, err, tt.err) } assert.Equal(t, tt.expErr, errOut) assert.Equal(t, tt.expOut, out) diff --git a/internal/cmd/context/delete_test.go b/internal/cmd/context/delete_test.go index fbb5bd3b..4835cf2d 100644 --- a/internal/cmd/context/delete_test.go +++ b/internal/cmd/context/delete_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/context" "github.com/hetznercloud/cli/internal/testutil" @@ -73,9 +74,9 @@ token = "super secret token" out, errOut, err := fx.Run(cmd, tt.args) if tt.err == "" { - assert.NoError(t, err) + require.NoError(t, err) } else { - assert.EqualError(t, err, tt.err) + require.EqualError(t, err, tt.err) } assert.Equal(t, tt.expErr, errOut) assert.Equal(t, tt.expOut, out) diff --git a/internal/cmd/context/list_test.go b/internal/cmd/context/list_test.go index 4e358bbd..0884d2ee 100644 --- a/internal/cmd/context/list_test.go +++ b/internal/cmd/context/list_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/context" "github.com/hetznercloud/cli/internal/testutil" @@ -106,9 +107,9 @@ my-third-context out, errOut, err := fx.Run(cmd, tt.args) if tt.err == "" { - assert.NoError(t, err) + require.NoError(t, err) } else { - assert.EqualError(t, err, tt.err) + require.EqualError(t, err, tt.err) } assert.Equal(t, tt.expErr, errOut) assert.Equal(t, tt.expOut, out) diff --git a/internal/cmd/context/use_test.go b/internal/cmd/context/use_test.go index 1123bf30..40051c7e 100644 --- a/internal/cmd/context/use_test.go +++ b/internal/cmd/context/use_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/context" "github.com/hetznercloud/cli/internal/testutil" @@ -78,9 +79,9 @@ func TestUse(t *testing.T) { out, errOut, err := fx.Run(cmd, tt.args) if tt.err == "" { - assert.NoError(t, err) + require.NoError(t, err) } else { - assert.EqualError(t, err, tt.err) + require.EqualError(t, err, tt.err) } assert.Equal(t, tt.expErr, errOut) assert.Equal(t, tt.expOut, out) diff --git a/internal/cmd/datacenter/describe_test.go b/internal/cmd/datacenter/describe_test.go index c8fc375e..4e5e5a1b 100644 --- a/internal/cmd/datacenter/describe_test.go +++ b/internal/cmd/datacenter/describe_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/datacenter" "github.com/hetznercloud/cli/internal/testutil" @@ -43,7 +44,7 @@ Server Types: No server types ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -116,7 +117,7 @@ Server Types: - ID: 9 Name: cx52 Supported: true Available: false ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/datacenter/list_test.go b/internal/cmd/datacenter/list_test.go index 9164d263..43f2cbd8 100644 --- a/internal/cmd/datacenter/list_test.go +++ b/internal/cmd/datacenter/list_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/datacenter" "github.com/hetznercloud/cli/internal/testutil" @@ -44,7 +45,7 @@ func TestList(t *testing.T) { 4 fsn1-dc14 Falkenstein 1 virtual DC 14 fsn1 ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -77,9 +78,9 @@ func TestListJSON(t *testing.T) { out, errOut, err := fx.Run(cmd, []string{"-o=json"}) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) - assert.JSONEq(t, out, ` + assert.JSONEq(t, ` [ { "id": 4, @@ -101,5 +102,5 @@ func TestListJSON(t *testing.T) { "available": null } } -]`) +]`, out) } diff --git a/internal/cmd/firewall/add_rule.go b/internal/cmd/firewall/add_rule.go index 2c79d2c2..2df06bdf 100644 --- a/internal/cmd/firewall/add_rule.go +++ b/internal/cmd/firewall/add_rule.go @@ -124,7 +124,7 @@ func parseRuleFromArgs(flags *pflag.FlagSet) (*hcloud.FirewallRule, error) { for i, ip := range destinationIPs { n, err := ValidateFirewallIP(ip) if err != nil { - return nil, fmt.Errorf("destination error on index %d: %s", i, err) + return nil, fmt.Errorf("destination error on index %d: %w", i, err) } rule.DestinationIPs = append(rule.DestinationIPs, *n) } @@ -132,7 +132,7 @@ func parseRuleFromArgs(flags *pflag.FlagSet) (*hcloud.FirewallRule, error) { for i, ip := range sourceIPs { n, err := ValidateFirewallIP(ip) if err != nil { - return nil, fmt.Errorf("source ips error on index %d: %s", i, err) + return nil, fmt.Errorf("source ips error on index %d: %w", i, err) } rule.SourceIPs = append(rule.SourceIPs, *n) } diff --git a/internal/cmd/firewall/add_rule_test.go b/internal/cmd/firewall/add_rule_test.go index 1bd05e72..c59097fe 100644 --- a/internal/cmd/firewall/add_rule_test.go +++ b/internal/cmd/firewall/add_rule_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" @@ -47,7 +48,7 @@ func TestAddRule(t *testing.T) { expOut := "Firewall Rules for Firewall 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/firewall/apply_to_resource_test.go b/internal/cmd/firewall/apply_to_resource_test.go index 2116e431..2aed60d0 100644 --- a/internal/cmd/firewall/apply_to_resource_test.go +++ b/internal/cmd/firewall/apply_to_resource_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" @@ -45,7 +46,7 @@ func TestApplyToServer(t *testing.T) { expOut := "Firewall 123 applied to resource\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -81,7 +82,7 @@ func TestApplyToLabelSelector(t *testing.T) { expOut := "Firewall 123 applied to resource\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/firewall/create.go b/internal/cmd/firewall/create.go index 81711673..34a9e282 100644 --- a/internal/cmd/firewall/create.go +++ b/internal/cmd/firewall/create.go @@ -90,7 +90,7 @@ func parseRulesFile(path string) ([]hcloud.FirewallRule, error) { for i, sourceIP := range rule.SourceIPs { _, sourceNet, err := net.ParseCIDR(sourceIP) if err != nil { - return nil, fmt.Errorf("invalid CIDR on index %d : %s", i, err) + return nil, fmt.Errorf("invalid CIDR on index %d : %w", i, err) } sourceNets = append(sourceNets, *sourceNet) } @@ -98,7 +98,7 @@ func parseRulesFile(path string) ([]hcloud.FirewallRule, error) { for i, destIP := range rule.DestinationIPs { _, destNet, err := net.ParseCIDR(destIP) if err != nil { - return nil, fmt.Errorf("invalid CIDR on index %d : %s", i, err) + return nil, fmt.Errorf("invalid CIDR on index %d : %w", i, err) } destNets = append(destNets, *destNet) } diff --git a/internal/cmd/firewall/create_test.go b/internal/cmd/firewall/create_test.go index d317c060..f333925e 100644 --- a/internal/cmd/firewall/create_test.go +++ b/internal/cmd/firewall/create_test.go @@ -8,6 +8,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" @@ -88,7 +89,7 @@ func TestCreate(t *testing.T) { expOut := "Firewall 123 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -135,7 +136,7 @@ func TestCreateJSON(t *testing.T) { expOut := "Firewall 123 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.JSONEq(t, createResponseJSON, jsonOut) } diff --git a/internal/cmd/firewall/delete_rule_test.go b/internal/cmd/firewall/delete_rule_test.go index 297456fd..9833b3fb 100644 --- a/internal/cmd/firewall/delete_rule_test.go +++ b/internal/cmd/firewall/delete_rule_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" @@ -46,7 +47,7 @@ func TestDeleteRule(t *testing.T) { expOut := "Firewall Rules for Firewall 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/firewall/delete_test.go b/internal/cmd/firewall/delete_test.go index f74c2903..b1d243f4 100644 --- a/internal/cmd/firewall/delete_test.go +++ b/internal/cmd/firewall/delete_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" @@ -34,7 +35,7 @@ func TestDelete(t *testing.T) { expOut := "firewall test deleted\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -74,7 +75,7 @@ func TestDeleteMultiple(t *testing.T) { out, errOut, err := fx.Run(cmd, names) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "firewalls test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/firewall/describe_test.go b/internal/cmd/firewall/describe_test.go index 32563384..89368492 100644 --- a/internal/cmd/firewall/describe_test.go +++ b/internal/cmd/firewall/describe_test.go @@ -8,6 +8,7 @@ import ( "github.com/dustin/go-humanize" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/cmd/util" @@ -75,7 +76,7 @@ Applied To: Server Name: myServer `, util.Datetime(fw.Created), humanize.Time(fw.Created)) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/firewall/labels_test.go b/internal/cmd/firewall/labels_test.go index c3015632..cc7d1607 100644 --- a/internal/cmd/firewall/labels_test.go +++ b/internal/cmd/firewall/labels_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" @@ -32,7 +33,7 @@ func TestLabelAdd(t *testing.T) { expOut := "Label(s) key added to firewall 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -61,7 +62,7 @@ func TestLabelRemove(t *testing.T) { expOut := "Label(s) key removed from firewall 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/firewall/list_test.go b/internal/cmd/firewall/list_test.go index 5a0a655f..b3fa2570 100644 --- a/internal/cmd/firewall/list_test.go +++ b/internal/cmd/firewall/list_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" @@ -46,7 +47,7 @@ func TestList(t *testing.T) { 123 test 5 Rules 2 Servers | 0 Label Selectors ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -114,9 +115,9 @@ func TestListJSON(t *testing.T) { out, errOut, err := fx.Run(cmd, []string{"-o=json"}) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) - assert.JSONEq(t, out, ` + assert.JSONEq(t, ` [ { "id": 42, @@ -151,5 +152,5 @@ func TestListJSON(t *testing.T) { } ] } -]`) +]`, out) } diff --git a/internal/cmd/firewall/remove_from_resource_test.go b/internal/cmd/firewall/remove_from_resource_test.go index 2fb78346..e7ffca6d 100644 --- a/internal/cmd/firewall/remove_from_resource_test.go +++ b/internal/cmd/firewall/remove_from_resource_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" @@ -45,7 +46,7 @@ func TestRemoveFromServer(t *testing.T) { expOut := "Firewall 123 removed from resource\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -81,7 +82,7 @@ func TestRemoveFromLabelSelector(t *testing.T) { expOut := "Firewall 123 removed from resource\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/firewall/replace_rules_test.go b/internal/cmd/firewall/replace_rules_test.go index ed4c6264..fead672c 100644 --- a/internal/cmd/firewall/replace_rules_test.go +++ b/internal/cmd/firewall/replace_rules_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" @@ -84,7 +85,7 @@ func TestReplaceRules(t *testing.T) { expOut := "Firewall Rules for Firewall 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/firewall/update_test.go b/internal/cmd/firewall/update_test.go index 8082c5a5..c4efcb3f 100644 --- a/internal/cmd/firewall/update_test.go +++ b/internal/cmd/firewall/update_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/firewall" "github.com/hetznercloud/cli/internal/testutil" @@ -30,7 +31,7 @@ func TestUpdateName(t *testing.T) { expOut := "Firewall 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/firewall/validation.go b/internal/cmd/firewall/validation.go index 0ae7b73f..6f5be2d3 100644 --- a/internal/cmd/firewall/validation.go +++ b/internal/cmd/firewall/validation.go @@ -8,7 +8,7 @@ import ( func ValidateFirewallIP(ip string) (*net.IPNet, error) { i, n, err := net.ParseCIDR(ip) if err != nil { - return nil, fmt.Errorf("%s", err) + return nil, err } if i.String() != n.IP.String() { return nil, fmt.Errorf("%s is not the start of the cidr block %s", ip, n) diff --git a/internal/cmd/firewall/validation_test.go b/internal/cmd/firewall/validation_test.go index d73702d3..99037b3f 100644 --- a/internal/cmd/firewall/validation_test.go +++ b/internal/cmd/firewall/validation_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/firewall" ) @@ -60,7 +61,7 @@ func TestValidateFirewallIP(t *testing.T) { return } - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, net) }) } diff --git a/internal/cmd/floatingip/assign_test.go b/internal/cmd/floatingip/assign_test.go index 04378eea..163771d0 100644 --- a/internal/cmd/floatingip/assign_test.go +++ b/internal/cmd/floatingip/assign_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" @@ -35,7 +36,7 @@ func TestAssign(t *testing.T) { expOut := "Floating IP 123 assigned to server 456\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/floatingip/create_test.go b/internal/cmd/floatingip/create_test.go index ba172428..127aa948 100644 --- a/internal/cmd/floatingip/create_test.go +++ b/internal/cmd/floatingip/create_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" @@ -47,7 +48,7 @@ func TestCreate(t *testing.T) { IPv4: 192.168.2.1 ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -83,7 +84,7 @@ func TestCreateJSON(t *testing.T) { expOut := "Floating IP 123 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.JSONEq(t, createResponseJSON, jsonOut) } @@ -132,7 +133,7 @@ Resource protection enabled for floating IP 123 IPv4: 192.168.2.1 ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/floatingip/delete_test.go b/internal/cmd/floatingip/delete_test.go index c8b84746..c56552e6 100644 --- a/internal/cmd/floatingip/delete_test.go +++ b/internal/cmd/floatingip/delete_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" @@ -34,7 +35,7 @@ func TestDelete(t *testing.T) { expOut := "Floating IP test deleted\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -74,7 +75,7 @@ func TestDeleteMultiple(t *testing.T) { out, errOut, err := fx.Run(cmd, names) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Floating IPs test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/floatingip/describe_test.go b/internal/cmd/floatingip/describe_test.go index e8d820bb..ca88650a 100644 --- a/internal/cmd/floatingip/describe_test.go +++ b/internal/cmd/floatingip/describe_test.go @@ -9,6 +9,7 @@ import ( "github.com/dustin/go-humanize" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/cmd/util" @@ -66,7 +67,7 @@ Labels: key: value `, util.Datetime(floatingIP.Created), humanize.Time(floatingIP.Created)) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/floatingip/disable_protection_test.go b/internal/cmd/floatingip/disable_protection_test.go index da9c1d12..0e449334 100644 --- a/internal/cmd/floatingip/disable_protection_test.go +++ b/internal/cmd/floatingip/disable_protection_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" @@ -34,7 +35,7 @@ func TestDisableProtection(t *testing.T) { expOut := "Resource protection disabled for floating IP 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/floatingip/enable_protection_test.go b/internal/cmd/floatingip/enable_protection_test.go index 7adbe27e..e1dffed3 100644 --- a/internal/cmd/floatingip/enable_protection_test.go +++ b/internal/cmd/floatingip/enable_protection_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" @@ -34,7 +35,7 @@ func TestEnableProtection(t *testing.T) { expOut := "Resource protection enabled for floating IP 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/floatingip/labels_test.go b/internal/cmd/floatingip/labels_test.go index 8a3694cd..a224a795 100644 --- a/internal/cmd/floatingip/labels_test.go +++ b/internal/cmd/floatingip/labels_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" @@ -32,7 +33,7 @@ func TestLabelAdd(t *testing.T) { expOut := "Label(s) key added to Floating IP 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -61,7 +62,7 @@ func TestLabelRemove(t *testing.T) { expOut := "Label(s) key removed from Floating IP 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/floatingip/list_test.go b/internal/cmd/floatingip/list_test.go index f5caa165..f2a5697a 100644 --- a/internal/cmd/floatingip/list_test.go +++ b/internal/cmd/floatingip/list_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" @@ -47,7 +48,7 @@ func TestList(t *testing.T) { 123 ipv4 test - 192.168.2.1 fsn1 - - 10m ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/floatingip/set_rdns_test.go b/internal/cmd/floatingip/set_rdns_test.go index f465d481..c7d7080d 100644 --- a/internal/cmd/floatingip/set_rdns_test.go +++ b/internal/cmd/floatingip/set_rdns_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" @@ -38,7 +39,7 @@ func TestSetRDNS(t *testing.T) { expOut := "Reverse DNS of Floating IP test changed\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/floatingip/unassign_test.go b/internal/cmd/floatingip/unassign_test.go index 65482dbe..ce755ed6 100644 --- a/internal/cmd/floatingip/unassign_test.go +++ b/internal/cmd/floatingip/unassign_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" @@ -32,7 +33,7 @@ func TestUnassign(t *testing.T) { expOut := "Floating IP 123 unassigned\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/floatingip/update_test.go b/internal/cmd/floatingip/update_test.go index 714a6fdd..1590ab36 100644 --- a/internal/cmd/floatingip/update_test.go +++ b/internal/cmd/floatingip/update_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/floatingip" "github.com/hetznercloud/cli/internal/testutil" @@ -30,7 +31,7 @@ func TestUpdateName(t *testing.T) { expOut := "Floating IP 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -54,7 +55,7 @@ func TestUpdateDescription(t *testing.T) { expOut := "Floating IP 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/image/delete_test.go b/internal/cmd/image/delete_test.go index ef40f5d4..c6a0d1ae 100644 --- a/internal/cmd/image/delete_test.go +++ b/internal/cmd/image/delete_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/image" "github.com/hetznercloud/cli/internal/testutil" @@ -34,7 +35,7 @@ func TestDelete(t *testing.T) { expOut := "image 123 deleted\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -71,7 +72,7 @@ func TestDeleteMultiple(t *testing.T) { out, errOut, err := fx.Run(cmd, ids) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "images 123, 456, 789 deleted\n", out) } diff --git a/internal/cmd/image/describe_test.go b/internal/cmd/image/describe_test.go index 30f5f7cd..c56271d9 100644 --- a/internal/cmd/image/describe_test.go +++ b/internal/cmd/image/describe_test.go @@ -8,6 +8,7 @@ import ( "github.com/dustin/go-humanize" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/image" "github.com/hetznercloud/cli/internal/cmd/util" @@ -63,7 +64,7 @@ Labels: key: value `, util.Datetime(img.Created), humanize.Time(img.Created)) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/image/disable_protection_test.go b/internal/cmd/image/disable_protection_test.go index 1812df89..a5b106b2 100644 --- a/internal/cmd/image/disable_protection_test.go +++ b/internal/cmd/image/disable_protection_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/image" "github.com/hetznercloud/cli/internal/testutil" @@ -31,7 +32,7 @@ func TestDisableProtection(t *testing.T) { expOut := "Resource protection disabled for image 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/image/enable_protection_test.go b/internal/cmd/image/enable_protection_test.go index b7cb97b5..75cb811b 100644 --- a/internal/cmd/image/enable_protection_test.go +++ b/internal/cmd/image/enable_protection_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/image" "github.com/hetznercloud/cli/internal/testutil" @@ -31,7 +32,7 @@ func TestEnableProtection(t *testing.T) { expOut := "Resource protection enabled for image 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/image/labels_test.go b/internal/cmd/image/labels_test.go index 47c5d0e7..f9ea050b 100644 --- a/internal/cmd/image/labels_test.go +++ b/internal/cmd/image/labels_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/image" "github.com/hetznercloud/cli/internal/testutil" @@ -32,7 +33,7 @@ func TestLabelAdd(t *testing.T) { expOut := "Label(s) key added to image 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -61,7 +62,7 @@ func TestLabelRemove(t *testing.T) { expOut := "Label(s) key removed from image 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/image/list_test.go b/internal/cmd/image/list_test.go index 9de87e77..9e0a1e5c 100644 --- a/internal/cmd/image/list_test.go +++ b/internal/cmd/image/list_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/image" "github.com/hetznercloud/cli/internal/testutil" @@ -48,7 +49,7 @@ func TestList(t *testing.T) { 123 system test - x86 20.00 GB 15 GB Wed Aug 20 12:00:00 UTC 2036 - ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/image/update.go b/internal/cmd/image/update.go index 5c289b3e..25ba1a25 100644 --- a/internal/cmd/image/update.go +++ b/internal/cmd/image/update.go @@ -33,7 +33,7 @@ var UpdateCmd = base.UpdateCmd{ Update: func(s state.State, _ *cobra.Command, resource interface{}, flags map[string]pflag.Value) error { image := resource.(*hcloud.Image) updOpts := hcloud.ImageUpdateOpts{ - Description: hcloud.String(flags["description"].String()), + Description: hcloud.Ptr(flags["description"].String()), Type: hcloud.ImageType(flags["type"].String()), } _, _, err := s.Client().Image().Update(s, image, updOpts) diff --git a/internal/cmd/image/update_test.go b/internal/cmd/image/update_test.go index 978a212e..ca11117a 100644 --- a/internal/cmd/image/update_test.go +++ b/internal/cmd/image/update_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/image" "github.com/hetznercloud/cli/internal/testutil" @@ -30,7 +31,7 @@ func TestUpdateDescription(t *testing.T) { expOut := "Image 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -55,7 +56,7 @@ func TestUpdateType(t *testing.T) { expOut := "Image 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/iso/describe_test.go b/internal/cmd/iso/describe_test.go index b132425d..a7516627 100644 --- a/internal/cmd/iso/describe_test.go +++ b/internal/cmd/iso/describe_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/iso" "github.com/hetznercloud/cli/internal/testutil" @@ -37,7 +38,7 @@ Type: public Architecture: x86 ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/iso/list_test.go b/internal/cmd/iso/list_test.go index a7295ae8..23c42ddf 100644 --- a/internal/cmd/iso/list_test.go +++ b/internal/cmd/iso/list_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/iso" "github.com/hetznercloud/cli/internal/testutil" @@ -45,7 +46,7 @@ func TestList(t *testing.T) { 123 test Test ISO public x86 ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/add_service.go b/internal/cmd/loadbalancer/add_service.go index 6a9fbac8..803eed04 100644 --- a/internal/cmd/loadbalancer/add_service.go +++ b/internal/cmd/loadbalancer/add_service.go @@ -102,26 +102,26 @@ var AddServiceCmd = base.Cmd{ opts := hcloud.LoadBalancerAddServiceOpts{ Protocol: hcloud.LoadBalancerServiceProtocol(protocol), - Proxyprotocol: hcloud.Bool(proxyProtocol), + Proxyprotocol: &proxyProtocol, } if listenPort != 0 { - opts.ListenPort = hcloud.Int(listenPort) + opts.ListenPort = &listenPort } if destinationPort != 0 { - opts.DestinationPort = hcloud.Int(destinationPort) + opts.DestinationPort = &destinationPort } if protocol != string(hcloud.LoadBalancerServiceProtocolTCP) { opts.HTTP = &hcloud.LoadBalancerAddServiceOptsHTTP{ - StickySessions: hcloud.Bool(httpStickySessions), - RedirectHTTP: hcloud.Bool(httpRedirect), + StickySessions: &httpStickySessions, + RedirectHTTP: &httpRedirect, } if httpCookieName != "" { - opts.HTTP.CookieName = hcloud.String(httpCookieName) + opts.HTTP.CookieName = &httpCookieName } if httpCookieLifetime != 0 { - opts.HTTP.CookieLifetime = hcloud.Duration(httpCookieLifetime) + opts.HTTP.CookieLifetime = &httpCookieLifetime } for _, certificateID := range httpCertificates { opts.HTTP.Certificates = append(opts.HTTP.Certificates, &hcloud.Certificate{ID: certificateID}) diff --git a/internal/cmd/loadbalancer/add_service_test.go b/internal/cmd/loadbalancer/add_service_test.go index 2355fee1..56c76e42 100644 --- a/internal/cmd/loadbalancer/add_service_test.go +++ b/internal/cmd/loadbalancer/add_service_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -42,7 +43,7 @@ func TestAddService(t *testing.T) { expOut := "Service was added to Load Balancer 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -114,7 +115,7 @@ func TestAddServiceWithHealthCheck(t *testing.T) { expOut := "Service was added to Load Balancer 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/add_target.go b/internal/cmd/loadbalancer/add_target.go index 89f55bea..5e506bea 100644 --- a/internal/cmd/loadbalancer/add_target.go +++ b/internal/cmd/loadbalancer/add_target.go @@ -70,7 +70,7 @@ var AddTargetCmd = base.Cmd{ } action, _, err = s.Client().LoadBalancer().AddServerTarget(s, loadBalancer, hcloud.LoadBalancerAddServerTargetOpts{ Server: server, - UsePrivateIP: hcloud.Bool(usePrivateIP), + UsePrivateIP: &usePrivateIP, }) if err != nil { return err @@ -78,7 +78,7 @@ var AddTargetCmd = base.Cmd{ case labelSelector != "": action, _, err = s.Client().LoadBalancer().AddLabelSelectorTarget(s, loadBalancer, hcloud.LoadBalancerAddLabelSelectorTargetOpts{ Selector: labelSelector, - UsePrivateIP: hcloud.Bool(usePrivateIP), + UsePrivateIP: &usePrivateIP, }) if err != nil { return err diff --git a/internal/cmd/loadbalancer/add_target_test.go b/internal/cmd/loadbalancer/add_target_test.go index 201fd4cc..0478bf34 100644 --- a/internal/cmd/loadbalancer/add_target_test.go +++ b/internal/cmd/loadbalancer/add_target_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -39,7 +40,7 @@ func TestAddTargetServer(t *testing.T) { expOut := "Target added to Load Balancer 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -68,7 +69,7 @@ func TestAddTargetLabelSelector(t *testing.T) { expOut := "Target added to Load Balancer 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -96,7 +97,7 @@ func TestAddTargetIP(t *testing.T) { expOut := "Target added to Load Balancer 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/attach_to_network_test.go b/internal/cmd/loadbalancer/attach_to_network_test.go index 310c8457..5d7b7685 100644 --- a/internal/cmd/loadbalancer/attach_to_network_test.go +++ b/internal/cmd/loadbalancer/attach_to_network_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -37,7 +38,7 @@ func TestAttachToNetwork(t *testing.T) { expOut := "Load Balancer 123 attached to network 321\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/change_algorithm_test.go b/internal/cmd/loadbalancer/change_algorithm_test.go index 6d0b55db..51071d11 100644 --- a/internal/cmd/loadbalancer/change_algorithm_test.go +++ b/internal/cmd/loadbalancer/change_algorithm_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -34,7 +35,7 @@ func TestChangeAlgorithm(t *testing.T) { expOut := "Algorithm for Load Balancer 123 was changed\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/change_type_test.go b/internal/cmd/loadbalancer/change_type_test.go index e65298da..4655c23d 100644 --- a/internal/cmd/loadbalancer/change_type_test.go +++ b/internal/cmd/loadbalancer/change_type_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -39,7 +40,7 @@ func TestChangeType(t *testing.T) { expOut := "LoadBalancer 123 changed to type lb21\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/create_test.go b/internal/cmd/loadbalancer/create_test.go index c7138675..efd1a320 100644 --- a/internal/cmd/loadbalancer/create_test.go +++ b/internal/cmd/loadbalancer/create_test.go @@ -8,6 +8,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -57,7 +58,7 @@ IPv4: 192.168.2.1 IPv6: :: ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -107,7 +108,7 @@ func TestCreateJSON(t *testing.T) { expOut := "Load Balancer 123 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.JSONEq(t, createResponseJSON, jsonOut) } @@ -161,7 +162,7 @@ IPv4: 192.168.2.1 IPv6: :: ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/delete_service_test.go b/internal/cmd/loadbalancer/delete_service_test.go index b556cfa6..4ebfd0b2 100644 --- a/internal/cmd/loadbalancer/delete_service_test.go +++ b/internal/cmd/loadbalancer/delete_service_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -29,7 +30,7 @@ func TestDeleteService(t *testing.T) { expOut := "Service on port 80 deleted from Load Balancer 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/delete_test.go b/internal/cmd/loadbalancer/delete_test.go index 07695a4b..e59dbf60 100644 --- a/internal/cmd/loadbalancer/delete_test.go +++ b/internal/cmd/loadbalancer/delete_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -34,7 +35,7 @@ func TestDelete(t *testing.T) { expOut := "Load Balancer test deleted\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -74,7 +75,7 @@ func TestDeleteMultiple(t *testing.T) { out, errOut, err := fx.Run(cmd, names) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Load Balancers test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/loadbalancer/describe_test.go b/internal/cmd/loadbalancer/describe_test.go index ba7a9d16..387457f6 100644 --- a/internal/cmd/loadbalancer/describe_test.go +++ b/internal/cmd/loadbalancer/describe_test.go @@ -9,6 +9,7 @@ import ( "github.com/dustin/go-humanize" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/cmd/util" @@ -95,7 +96,7 @@ Labels: No labels `, util.Datetime(lb.Created), humanize.Time(lb.Created)) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/detach_from_network_test.go b/internal/cmd/loadbalancer/detach_from_network_test.go index 17f78bc0..05e07c55 100644 --- a/internal/cmd/loadbalancer/detach_from_network_test.go +++ b/internal/cmd/loadbalancer/detach_from_network_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -37,7 +38,7 @@ func TestDetachFromNetwork(t *testing.T) { expOut := "Load Balancer 123 detached from Network 321\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/disable_protection_test.go b/internal/cmd/loadbalancer/disable_protection_test.go index 3211b58e..5d7cb26a 100644 --- a/internal/cmd/loadbalancer/disable_protection_test.go +++ b/internal/cmd/loadbalancer/disable_protection_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -34,7 +35,7 @@ func TestDisableProtection(t *testing.T) { expOut := "Resource protection disabled for Load Balancer 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/disable_public_interface_test.go b/internal/cmd/loadbalancer/disable_public_interface_test.go index a80ca898..f38923b5 100644 --- a/internal/cmd/loadbalancer/disable_public_interface_test.go +++ b/internal/cmd/loadbalancer/disable_public_interface_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -32,7 +33,7 @@ func TestDisablePublicInterface(t *testing.T) { expOut := "Public interface of Load Balancer 123 was disabled\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/enable_protection_test.go b/internal/cmd/loadbalancer/enable_protection_test.go index 6f272eb1..eff775fe 100644 --- a/internal/cmd/loadbalancer/enable_protection_test.go +++ b/internal/cmd/loadbalancer/enable_protection_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -34,7 +35,7 @@ func TestEnableProtection(t *testing.T) { expOut := "Resource protection enabled for Load Balancer 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/enable_public_interface_test.go b/internal/cmd/loadbalancer/enable_public_interface_test.go index 50b49b81..2aa1ea4a 100644 --- a/internal/cmd/loadbalancer/enable_public_interface_test.go +++ b/internal/cmd/loadbalancer/enable_public_interface_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -32,7 +33,7 @@ func TestEnablePublicInterface(t *testing.T) { expOut := "Public interface of Load Balancer 123 was enabled\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/labels_test.go b/internal/cmd/loadbalancer/labels_test.go index 1dbce67a..419b93c1 100644 --- a/internal/cmd/loadbalancer/labels_test.go +++ b/internal/cmd/loadbalancer/labels_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -32,7 +33,7 @@ func TestLabelAdd(t *testing.T) { expOut := "Label(s) key added to Load Balancer 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -61,7 +62,7 @@ func TestLabelRemove(t *testing.T) { expOut := "Label(s) key removed from Load Balancer 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/list.go b/internal/cmd/loadbalancer/list.go index a333160c..ee9ed869 100644 --- a/internal/cmd/loadbalancer/list.go +++ b/internal/cmd/loadbalancer/list.go @@ -109,7 +109,7 @@ func Health(l *hcloud.LoadBalancer) string { case hcloud.LoadBalancerTargetHealthStatusStatusUnhealthy: unhealthyCount++ - default: + case hcloud.LoadBalancerTargetHealthStatusStatusUnknown: unknownCount++ } } diff --git a/internal/cmd/loadbalancer/metrics_test.go b/internal/cmd/loadbalancer/metrics_test.go index 8514b4c0..17ecdd1a 100644 --- a/internal/cmd/loadbalancer/metrics_test.go +++ b/internal/cmd/loadbalancer/metrics_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -94,7 +95,7 @@ func TestMetrics(t *testing.T) { ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/remove_target_test.go b/internal/cmd/loadbalancer/remove_target_test.go index 1a2a47ce..7e656296 100644 --- a/internal/cmd/loadbalancer/remove_target_test.go +++ b/internal/cmd/loadbalancer/remove_target_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -36,7 +37,7 @@ func TestRemoveTargetServer(t *testing.T) { expOut := "Target removed from Load Balancer 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -62,7 +63,7 @@ func TestRemoveTargetLabelSelector(t *testing.T) { expOut := "Target removed from Load Balancer 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -88,7 +89,7 @@ func TestRemoveTargetIP(t *testing.T) { expOut := "Target removed from Load Balancer 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/set_rdns_test.go b/internal/cmd/loadbalancer/set_rdns_test.go index 1ffa96d7..d98c6163 100644 --- a/internal/cmd/loadbalancer/set_rdns_test.go +++ b/internal/cmd/loadbalancer/set_rdns_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -42,7 +43,7 @@ func TestSetRDNS(t *testing.T) { expOut := "Reverse DNS of Load Balancer test changed\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/update_service.go b/internal/cmd/loadbalancer/update_service.go index 919b89fc..43e7bd48 100644 --- a/internal/cmd/loadbalancer/update_service.go +++ b/internal/cmd/loadbalancer/update_service.go @@ -84,24 +84,24 @@ var UpdateServiceCmd = base.Cmd{ } if cmd.Flag("proxy-protocol").Changed { proxyProtocol, _ := cmd.Flags().GetBool("proxy-protocol") - opts.Proxyprotocol = hcloud.Bool(proxyProtocol) + opts.Proxyprotocol = &proxyProtocol } // HTTP if cmd.Flag("http-redirect-http").Changed { redirectHTTP, _ := cmd.Flags().GetBool("http-redirect-http") - opts.HTTP.RedirectHTTP = hcloud.Bool(redirectHTTP) + opts.HTTP.RedirectHTTP = &redirectHTTP } if cmd.Flag("http-sticky-sessions").Changed { stickySessions, _ := cmd.Flags().GetBool("http-sticky-sessions") - opts.HTTP.StickySessions = hcloud.Bool(stickySessions) + opts.HTTP.StickySessions = &stickySessions } if cmd.Flag("http-cookie-name").Changed { cookieName, _ := cmd.Flags().GetString("http-cookie-name") - opts.HTTP.CookieName = hcloud.String(cookieName) + opts.HTTP.CookieName = &cookieName } if cmd.Flag("http-cookie-lifetime").Changed { cookieLifetime, _ := cmd.Flags().GetDuration("http-cookie-lifetime") - opts.HTTP.CookieLifetime = hcloud.Duration(cookieLifetime) + opts.HTTP.CookieLifetime = &cookieLifetime } if cmd.Flag("http-certificates").Changed { certificates, _ := cmd.Flags().GetInt64Slice("http-certificates") @@ -116,19 +116,19 @@ var UpdateServiceCmd = base.Cmd{ } if cmd.Flag("health-check-port").Changed { healthCheckPort, _ := cmd.Flags().GetInt("health-check-port") - opts.HealthCheck.Port = hcloud.Int(healthCheckPort) + opts.HealthCheck.Port = &healthCheckPort } if cmd.Flag("health-check-interval").Changed { healthCheckInterval, _ := cmd.Flags().GetDuration("health-check-interval") - opts.HealthCheck.Interval = hcloud.Duration(healthCheckInterval) + opts.HealthCheck.Interval = &healthCheckInterval } if cmd.Flag("health-check-timeout").Changed { healthCheckTimeout, _ := cmd.Flags().GetDuration("health-check-timeout") - opts.HealthCheck.Timeout = hcloud.Duration(healthCheckTimeout) + opts.HealthCheck.Timeout = &healthCheckTimeout } if cmd.Flag("health-check-retries").Changed { healthCheckRetries, _ := cmd.Flags().GetInt("health-check-retries") - opts.HealthCheck.Retries = hcloud.Int(healthCheckRetries) + opts.HealthCheck.Retries = &healthCheckRetries } // Health Check HTTP @@ -138,15 +138,15 @@ var UpdateServiceCmd = base.Cmd{ if cmd.Flag("health-check-http-domain").Changed { healthCheckHTTPDomain, _ := cmd.Flags().GetString("health-check-http-domain") - opts.HealthCheck.HTTP.Domain = hcloud.String(healthCheckHTTPDomain) + opts.HealthCheck.HTTP.Domain = &healthCheckHTTPDomain } if cmd.Flag("health-check-http-path").Changed { healthCheckHTTPPath, _ := cmd.Flags().GetString("health-check-http-path") - opts.HealthCheck.HTTP.Path = hcloud.String(healthCheckHTTPPath) + opts.HealthCheck.HTTP.Path = &healthCheckHTTPPath } if cmd.Flag("health-check-http-response").Changed { healthCheckHTTPResponse, _ := cmd.Flags().GetString("health-check-http-response") - opts.HealthCheck.HTTP.Response = hcloud.String(healthCheckHTTPResponse) + opts.HealthCheck.HTTP.Response = &healthCheckHTTPResponse } if cmd.Flag("health-check-http-status-codes").Changed { healthCheckHTTPStatusCodes, _ := cmd.Flags().GetStringSlice("health-check-http-status-codes") @@ -154,7 +154,7 @@ var UpdateServiceCmd = base.Cmd{ } if cmd.Flag("health-check-http-tls").Changed { healthCheckHTTPTLS, _ := cmd.Flags().GetBool("health-check-http-tls") - opts.HealthCheck.HTTP.TLS = hcloud.Bool(healthCheckHTTPTLS) + opts.HealthCheck.HTTP.TLS = &healthCheckHTTPTLS } } diff --git a/internal/cmd/loadbalancer/update_service_test.go b/internal/cmd/loadbalancer/update_service_test.go index 870f9d1a..6cc1b2b8 100644 --- a/internal/cmd/loadbalancer/update_service_test.go +++ b/internal/cmd/loadbalancer/update_service_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -79,7 +80,7 @@ func TestUpdateService(t *testing.T) { expOut := "Service 80 on Load Balancer 123 was updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancer/update_test.go b/internal/cmd/loadbalancer/update_test.go index 947b40bf..86901414 100644 --- a/internal/cmd/loadbalancer/update_test.go +++ b/internal/cmd/loadbalancer/update_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancer" "github.com/hetznercloud/cli/internal/testutil" @@ -30,7 +31,7 @@ func TestUpdateName(t *testing.T) { expOut := "Load Balancer 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancertype/describe_test.go b/internal/cmd/loadbalancertype/describe_test.go index be9e7243..d7fc6ce2 100644 --- a/internal/cmd/loadbalancertype/describe_test.go +++ b/internal/cmd/loadbalancertype/describe_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancertype" "github.com/hetznercloud/cli/internal/testutil" @@ -98,7 +99,7 @@ Pricings per Location: ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/loadbalancertype/list_test.go b/internal/cmd/loadbalancertype/list_test.go index f384dee3..1e28a6f3 100644 --- a/internal/cmd/loadbalancertype/list_test.go +++ b/internal/cmd/loadbalancertype/list_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/loadbalancertype" "github.com/hetznercloud/cli/internal/testutil" @@ -45,7 +46,7 @@ func TestList(t *testing.T) { 123 test - 12 100 5 ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/location/describe_test.go b/internal/cmd/location/describe_test.go index 05931399..0c75d46f 100644 --- a/internal/cmd/location/describe_test.go +++ b/internal/cmd/location/describe_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/location" "github.com/hetznercloud/cli/internal/testutil" @@ -43,7 +44,7 @@ Latitude: 60.169855 Longitude: 24.938379 ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/location/list_test.go b/internal/cmd/location/list_test.go index 4d4d385c..9fc67b26 100644 --- a/internal/cmd/location/list_test.go +++ b/internal/cmd/location/list_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/location" "github.com/hetznercloud/cli/internal/testutil" @@ -45,7 +46,7 @@ func TestList(t *testing.T) { 1 fsn1 - eu-central DE Falkenstein ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/network/add_route_test.go b/internal/cmd/network/add_route_test.go index edc69991..469c3fa6 100644 --- a/internal/cmd/network/add_route_test.go +++ b/internal/cmd/network/add_route_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" @@ -41,7 +42,7 @@ func TestAddRoute(t *testing.T) { expOut := "Route added to network 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.Empty(t, errOut) } diff --git a/internal/cmd/network/add_subnet_test.go b/internal/cmd/network/add_subnet_test.go index 71dedef5..b99a9a5a 100644 --- a/internal/cmd/network/add_subnet_test.go +++ b/internal/cmd/network/add_subnet_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" @@ -42,7 +43,7 @@ func TestAddSubnet(t *testing.T) { expOut := "Subnet added to network 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.Empty(t, errOut) } diff --git a/internal/cmd/network/change_ip_range_test.go b/internal/cmd/network/change_ip_range_test.go index d2321c60..6a0c8b92 100644 --- a/internal/cmd/network/change_ip_range_test.go +++ b/internal/cmd/network/change_ip_range_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" @@ -38,7 +39,7 @@ func TestChangeIPRange(t *testing.T) { expOut := "IP range of network 123 changed\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.Empty(t, errOut) } diff --git a/internal/cmd/network/create_test.go b/internal/cmd/network/create_test.go index eb5b8140..3b139f8f 100644 --- a/internal/cmd/network/create_test.go +++ b/internal/cmd/network/create_test.go @@ -8,6 +8,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" @@ -41,7 +42,7 @@ func TestCreate(t *testing.T) { expOut := "Network 123 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -77,7 +78,7 @@ func TestCreateJSON(t *testing.T) { expOut := "Network 123 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.JSONEq(t, createResponseJSON, jsonOut) } @@ -116,7 +117,7 @@ func TestCreateProtection(t *testing.T) { Resource protection enabled for network 123 ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/network/delete_test.go b/internal/cmd/network/delete_test.go index a563538c..f6a80be8 100644 --- a/internal/cmd/network/delete_test.go +++ b/internal/cmd/network/delete_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" @@ -34,7 +35,7 @@ func TestDelete(t *testing.T) { expOut := "Network test deleted\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -74,7 +75,7 @@ func TestDeleteMultiple(t *testing.T) { out, errOut, err := fx.Run(cmd, names) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Networks test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/network/describe_test.go b/internal/cmd/network/describe_test.go index 2e79726d..9c63f8d3 100644 --- a/internal/cmd/network/describe_test.go +++ b/internal/cmd/network/describe_test.go @@ -9,6 +9,7 @@ import ( "github.com/dustin/go-humanize" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/cmd/util" @@ -55,7 +56,7 @@ Labels: key: value `, util.Datetime(n.Created), humanize.Time(n.Created)) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/network/disable_protection_test.go b/internal/cmd/network/disable_protection_test.go index a4b1c558..7702cf35 100644 --- a/internal/cmd/network/disable_protection_test.go +++ b/internal/cmd/network/disable_protection_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" @@ -35,7 +36,7 @@ func TestDisableProtection(t *testing.T) { args := []string{"myNetwork", "delete"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Resource protection disabled for network 123\n", out) } diff --git a/internal/cmd/network/enable_protection_test.go b/internal/cmd/network/enable_protection_test.go index 58601b90..8ea5487f 100644 --- a/internal/cmd/network/enable_protection_test.go +++ b/internal/cmd/network/enable_protection_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" @@ -35,7 +36,7 @@ func TestEnableProtection(t *testing.T) { args := []string{"myNetwork", "delete"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Resource protection enabled for network 123\n", out) } diff --git a/internal/cmd/network/expose_routes_to_vswitch_test.go b/internal/cmd/network/expose_routes_to_vswitch_test.go index 1e9a7b03..e6e3df6c 100644 --- a/internal/cmd/network/expose_routes_to_vswitch_test.go +++ b/internal/cmd/network/expose_routes_to_vswitch_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" @@ -32,7 +33,7 @@ func TestExposeRoutesToVSwitchEnable(t *testing.T) { args := []string{"123"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Exposing routes to connected vSwitch of network myNetwork enabled\n", out) } @@ -58,7 +59,7 @@ func TestExposeRoutesToVSwitchDisable(t *testing.T) { args := []string{"123", "--disable"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Exposing routes to connected vSwitch of network myNetwork disabled\n", out) } diff --git a/internal/cmd/network/labels_test.go b/internal/cmd/network/labels_test.go index 0eca123f..65eb2a2f 100644 --- a/internal/cmd/network/labels_test.go +++ b/internal/cmd/network/labels_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" @@ -32,7 +33,7 @@ func TestLabelAdd(t *testing.T) { expOut := "Label(s) key added to Network 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -61,7 +62,7 @@ func TestLabelRemove(t *testing.T) { expOut := "Label(s) key removed from Network 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/network/list_test.go b/internal/cmd/network/list_test.go index ee2518a4..5ff50d82 100644 --- a/internal/cmd/network/list_test.go +++ b/internal/cmd/network/list_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" @@ -48,7 +49,7 @@ func TestList(t *testing.T) { 123 test-net 192.0.2.1/24 1 server 10s ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/network/remove_route_test.go b/internal/cmd/network/remove_route_test.go index df2fb1d1..8d4bd564 100644 --- a/internal/cmd/network/remove_route_test.go +++ b/internal/cmd/network/remove_route_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" @@ -41,7 +42,7 @@ func TestRemoveRoute(t *testing.T) { expOut := "Route removed from network 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.Empty(t, errOut) } diff --git a/internal/cmd/network/remove_subnet_test.go b/internal/cmd/network/remove_subnet_test.go index 5915fa92..a5e13875 100644 --- a/internal/cmd/network/remove_subnet_test.go +++ b/internal/cmd/network/remove_subnet_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" @@ -40,7 +41,7 @@ func TestRemoveSubnet(t *testing.T) { expOut := "Subnet 10.0.0.0/24 removed from network 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.Empty(t, errOut) } diff --git a/internal/cmd/network/update_test.go b/internal/cmd/network/update_test.go index bf4c4720..91aac231 100644 --- a/internal/cmd/network/update_test.go +++ b/internal/cmd/network/update_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/network" "github.com/hetznercloud/cli/internal/testutil" @@ -30,7 +31,7 @@ func TestUpdateName(t *testing.T) { expOut := "Network 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/placementgroup/create_test.go b/internal/cmd/placementgroup/create_test.go index 00643910..c4dbd080 100644 --- a/internal/cmd/placementgroup/create_test.go +++ b/internal/cmd/placementgroup/create_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/placementgroup" "github.com/hetznercloud/cli/internal/testutil" @@ -49,7 +50,7 @@ func TestCreate(t *testing.T) { expOut := `Placement group 897 created ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -90,7 +91,7 @@ func TestCreateJSON(t *testing.T) { expOut := "Placement group 897 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.JSONEq(t, createResponseJSON, jsonOut) } diff --git a/internal/cmd/placementgroup/delete_test.go b/internal/cmd/placementgroup/delete_test.go index 647fbb73..7f584b9d 100644 --- a/internal/cmd/placementgroup/delete_test.go +++ b/internal/cmd/placementgroup/delete_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/placementgroup" "github.com/hetznercloud/cli/internal/testutil" @@ -38,7 +39,7 @@ func TestDelete(t *testing.T) { expOut := "placement group my Placement Group deleted\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -78,7 +79,7 @@ func TestDeleteMultiple(t *testing.T) { out, errOut, err := fx.Run(cmd, names) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "placement groups test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/placementgroup/describe_test.go b/internal/cmd/placementgroup/describe_test.go index 11945785..171f87c0 100644 --- a/internal/cmd/placementgroup/describe_test.go +++ b/internal/cmd/placementgroup/describe_test.go @@ -8,6 +8,7 @@ import ( "github.com/dustin/go-humanize" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/placementgroup" "github.com/hetznercloud/cli/internal/cmd/util" @@ -58,7 +59,7 @@ Servers: Type: spread `, util.Datetime(placementGroup.Created), humanize.Time(placementGroup.Created)) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/placementgroup/labels_test.go b/internal/cmd/placementgroup/labels_test.go index c727551a..ec487c15 100644 --- a/internal/cmd/placementgroup/labels_test.go +++ b/internal/cmd/placementgroup/labels_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/placementgroup" "github.com/hetznercloud/cli/internal/testutil" @@ -32,7 +33,7 @@ func TestLabelAdd(t *testing.T) { expOut := "Label(s) key added to placement group 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -61,7 +62,7 @@ func TestLabelRemove(t *testing.T) { expOut := "Label(s) key removed from placement group 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/placementgroup/list_test.go b/internal/cmd/placementgroup/list_test.go index 513b33c4..d5fc09b8 100644 --- a/internal/cmd/placementgroup/list_test.go +++ b/internal/cmd/placementgroup/list_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/placementgroup" "github.com/hetznercloud/cli/internal/testutil" @@ -47,7 +48,7 @@ func TestList(t *testing.T) { 897 my Placement Group 2 servers spread 10s ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/placementgroup/update_test.go b/internal/cmd/placementgroup/update_test.go index 1d9f48f4..47e1ae24 100644 --- a/internal/cmd/placementgroup/update_test.go +++ b/internal/cmd/placementgroup/update_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/placementgroup" "github.com/hetznercloud/cli/internal/testutil" @@ -30,7 +31,7 @@ func TestUpdateName(t *testing.T) { expOut := "placement group 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/primaryip/assign_test.go b/internal/cmd/primaryip/assign_test.go index 000d7db5..aeda55f1 100644 --- a/internal/cmd/primaryip/assign_test.go +++ b/internal/cmd/primaryip/assign_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" @@ -60,7 +61,7 @@ func TestAssign(t *testing.T) { expOut := "Primary IP 13 assigned to server 15\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/primaryip/create_test.go b/internal/cmd/primaryip/create_test.go index 11af3c7c..99abefc8 100644 --- a/internal/cmd/primaryip/create_test.go +++ b/internal/cmd/primaryip/create_test.go @@ -8,6 +8,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" @@ -55,7 +56,7 @@ func TestCreate(t *testing.T) { IPv4: 192.168.2.1 ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -108,7 +109,7 @@ func TestCreateJSON(t *testing.T) { expOut := "Primary IP 1 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.JSONEq(t, createResponseJSON, jsonOut) } diff --git a/internal/cmd/primaryip/delete_test.go b/internal/cmd/primaryip/delete_test.go index ee19d549..b4cd1a93 100644 --- a/internal/cmd/primaryip/delete_test.go +++ b/internal/cmd/primaryip/delete_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" @@ -42,7 +43,7 @@ func TestDelete(t *testing.T) { expOut := "Primary IP 13 deleted\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -82,7 +83,7 @@ func TestDeleteMultiple(t *testing.T) { out, errOut, err := fx.Run(cmd, names) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Primary IPs test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/primaryip/describe_test.go b/internal/cmd/primaryip/describe_test.go index f01c1673..c6b0381f 100644 --- a/internal/cmd/primaryip/describe_test.go +++ b/internal/cmd/primaryip/describe_test.go @@ -9,6 +9,7 @@ import ( "github.com/dustin/go-humanize" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/cmd/util" @@ -71,7 +72,7 @@ Datacenter: Longitude: 0.000000 `, util.Datetime(primaryIP.Created), humanize.Time(primaryIP.Created)) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/primaryip/disable_protection_test.go b/internal/cmd/primaryip/disable_protection_test.go index 531bfd13..4fc44742 100644 --- a/internal/cmd/primaryip/disable_protection_test.go +++ b/internal/cmd/primaryip/disable_protection_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" @@ -48,7 +49,7 @@ func TestDisableProtection(t *testing.T) { expOut := "Resource protection disabled for primary IP 13\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -78,7 +79,7 @@ func TestDisableDeleteProtection(t *testing.T) { expOut := "Resource protection disabled for primary IP 13\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/primaryip/enable_protection_test.go b/internal/cmd/primaryip/enable_protection_test.go index 559d98f1..588a1803 100644 --- a/internal/cmd/primaryip/enable_protection_test.go +++ b/internal/cmd/primaryip/enable_protection_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" @@ -48,7 +49,7 @@ func TestEnableProtection(t *testing.T) { expOut := "Resource protection enabled for primary IP 13\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -77,7 +78,7 @@ func TestEnableDeleteProtection(t *testing.T) { expOut := "Resource protection enabled for primary IP 13\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/primaryip/labels_test.go b/internal/cmd/primaryip/labels_test.go index 9057feb5..48910f09 100644 --- a/internal/cmd/primaryip/labels_test.go +++ b/internal/cmd/primaryip/labels_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" @@ -32,7 +33,7 @@ func TestLabelAdd(t *testing.T) { expOut := "Label(s) key added to primary-ip 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -61,7 +62,7 @@ func TestLabelRemove(t *testing.T) { expOut := "Label(s) key removed from primary-ip 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/primaryip/list_test.go b/internal/cmd/primaryip/list_test.go index 85710fb6..fece94d9 100644 --- a/internal/cmd/primaryip/list_test.go +++ b/internal/cmd/primaryip/list_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" @@ -49,7 +50,7 @@ func TestList(t *testing.T) { 123 ipv4 test-net 127.0.0.1 - - yes 10s ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/primaryip/set_rdns_test.go b/internal/cmd/primaryip/set_rdns_test.go index 447f7258..fd1ee6c6 100644 --- a/internal/cmd/primaryip/set_rdns_test.go +++ b/internal/cmd/primaryip/set_rdns_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" @@ -48,7 +49,7 @@ func TestSetRDNS(t *testing.T) { expOut := "Reverse DNS of Primary IP 13 changed\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/primaryip/unassign_test.go b/internal/cmd/primaryip/unassign_test.go index f50d8595..52712d16 100644 --- a/internal/cmd/primaryip/unassign_test.go +++ b/internal/cmd/primaryip/unassign_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" @@ -45,7 +46,7 @@ func TestUnAssign(t *testing.T) { expOut := "Primary IP 13 was unassigned successfully\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/primaryip/update_test.go b/internal/cmd/primaryip/update_test.go index ba198787..02c03d4b 100644 --- a/internal/cmd/primaryip/update_test.go +++ b/internal/cmd/primaryip/update_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/primaryip" "github.com/hetznercloud/cli/internal/testutil" @@ -31,7 +32,7 @@ func TestUpdateName(t *testing.T) { expOut := "Primary IP 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -55,7 +56,7 @@ func TestUpdateAutoDelete(t *testing.T) { expOut := "Primary IP 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/server/add_to_placement_group_test.go b/internal/cmd/server/add_to_placement_group_test.go index 2515b8ef..c63766e5 100644 --- a/internal/cmd/server/add_to_placement_group_test.go +++ b/internal/cmd/server/add_to_placement_group_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -44,7 +45,7 @@ func TestAddToPlacementGroup(t *testing.T) { expOut := `Server 42 added to placement group my Placement Group ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/server/attach_iso_test.go b/internal/cmd/server/attach_iso_test.go index b7794b92..69859ad4 100644 --- a/internal/cmd/server/attach_iso_test.go +++ b/internal/cmd/server/attach_iso_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -37,7 +38,7 @@ func TestAttachISO(t *testing.T) { args := []string{"my-server", "my-iso"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "ISO my-iso attached to server 123\n", out) } diff --git a/internal/cmd/server/attach_to_network_test.go b/internal/cmd/server/attach_to_network_test.go index cfdfc609..c27e82e7 100644 --- a/internal/cmd/server/attach_to_network_test.go +++ b/internal/cmd/server/attach_to_network_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -45,7 +46,7 @@ func TestAttachToNetwork(t *testing.T) { args := []string{"my-server", "--network", "my-network", "--ip", "192.168.0.1", "--alias-ips", "10.0.1.2,10.0.1.3"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Server 123 attached to network 456\n", out) } diff --git a/internal/cmd/server/change_alias_ips_test.go b/internal/cmd/server/change_alias_ips_test.go index cf092349..465e0e16 100644 --- a/internal/cmd/server/change_alias_ips_test.go +++ b/internal/cmd/server/change_alias_ips_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -44,7 +45,7 @@ func TestChangeAliasIPs(t *testing.T) { args := []string{"my-server", "--network", "my-network", "--alias-ips", "10.0.1.2,10.0.1.3"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Alias IPs changed for server 123 in network 456\n", out) } diff --git a/internal/cmd/server/change_type_test.go b/internal/cmd/server/change_type_test.go index 7f620ca2..2b52dbb6 100644 --- a/internal/cmd/server/change_type_test.go +++ b/internal/cmd/server/change_type_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -40,7 +41,7 @@ func TestChangeType(t *testing.T) { args := []string{"my-server", "cax21"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Server 123 changed to type cax21\n", out) } @@ -74,7 +75,7 @@ func TestChangeTypeKeepDisk(t *testing.T) { args := []string{"my-server", "cax21", "--keep-disk"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Server 123 changed to type cax21 (disk size was unchanged)\n", out) } diff --git a/internal/cmd/server/create.go b/internal/cmd/server/create.go index 45b3ce01..c5f1813a 100644 --- a/internal/cmd/server/create.go +++ b/internal/cmd/server/create.go @@ -3,8 +3,9 @@ package server import ( "bytes" "encoding/base64" + "errors" "fmt" - "io/ioutil" + "io" "mime/multipart" "net/textproto" "os" @@ -200,9 +201,9 @@ func buildUserData(files []string) (string, error) { err error ) if file == "-" { - data, err = ioutil.ReadAll(os.Stdin) + data, err = io.ReadAll(os.Stdin) } else { - data, err = ioutil.ReadFile(file) + data, err = os.ReadFile(file) } if err != nil { return "", err @@ -219,11 +220,11 @@ func buildUserData(files []string) (string, error) { w, err := mp.CreatePart(header) if err != nil { - return "", fmt.Errorf("failed to create multipart for file %q: %s", file, err) + return "", fmt.Errorf("failed to create multipart for file %q: %w", file, err) } if _, err := base64.NewEncoder(base64.StdEncoding, w).Write(data); err != nil { - return "", fmt.Errorf("failed to encode data for file %q: %s", file, err) + return "", fmt.Errorf("failed to encode data for file %q: %w", file, err) } } @@ -339,9 +340,9 @@ func createOptsFromFlags( if len(userDataFiles) == 1 { var data []byte if userDataFiles[0] == "-" { - data, err = ioutil.ReadAll(os.Stdin) + data, err = io.ReadAll(os.Stdin) } else { - data, err = ioutil.ReadFile(userDataFiles[0]) + data, err = os.ReadFile(userDataFiles[0]) } if err != nil { return @@ -452,21 +453,21 @@ func getSSHKeyForFingerprint( publicKey ssh.PublicKey ) - if fileContent, err = ioutil.ReadFile(file); err == os.ErrNotExist { + if fileContent, err = os.ReadFile(file); errors.Is(err, os.ErrNotExist) { err = nil return } else if err != nil { - err = fmt.Errorf("lookup SSH key by fingerprint: %v", err) + err = fmt.Errorf("lookup SSH key by fingerprint: %w", err) return } if publicKey, _, _, _, err = ssh.ParseAuthorizedKey(fileContent); err != nil { - err = fmt.Errorf("lookup SSH key by fingerprint: %v", err) + err = fmt.Errorf("lookup SSH key by fingerprint: %w", err) return } sshKey, _, err = s.Client().SSHKey().GetByFingerprint(s, ssh.FingerprintLegacyMD5(publicKey)) if err != nil { - err = fmt.Errorf("lookup SSH key by fingerprint: %v", err) + err = fmt.Errorf("lookup SSH key by fingerprint: %w", err) return } if sshKey == nil { diff --git a/internal/cmd/server/create_image_test.go b/internal/cmd/server/create_image_test.go index 8f41563b..70d4d483 100644 --- a/internal/cmd/server/create_image_test.go +++ b/internal/cmd/server/create_image_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -40,7 +41,7 @@ func TestCreateImage(t *testing.T) { args := []string{"my-server", "--type", "snapshot", "--description", "my-snapshot"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Image 456 created from server 123\n", out) } diff --git a/internal/cmd/server/create_test.go b/internal/cmd/server/create_test.go index cd573178..c50c687e 100644 --- a/internal/cmd/server/create_test.go +++ b/internal/cmd/server/create_test.go @@ -9,6 +9,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -100,7 +101,7 @@ func TestCreate(t *testing.T) { args := []string{"--name", "cli-test", "--type", "cx22", "--image", "ubuntu-20.04"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) expOut := `Server 1234 created IPv4: 192.0.2.1 @@ -205,7 +206,7 @@ func TestCreateJSON(t *testing.T) { expOut := "Server 1234 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.JSONEq(t, createResponseJSON, jsonOut) @@ -282,7 +283,7 @@ func TestCreateProtectionBackup(t *testing.T) { args := []string{"--name", "cli-test", "--type", "cx22", "--image", "ubuntu-20.04", "--enable-protection", "rebuild,delete", "--enable-backup"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) expOut := `Server 1234 created Resource protection enabled for server 1234 diff --git a/internal/cmd/server/delete_test.go b/internal/cmd/server/delete_test.go index f24eed80..279fcedc 100644 --- a/internal/cmd/server/delete_test.go +++ b/internal/cmd/server/delete_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -38,7 +39,7 @@ func TestDelete(t *testing.T) { expOut := "Server test deleted\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -85,7 +86,7 @@ func TestDeleteMultiple(t *testing.T) { out, errOut, err := fx.Run(cmd, names) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Servers test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/server/describe.go b/internal/cmd/server/describe.go index 0a346929..f775390f 100644 --- a/internal/cmd/server/describe.go +++ b/internal/cmd/server/describe.go @@ -69,7 +69,7 @@ var DescribeCmd = base.DescribeCmd{ for _, f := range server.PublicNet.FloatingIPs { floatingIP, _, err := s.Client().FloatingIP().GetByID(s, f.ID) if err != nil { - return fmt.Errorf("error fetching Floating IP: %v", err) + return fmt.Errorf("error fetching Floating IP: %w", err) } cmd.Printf(" - ID:\t\t\t%d\n", floatingIP.ID) cmd.Printf(" Description:\t%s\n", util.NA(floatingIP.Description)) @@ -84,7 +84,7 @@ var DescribeCmd = base.DescribeCmd{ for _, n := range server.PrivateNet { network, _, err := s.Client().Network().GetByID(s, n.Network.ID) if err != nil { - return fmt.Errorf("error fetching network: %v", err) + return fmt.Errorf("error fetching network: %w", err) } cmd.Printf(" - ID:\t\t\t%d\n", network.ID) cmd.Printf(" Name:\t\t%s\n", network.Name) @@ -108,7 +108,7 @@ var DescribeCmd = base.DescribeCmd{ for _, v := range server.Volumes { volume, _, err := s.Client().Volume().GetByID(s, v.ID) if err != nil { - return fmt.Errorf("error fetching Volume: %v", err) + return fmt.Errorf("error fetching Volume: %w", err) } cmd.Printf(" - ID:\t\t%d\n", volume.ID) cmd.Printf(" Name:\t%s\n", volume.Name) diff --git a/internal/cmd/server/describe_test.go b/internal/cmd/server/describe_test.go index 30c1293d..4114a3d8 100644 --- a/internal/cmd/server/describe_test.go +++ b/internal/cmd/server/describe_test.go @@ -8,6 +8,7 @@ import ( "github.com/dustin/go-humanize" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/cmd/util" @@ -143,7 +144,7 @@ Placement Group: util.Datetime(srv.Created), humanize.Time(srv.Created), util.Datetime(srv.Image.Created), humanize.Time(srv.Image.Created)) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/server/detach_from_network_test.go b/internal/cmd/server/detach_from_network_test.go index dc539e14..94e66732 100644 --- a/internal/cmd/server/detach_from_network_test.go +++ b/internal/cmd/server/detach_from_network_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -39,7 +40,7 @@ func TestDetachFromNetwork(t *testing.T) { args := []string{"my-server", "--network", "my-network"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Server 123 detached from network 456\n", out) } diff --git a/internal/cmd/server/detach_iso_test.go b/internal/cmd/server/detach_iso_test.go index 28443b0e..a493a50e 100644 --- a/internal/cmd/server/detach_iso_test.go +++ b/internal/cmd/server/detach_iso_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -33,7 +34,7 @@ func TestDetachISO(t *testing.T) { args := []string{"my-server"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "ISO detached from server 123\n", out) } diff --git a/internal/cmd/server/disable_backup_test.go b/internal/cmd/server/disable_backup_test.go index 0f03e5b4..3066d3f0 100644 --- a/internal/cmd/server/disable_backup_test.go +++ b/internal/cmd/server/disable_backup_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -33,7 +34,7 @@ func TestDisableBackup(t *testing.T) { args := []string{"my-server"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Backup disabled for server 123\n", out) } diff --git a/internal/cmd/server/disable_protection_test.go b/internal/cmd/server/disable_protection_test.go index 6212438b..0bef07b3 100644 --- a/internal/cmd/server/disable_protection_test.go +++ b/internal/cmd/server/disable_protection_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -36,7 +37,7 @@ func TestDisableProtection(t *testing.T) { args := []string{"my-server", "delete", "rebuild"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Resource protection disabled for server 123\n", out) } diff --git a/internal/cmd/server/disable_rescue_test.go b/internal/cmd/server/disable_rescue_test.go index 7fbaeea9..3e0e7d80 100644 --- a/internal/cmd/server/disable_rescue_test.go +++ b/internal/cmd/server/disable_rescue_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -33,7 +34,7 @@ func TestDisableRescue(t *testing.T) { args := []string{"my-server"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Rescue disabled for server 123\n", out) } diff --git a/internal/cmd/server/enable_backup_test.go b/internal/cmd/server/enable_backup_test.go index 055f8190..50169cce 100644 --- a/internal/cmd/server/enable_backup_test.go +++ b/internal/cmd/server/enable_backup_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -33,7 +34,7 @@ func TestEnableBackup(t *testing.T) { args := []string{"my-server"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Backup enabled for server 123\n", out) } diff --git a/internal/cmd/server/enable_protection_test.go b/internal/cmd/server/enable_protection_test.go index 7ecce3f0..3c44b1b5 100644 --- a/internal/cmd/server/enable_protection_test.go +++ b/internal/cmd/server/enable_protection_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -36,7 +37,7 @@ func TestEnableProtection(t *testing.T) { args := []string{"my-server", "delete", "rebuild"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Resource protection disabled for server 123\n", out) } diff --git a/internal/cmd/server/enable_rescue.go b/internal/cmd/server/enable_rescue.go index 5f9a1f18..51cdcf98 100644 --- a/internal/cmd/server/enable_rescue.go +++ b/internal/cmd/server/enable_rescue.go @@ -47,7 +47,7 @@ var EnableRescueCmd = base.Cmd{ switch opts.Type { case hcloud.ServerRescueTypeLinux64: break - case hcloud.ServerRescueTypeLinux32: + case hcloud.ServerRescueTypeLinux32: //nolint:staticcheck return fmt.Errorf("rescue type not supported anymore: %s", opts.Type) default: return fmt.Errorf("invalid rescue type: %s", opts.Type) diff --git a/internal/cmd/server/enable_rescue_test.go b/internal/cmd/server/enable_rescue_test.go index 97266232..1bb18a4e 100644 --- a/internal/cmd/server/enable_rescue_test.go +++ b/internal/cmd/server/enable_rescue_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -36,7 +37,7 @@ func TestEnableRescue(t *testing.T) { args := []string{"my-server"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Rescue enabled for server 123 with root password: root-password\n", out) } diff --git a/internal/cmd/server/ip_test.go b/internal/cmd/server/ip_test.go index 4759a632..67650445 100644 --- a/internal/cmd/server/ip_test.go +++ b/internal/cmd/server/ip_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -41,7 +42,7 @@ func TestIPv4(t *testing.T) { args := []string{"my-server"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, ip.String()+"\n", out) } @@ -74,7 +75,7 @@ func TestIPv6(t *testing.T) { args := []string{"my-server", "-6"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, ip.String()+"1\n", out) } diff --git a/internal/cmd/server/labels_test.go b/internal/cmd/server/labels_test.go index 6d610189..535b02df 100644 --- a/internal/cmd/server/labels_test.go +++ b/internal/cmd/server/labels_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -32,7 +33,7 @@ func TestLabelAdd(t *testing.T) { expOut := "Label(s) key added to server 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -59,7 +60,7 @@ func TestMultiLabelAdd(t *testing.T) { expOut := "Label(s) foo, baz added to server 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -88,7 +89,7 @@ func TestLabelRemove(t *testing.T) { expOut := "Label(s) key removed from server 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -121,7 +122,7 @@ func TestMultiLabelRemove(t *testing.T) { expOut := "Label(s) foo, baz removed from server 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/server/list_test.go b/internal/cmd/server/list_test.go index 759b2156..0b6f5ae0 100644 --- a/internal/cmd/server/list_test.go +++ b/internal/cmd/server/list_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -52,7 +53,7 @@ func TestList(t *testing.T) { 123 test running 192.168.2.1 - - fsn1-dc14 20s ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/server/metrics_test.go b/internal/cmd/server/metrics_test.go index f45f32d0..99ce0194 100644 --- a/internal/cmd/server/metrics_test.go +++ b/internal/cmd/server/metrics_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -98,7 +99,7 @@ func TestMetrics(t *testing.T) { ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/server/poweroff_test.go b/internal/cmd/server/poweroff_test.go index d17fca75..69835c9c 100644 --- a/internal/cmd/server/poweroff_test.go +++ b/internal/cmd/server/poweroff_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -33,7 +34,7 @@ func TestPoweroff(t *testing.T) { args := []string{"my-server"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Server 123 stopped\n", out) } diff --git a/internal/cmd/server/poweron_test.go b/internal/cmd/server/poweron_test.go index 343be43b..920783cb 100644 --- a/internal/cmd/server/poweron_test.go +++ b/internal/cmd/server/poweron_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -33,7 +34,7 @@ func TestPoweron(t *testing.T) { args := []string{"my-server"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Server 123 started\n", out) } diff --git a/internal/cmd/server/reboot_test.go b/internal/cmd/server/reboot_test.go index 865a9189..d55f4c53 100644 --- a/internal/cmd/server/reboot_test.go +++ b/internal/cmd/server/reboot_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -33,7 +34,7 @@ func TestReboot(t *testing.T) { args := []string{"my-server"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Server 123 rebooted\n", out) } diff --git a/internal/cmd/server/rebuild_test.go b/internal/cmd/server/rebuild_test.go index e00b40a7..a41795ed 100644 --- a/internal/cmd/server/rebuild_test.go +++ b/internal/cmd/server/rebuild_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -41,7 +42,7 @@ func TestRebuild(t *testing.T) { args := []string{"my-server", "--image", "ubuntu-22.04"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Server 123 rebuilt with image ubuntu-22.04\nRoot password: root-password\n", out) } @@ -70,7 +71,7 @@ func TestRebuildDeprecated(t *testing.T) { errorMsg := "image ubuntu-22.04 is deprecated, please use --allow-deprecated-image to create a server with this image. It will continue to be available until 2036-08-20" - assert.Error(t, err, errorMsg) + require.Error(t, err, errorMsg) assert.Equal(t, "Error: "+errorMsg+"\n", errOut) assert.Empty(t, out) } diff --git a/internal/cmd/server/remove_from_placement_group_test.go b/internal/cmd/server/remove_from_placement_group_test.go index b231fcb9..78c29c9e 100644 --- a/internal/cmd/server/remove_from_placement_group_test.go +++ b/internal/cmd/server/remove_from_placement_group_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -35,7 +36,7 @@ func TestRemoveFromPlacementGroup(t *testing.T) { expOut := `Server 42 removed from placement group ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/server/request_console_test.go b/internal/cmd/server/request_console_test.go index 0e0b19cf..fbafc3bf 100644 --- a/internal/cmd/server/request_console_test.go +++ b/internal/cmd/server/request_console_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -37,7 +38,7 @@ func TestRequestConsole(t *testing.T) { args := []string{"my-server"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Console for server 123:\nWebSocket URL: wss://console.hetzner.cloud/?token=123\nVNC Password: root-password\n", out) } @@ -68,7 +69,7 @@ func TestRequestConsoleJSON(t *testing.T) { args := []string{"my-server", "-o=json"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.JSONEq(t, `{"wss_url": "wss://console.hetzner.cloud/?token=123", "password": "root-password"}`, out) } diff --git a/internal/cmd/server/reset_password_test.go b/internal/cmd/server/reset_password_test.go index 68af729f..0f78d51d 100644 --- a/internal/cmd/server/reset_password_test.go +++ b/internal/cmd/server/reset_password_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -36,7 +37,7 @@ func TestResetPassword(t *testing.T) { args := []string{"my-server"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Password of server 123 reset to: root-password\n", out) } diff --git a/internal/cmd/server/reset_test.go b/internal/cmd/server/reset_test.go index 9e6db4e3..a0f842f8 100644 --- a/internal/cmd/server/reset_test.go +++ b/internal/cmd/server/reset_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -33,7 +34,7 @@ func TestReset(t *testing.T) { args := []string{"my-server"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Server 123 reset\n", out) } diff --git a/internal/cmd/server/set_rdns_test.go b/internal/cmd/server/set_rdns_test.go index cec4a8bc..5402bfd7 100644 --- a/internal/cmd/server/set_rdns_test.go +++ b/internal/cmd/server/set_rdns_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -38,7 +39,7 @@ func TestSetRDNS(t *testing.T) { args := []string{"my-server", "--hostname", "s1.example.com"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Reverse DNS of Server my-server changed\n", out) } diff --git a/internal/cmd/server/shutdown_test.go b/internal/cmd/server/shutdown_test.go index dff37f4d..18b9d272 100644 --- a/internal/cmd/server/shutdown_test.go +++ b/internal/cmd/server/shutdown_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -36,7 +37,7 @@ func TestShutdown(t *testing.T) { expOut := "Sent shutdown signal to server 42\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -73,7 +74,7 @@ func TestShutdownWait(t *testing.T) { expOut := "Sent shutdown signal to server 42\nServer 42 shut down\n" expErrOut := "Waiting for server to shut down (server: 42) ...\nWaiting for server to shut down (server: 42) ... done\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expErrOut, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/server/ssh.go b/internal/cmd/server/ssh.go index c4792e95..d3080c29 100644 --- a/internal/cmd/server/ssh.go +++ b/internal/cmd/server/ssh.go @@ -1,6 +1,7 @@ package server import ( + "errors" "fmt" "os" "os/exec" @@ -59,13 +60,14 @@ var SSHCmd = base.Cmd{ } sshArgs := []string{"-l", user, "-p", strconv.Itoa(port), ipAddress.String()} - sshCommand := exec.Command(SSHPath, append(sshArgs, args[1:]...)...) + sshCommand := exec.Command(SSHPath, append(sshArgs, args[1:]...)...) //nolint:gosec sshCommand.Stdin = os.Stdin sshCommand.Stdout = os.Stdout sshCommand.Stderr = os.Stderr if err := sshCommand.Run(); err != nil { - if exitError, ok := err.(*exec.ExitError); ok { + var exitError *exec.ExitError + if errors.As(err, &exitError) { waitStatus := exitError.Sys().(syscall.WaitStatus) os.Exit(waitStatus.ExitStatus()) } diff --git a/internal/cmd/server/update_test.go b/internal/cmd/server/update_test.go index 1b0ae495..64747c9d 100644 --- a/internal/cmd/server/update_test.go +++ b/internal/cmd/server/update_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/server" "github.com/hetznercloud/cli/internal/testutil" @@ -30,7 +31,7 @@ func TestUpdateName(t *testing.T) { expOut := "Server 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/servertype/describe_test.go b/internal/cmd/servertype/describe_test.go index d8c4d60a..dd23e873 100644 --- a/internal/cmd/servertype/describe_test.go +++ b/internal/cmd/servertype/describe_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/servertype" "github.com/hetznercloud/cli/internal/testutil" @@ -101,7 +102,7 @@ Pricings per Location: ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/servertype/list_test.go b/internal/cmd/servertype/list_test.go index 9fcf9b26..6fa48f84 100644 --- a/internal/cmd/servertype/list_test.go +++ b/internal/cmd/servertype/list_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/servertype" "github.com/hetznercloud/cli/internal/testutil" @@ -48,7 +49,7 @@ func TestList(t *testing.T) { 123 test 2 shared arm 8.0 GB 80 GB local ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -94,7 +95,7 @@ func TestListColumnDeprecated(t *testing.T) { 124 current - ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/sshkey/create_test.go b/internal/cmd/sshkey/create_test.go index 6d16def0..872577d7 100644 --- a/internal/cmd/sshkey/create_test.go +++ b/internal/cmd/sshkey/create_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/sshkey" "github.com/hetznercloud/cli/internal/testutil" @@ -39,7 +40,7 @@ func TestCreate(t *testing.T) { expOut := "SSH key 123 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -72,7 +73,7 @@ func TestCreateJSON(t *testing.T) { expOut := "SSH key 123 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.JSONEq(t, createResponseJSON, jsonOut) } diff --git a/internal/cmd/sshkey/delete_test.go b/internal/cmd/sshkey/delete_test.go index a5747e9c..1cbfbec9 100644 --- a/internal/cmd/sshkey/delete_test.go +++ b/internal/cmd/sshkey/delete_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/sshkey" "github.com/hetznercloud/cli/internal/testutil" @@ -34,7 +35,7 @@ func TestDelete(t *testing.T) { expOut := "SSH Key test deleted\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -74,7 +75,7 @@ func TestDeleteMultiple(t *testing.T) { out, errOut, err := fx.Run(cmd, names) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "SSH Keys test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/sshkey/describe_test.go b/internal/cmd/sshkey/describe_test.go index 140af57a..e4b9aed8 100644 --- a/internal/cmd/sshkey/describe_test.go +++ b/internal/cmd/sshkey/describe_test.go @@ -8,6 +8,7 @@ import ( "github.com/dustin/go-humanize" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/sshkey" "github.com/hetznercloud/cli/internal/cmd/util" @@ -48,7 +49,7 @@ Labels: No labels `, util.Datetime(key.Created), humanize.Time(key.Created)) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/sshkey/labels_test.go b/internal/cmd/sshkey/labels_test.go index 806b295e..c5702a0d 100644 --- a/internal/cmd/sshkey/labels_test.go +++ b/internal/cmd/sshkey/labels_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/sshkey" "github.com/hetznercloud/cli/internal/testutil" @@ -32,7 +33,7 @@ func TestLabelAdd(t *testing.T) { expOut := "Label(s) key added to SSH Key 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -61,7 +62,7 @@ func TestLabelRemove(t *testing.T) { expOut := "Label(s) key removed from SSH Key 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/sshkey/list_test.go b/internal/cmd/sshkey/list_test.go index 16c87b07..0340a5e2 100644 --- a/internal/cmd/sshkey/list_test.go +++ b/internal/cmd/sshkey/list_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + require "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/sshkey" "github.com/hetznercloud/cli/internal/testutil" @@ -43,7 +44,7 @@ func TestList(t *testing.T) { 123 test - 1h ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/sshkey/update_test.go b/internal/cmd/sshkey/update_test.go index 0a3405b8..b3e74844 100644 --- a/internal/cmd/sshkey/update_test.go +++ b/internal/cmd/sshkey/update_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/sshkey" "github.com/hetznercloud/cli/internal/testutil" @@ -30,7 +31,7 @@ func TestUpdateName(t *testing.T) { expOut := "SSHKey 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/util/util_test.go b/internal/cmd/util/util_test.go index a6eb4769..05bf557c 100644 --- a/internal/cmd/util/util_test.go +++ b/internal/cmd/util/util_test.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" "github.com/stretchr/testify/assert" + require "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/testutil" @@ -49,7 +50,7 @@ func TestChainRunE(t *testing.T) { fn := util.ChainRunE(f1, f2, f3) err := fn(nil, nil) - assert.EqualError(t, err, "error") + require.EqualError(t, err, "error") assert.Equal(t, 2, calls) } @@ -199,7 +200,7 @@ func TestDescribeFormat(t *testing.T) { }, "Foo is: {{.Foo}} Bar is: {{.Bar}}") }) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "Foo is: foo Bar is: bar\n", stdout) assert.Empty(t, stderr) } @@ -215,7 +216,7 @@ func TestDescribeJSON(t *testing.T) { }) }) - assert.NoError(t, err) + require.NoError(t, err) assert.JSONEq(t, `{"foo":"foo", "bar": "bar"}`, stdout) assert.Empty(t, stderr) } @@ -231,7 +232,7 @@ func TestDescribeYAML(t *testing.T) { }) }) - assert.NoError(t, err) + require.NoError(t, err) assert.YAMLEq(t, `{"foo":"foo", "bar": "bar"}`, stdout) assert.Empty(t, stderr) } @@ -240,7 +241,8 @@ func TestWrap(t *testing.T) { wrapped := util.Wrap("json", map[string]interface{}{ "foo": "bar", }) - jsonString, _ := json.Marshal(wrapped) + jsonString, err := json.Marshal(wrapped) + require.NoError(t, err) assert.JSONEq(t, `{"json": {"foo": "bar"}}`, string(jsonString)) } @@ -253,7 +255,7 @@ func TestValidateRequiredFlags(t *testing.T) { _ = flags.Set("bar", "bar") err := util.ValidateRequiredFlags(flags, "foo") - assert.NoError(t, err) + require.NoError(t, err) err = util.ValidateRequiredFlags(flags, "baz") assert.EqualError(t, err, "hcloud: required flag(s) \"baz\" not set") @@ -262,10 +264,10 @@ func TestValidateRequiredFlags(t *testing.T) { func TestAddGroup(t *testing.T) { cmd := &cobra.Command{} util.AddGroup(cmd, "id", "title", &cobra.Command{}) - assert.Equal(t, len(cmd.Commands()), 1) - assert.Equal(t, len(cmd.Groups()), 1) - assert.Equal(t, cmd.Groups()[0].ID, "id") - assert.Equal(t, cmd.Groups()[0].Title, "title:") + assert.Len(t, cmd.Commands(), 1) + assert.Len(t, cmd.Groups(), 1) + assert.Equal(t, "id", cmd.Groups()[0].ID) + assert.Equal(t, "title:", cmd.Groups()[0].Title) } func TestToKebabCase(t *testing.T) { @@ -341,70 +343,70 @@ func TestToAnySlice(t *testing.T) { func TestParseBoolLenient(t *testing.T) { b, err := util.ParseBoolLenient("true") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, b) b, err = util.ParseBoolLenient("True") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, b) b, err = util.ParseBoolLenient("t") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, b) b, err = util.ParseBoolLenient("yes") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, b) b, err = util.ParseBoolLenient("y") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, b) b, err = util.ParseBoolLenient("1") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, b) b, err = util.ParseBoolLenient("false") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, b) b, err = util.ParseBoolLenient("False") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, b) b, err = util.ParseBoolLenient("f") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, b) b, err = util.ParseBoolLenient("no") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, b) b, err = util.ParseBoolLenient("n") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, b) b, err = util.ParseBoolLenient("0") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, b) b, err = util.ParseBoolLenient("invalid") - assert.EqualError(t, err, "invalid boolean value: invalid") + require.EqualError(t, err, "invalid boolean value: invalid") assert.False(t, b) b, err = util.ParseBoolLenient("") - assert.EqualError(t, err, "invalid boolean value: ") + require.EqualError(t, err, "invalid boolean value: ") assert.False(t, b) } func TestBoolFromAny(t *testing.T) { b, err := util.ToBoolE(true) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, b) b, err = util.ToBoolE("true") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, b) b, err = util.ToBoolE("false") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, b) b, err = util.ToBoolE("yes") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, b) b, err = util.ToBoolE("no") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, b) b, err = util.ToBoolE(1) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, b) b, err = util.ToBoolE(0) - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, b) _, err = util.ToBoolE("invalid") assert.EqualError(t, err, "invalid boolean value: invalid") diff --git a/internal/cmd/util/validation_test.go b/internal/cmd/util/validation_test.go index 3f61b70f..b2a77e50 100644 --- a/internal/cmd/util/validation_test.go +++ b/internal/cmd/util/validation_test.go @@ -5,6 +5,7 @@ import ( "github.com/spf13/cobra" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/testutil" @@ -99,7 +100,7 @@ func TestValidate(t *testing.T) { assert.Equal(t, test.expectedStdout, stdout) assert.Equal(t, test.expectedStderr, stderr) if test.expectedErr == "" { - assert.NoError(t, err) + require.NoError(t, err) } else { assert.EqualError(t, err, test.expectedErr) } diff --git a/internal/cmd/volume/attach_test.go b/internal/cmd/volume/attach_test.go index 07ce1e3e..2b724456 100644 --- a/internal/cmd/volume/attach_test.go +++ b/internal/cmd/volume/attach_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" @@ -40,7 +41,7 @@ func TestAttach(t *testing.T) { expOut := "Volume 123 attached to server myServer\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/volume/create_test.go b/internal/cmd/volume/create_test.go index a32e69b6..a202df84 100644 --- a/internal/cmd/volume/create_test.go +++ b/internal/cmd/volume/create_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" @@ -47,7 +48,7 @@ func TestCreate(t *testing.T) { expOut := "Volume 123 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -92,7 +93,7 @@ func TestCreateJSON(t *testing.T) { expOut := "Volume 123 created\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expOut, out) assert.JSONEq(t, createResponseJSON, jsonOut) } @@ -139,7 +140,7 @@ func TestCreateProtection(t *testing.T) { Resource protection enabled for volume 123 ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/volume/delete_test.go b/internal/cmd/volume/delete_test.go index 453a5ab4..591ad4ed 100644 --- a/internal/cmd/volume/delete_test.go +++ b/internal/cmd/volume/delete_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" @@ -34,7 +35,7 @@ func TestDelete(t *testing.T) { expOut := "Volume test deleted\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -74,7 +75,7 @@ func TestDeleteMultiple(t *testing.T) { out, errOut, err := fx.Run(cmd, names) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Volumes test1, test2, test3 deleted\n", out) } diff --git a/internal/cmd/volume/describe_test.go b/internal/cmd/volume/describe_test.go index f1c69886..329e994f 100644 --- a/internal/cmd/volume/describe_test.go +++ b/internal/cmd/volume/describe_test.go @@ -8,6 +8,7 @@ import ( "github.com/dustin/go-humanize" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/cmd/volume" @@ -72,7 +73,7 @@ Labels: No labels `, util.Datetime(v.Created), humanize.Time(v.Created)) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/volume/detach_test.go b/internal/cmd/volume/detach_test.go index 9aed6e7e..3f886d1f 100644 --- a/internal/cmd/volume/detach_test.go +++ b/internal/cmd/volume/detach_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" @@ -34,7 +35,7 @@ func TestDetach(t *testing.T) { expOut := "Volume 123 detached\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/volume/disable_protection_test.go b/internal/cmd/volume/disable_protection_test.go index dabd4f8a..840bca6f 100644 --- a/internal/cmd/volume/disable_protection_test.go +++ b/internal/cmd/volume/disable_protection_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" @@ -35,7 +36,7 @@ func TestDisableProtection(t *testing.T) { args := []string{"myVolume", "delete"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Resource protection disabled for volume 123\n", out) } diff --git a/internal/cmd/volume/enable_protection_test.go b/internal/cmd/volume/enable_protection_test.go index fcf7fe09..9cca011d 100644 --- a/internal/cmd/volume/enable_protection_test.go +++ b/internal/cmd/volume/enable_protection_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" @@ -35,7 +36,7 @@ func TestEnableProtection(t *testing.T) { args := []string{"myVolume", "delete"} out, errOut, err := fx.Run(cmd, args) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, "Resource protection enabled for volume 123\n", out) } diff --git a/internal/cmd/volume/labels_test.go b/internal/cmd/volume/labels_test.go index 36eda65b..0f0bda17 100644 --- a/internal/cmd/volume/labels_test.go +++ b/internal/cmd/volume/labels_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" @@ -32,7 +33,7 @@ func TestLabelAdd(t *testing.T) { expOut := "Label(s) key added to Volume 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } @@ -61,7 +62,7 @@ func TestLabelRemove(t *testing.T) { expOut := "Label(s) key removed from Volume 123\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/volume/list_test.go b/internal/cmd/volume/list_test.go index 893f9560..74277b28 100644 --- a/internal/cmd/volume/list_test.go +++ b/internal/cmd/volume/list_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" @@ -49,7 +50,7 @@ func TestList(t *testing.T) { 123 test 50 GB myServer fsn1 1h ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/volume/resize_test.go b/internal/cmd/volume/resize_test.go index b7497945..959243b3 100644 --- a/internal/cmd/volume/resize_test.go +++ b/internal/cmd/volume/resize_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" @@ -36,7 +37,7 @@ func TestResize(t *testing.T) { You might need to adjust the filesystem size on the server too ` - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/cmd/volume/update_test.go b/internal/cmd/volume/update_test.go index df012542..14e70fb7 100644 --- a/internal/cmd/volume/update_test.go +++ b/internal/cmd/volume/update_test.go @@ -5,6 +5,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cmd/volume" "github.com/hetznercloud/cli/internal/testutil" @@ -30,7 +31,7 @@ func TestUpdateName(t *testing.T) { expOut := "Volume 123 updated\n" - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, errOut) assert.Equal(t, expOut, out) } diff --git a/internal/state/actions_test.go b/internal/state/actions_test.go index c609a793..4c32ef1a 100644 --- a/internal/state/actions_test.go +++ b/internal/state/actions_test.go @@ -9,6 +9,7 @@ import ( gomock "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" hcapi2_mock "github.com/hetznercloud/cli/internal/hcapi2/mock" "github.com/hetznercloud/hcloud-go/v2/hcloud" @@ -34,11 +35,11 @@ func TestWaitForActionsSuccess(t *testing.T) { client.EXPECT(). WaitForFunc(gomock.Any(), gomock.Any(), action). DoAndReturn(func(_ context.Context, handleUpdate func(update *hcloud.Action) error, _ ...*hcloud.Action) error { - assert.NoError(t, handleUpdate(action)) + require.NoError(t, handleUpdate(action)) action.Status = hcloud.ActionStatusRunning - assert.NoError(t, handleUpdate(action)) + require.NoError(t, handleUpdate(action)) action.Status = hcloud.ActionStatusSuccess - assert.NoError(t, handleUpdate(action)) + require.NoError(t, handleUpdate(action)) return nil }) @@ -75,13 +76,13 @@ func TestWaitForActionsError(t *testing.T) { client.EXPECT(). WaitForFunc(gomock.Any(), gomock.Any(), action). DoAndReturn(func(_ context.Context, handleUpdate func(update *hcloud.Action) error, _ ...*hcloud.Action) error { - assert.NoError(t, handleUpdate(action)) + require.NoError(t, handleUpdate(action)) action.Status = hcloud.ActionStatusRunning - assert.NoError(t, handleUpdate(action)) + require.NoError(t, handleUpdate(action)) action.Status = hcloud.ActionStatusError action.ErrorCode = "action_failed" action.ErrorMessage = "action failed" - assert.Error(t, handleUpdate(action)) + require.Error(t, handleUpdate(action)) return action.Error() }) diff --git a/internal/state/config/options.go b/internal/state/config/options.go index e2de679e..453cec81 100644 --- a/internal/state/config/options.go +++ b/internal/state/config/options.go @@ -268,14 +268,14 @@ func (o *Option[T]) Get(c Config) (T, error) { // we can use the cast package included with viper here d, err := cast.ToDurationE(val) if err != nil { - return o.Default, fmt.Errorf("%s: %s", o.Name, err) + return o.Default, fmt.Errorf("%s: %w", o.Name, err) } val = d case bool: b, err := util.ToBoolE(val) if err != nil { - return o.Default, fmt.Errorf("%s: %s", o.Name, err) + return o.Default, fmt.Errorf("%s: %w", o.Name, err) } val = b diff --git a/internal/state/config/preferences_test.go b/internal/state/config/preferences_test.go index 59671864..734f4d74 100644 --- a/internal/state/config/preferences_test.go +++ b/internal/state/config/preferences_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/state/config" ) @@ -153,7 +154,7 @@ func TestPreferences_Validate(t *testing.T) { defer cleanup() p := config.Preferences{"foo": ""} - assert.NoError(t, p.Validate()) + require.NoError(t, p.Validate()) }) t.Run("existing nested", func(t *testing.T) { @@ -161,7 +162,7 @@ func TestPreferences_Validate(t *testing.T) { defer cleanup() p := config.Preferences{"foo": map[string]any{"bar": ""}} - assert.NoError(t, p.Validate()) + require.NoError(t, p.Validate()) }) t.Run("existing but no preference", func(t *testing.T) { diff --git a/internal/state/state.go b/internal/state/state.go index 7d2cc68f..4af2378b 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -117,7 +117,9 @@ func (c *state) newClient() (hcapi2.Client, error) { } if pollInterval > 0 { - opts = append(opts, hcloud.WithPollBackoffFunc(hcloud.ConstantBackoff(pollInterval))) + opts = append(opts, hcloud.WithPollOpts(hcloud.PollOpts{ + BackoffFunc: hcloud.ConstantBackoff(pollInterval), + })) } return hcapi2.NewClient(opts...), nil diff --git a/internal/testutil/cmd.go b/internal/testutil/cmd.go index b28f9873..0746ce5f 100644 --- a/internal/testutil/cmd.go +++ b/internal/testutil/cmd.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cobra" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/hetznercloud/cli/internal/cli" "github.com/hetznercloud/cli/internal/state" @@ -43,7 +44,7 @@ func (dt DataType) test(t *testing.T, expected string, actual string, _ ...any) return } assert.YAMLEq(t, expected, actual) - default: + case DataTypeText: assert.Equal(t, expected, actual) } } @@ -73,9 +74,9 @@ func TestCommand(t *testing.T, cmd TestableCommand, cases map[string]TestCase) { out, errOut, err := fx.Run(rootCmd, testCase.Args) if testCase.ExpErr != "" { - assert.EqualError(t, err, testCase.ExpErr) + require.EqualError(t, err, testCase.ExpErr) } else { - assert.NoError(t, err) + require.NoError(t, err) } testCase.ExpOutType.test(t, testCase.ExpOut, out) testCase.ExpErrOutType.test(t, testCase.ExpErrOut, errOut) diff --git a/internal/testutil/testing.go b/internal/testutil/testing.go index 5caa143f..884ef4a3 100644 --- a/internal/testutil/testing.go +++ b/internal/testutil/testing.go @@ -13,11 +13,11 @@ import ( func CaptureOutStreams(fn func() error) (string, string, error) { outR, outW, err := os.Pipe() if err != nil { - return "", "", fmt.Errorf("capture stdout: %v", err) + return "", "", fmt.Errorf("capture stdout: %w", err) } errR, errW, err := os.Pipe() if err != nil { - return "", "", fmt.Errorf("capture stderr: %v", err) + return "", "", fmt.Errorf("capture stderr: %w", err) } origOut, origErr := os.Stdout, os.Stderr @@ -35,13 +35,13 @@ func CaptureOutStreams(fn func() error) (string, string, error) { copied, err := io.Copy(outBuf, outR) if err != nil { - copyErr <- fmt.Errorf("capture stdout: %v, copied: %d", err, copied) + copyErr <- fmt.Errorf("capture stdout: %w, copied: %d", err, copied) return } copied, err = io.Copy(errBuf, errR) if err != nil { - copyErr <- fmt.Errorf("capture stderr: %v, copied: %d", err, copied) + copyErr <- fmt.Errorf("capture stderr: %w, copied: %d", err, copied) return } }() @@ -49,11 +49,11 @@ func CaptureOutStreams(fn func() error) (string, string, error) { err = fn() if err := outW.Close(); err != nil { - return "", "", fmt.Errorf("capture stdout close pipe writer: %v", err) + return "", "", fmt.Errorf("capture stdout close pipe writer: %w", err) } if err := errW.Close(); err != nil { - return "", "", fmt.Errorf("capture stderr close pipe writer: %v", err) + return "", "", fmt.Errorf("capture stderr close pipe writer: %w", err) } if err := <-copyErr; err != nil {