diff --git a/.golangci.yml b/.golangci.yml index 6b7e892d72..1b26d35e5e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -23,6 +23,7 @@ linters: - gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. [fast: true, auto-fix: false] - gochecksumtype # Run exhaustiveness checks on Go "sum types" [fast: false, auto-fix: false] - goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false] + - gocritic # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: false] - gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false] - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true] - gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true] diff --git a/cmd/scw/main.go b/cmd/scw/main.go index 1a2b2f743e..26aaf4d4e9 100644 --- a/cmd/scw/main.go +++ b/cmd/scw/main.go @@ -60,6 +60,11 @@ func buildVersion() string { } func main() { + exitCode := mainNoExit() + os.Exit(exitCode) +} + +func mainNoExit() int { buildInfo := &core.BuildInfo{ Version: version.Must(version.NewSemver(buildVersion())), // panic when version does not respect semantic versioning BuildDate: BuildDate, @@ -82,5 +87,5 @@ func main() { Platform: terminal.NewPlatform(buildInfo.GetUserAgent()), }) - os.Exit(exitCode) + return exitCode } diff --git a/internal/args/marshal.go b/internal/args/marshal.go index f1f890d3d2..f79c5a8bb1 100644 --- a/internal/args/marshal.go +++ b/internal/args/marshal.go @@ -27,7 +27,7 @@ var marshalFuncs = map[reflect.Type]MarshalFunc{ reflect.TypeOf((*scw.Size)(nil)).Elem(): func(src interface{}) (s string, e error) { v := src.(*scw.Size) value := humanize.Bytes(uint64(*v)) - value = strings.Replace(value, " ", "", -1) + value = strings.ReplaceAll(value, " ", "") return value, nil }, reflect.TypeOf((*time.Time)(nil)).Elem(): func(src interface{}) (string, error) { diff --git a/internal/core/autocomplete.go b/internal/core/autocomplete.go index 5a791789bd..9b75784ba2 100644 --- a/internal/core/autocomplete.go +++ b/internal/core/autocomplete.go @@ -370,8 +370,7 @@ func AutoCompleteArgValue(ctx context.Context, cmd *Command, argSpec *ArgSpec, a possibleValues := []string(nil) if fieldType, err := args.GetArgType(cmd.ArgsType, argSpec.Name); err == nil { - switch fieldType.Kind() { - case reflect.Bool: + if fieldType.Kind() == reflect.Bool { possibleValues = []string{"true", "false"} } } diff --git a/internal/core/autocomplete_test.go b/internal/core/autocomplete_test.go index bbee9b74b6..c63b12d1ee 100644 --- a/internal/core/autocomplete_test.go +++ b/internal/core/autocomplete_test.go @@ -89,8 +89,8 @@ func runAutocompleteTest(ctx context.Context, tc *autoCompleteTestCase) func(*te t.Helper() words := tc.Words if len(words) == 0 { - name := strings.Replace(t.Name(), "TestAutocomplete/", "", -1) - name = strings.Replace(name, "_", " ", -1) + name := strings.ReplaceAll(t.Name(), "TestAutocomplete/", "") + name = strings.ReplaceAll(name, "_", " ") // Test can contain a sharp if duplicated // MyTest/scw_-flag_#01 sharpIndex := strings.Index(name, "#") diff --git a/internal/core/autocomplete_utils.go b/internal/core/autocomplete_utils.go index 44ed549d70..eb793cf544 100644 --- a/internal/core/autocomplete_utils.go +++ b/internal/core/autocomplete_utils.go @@ -73,7 +73,7 @@ func AutocompleteProfileName() AutoCompleteArgFunc { } } - if strings.HasPrefix(scw.DefaultProfileName, prefix) { + if strings.HasPrefix(scw.DefaultProfileName, prefix) { //nolint:gocritic res = append(res, scw.DefaultProfileName) } return res diff --git a/internal/core/cobra_utils.go b/internal/core/cobra_utils.go index be7a03efde..055c60129b 100644 --- a/internal/core/cobra_utils.go +++ b/internal/core/cobra_utils.go @@ -206,7 +206,7 @@ func handleUnmarshalErrors(cmd *Command, unmarshalErr *args.UnmarshalArgError) e switch e := wrappedErr.(type) { case *args.CannotUnmarshalError: - switch e.Err.(type) { + switch e.Err.(type) { //nolint:gocritic case *args.CannotParseBoolError: return &CliError{ Err: errors.New(""), diff --git a/internal/core/command.go b/internal/core/command.go index 90b2b76404..bc995bc3f5 100644 --- a/internal/core/command.go +++ b/internal/core/command.go @@ -386,11 +386,12 @@ func (c *Commands) applyAliases(config *alias.Config) { for _, command := range c.commands { aliases := []alias.Alias(nil) exists := false - if command.Verb != "" { + switch { + case command.Verb != "": aliases, exists = config.ResolveAliasesByFirstWord(command.Verb) - } else if command.Resource != "" { + case command.Resource != "": aliases, exists = config.ResolveAliasesByFirstWord(command.Resource) - } else if command.Namespace != "" { + case command.Namespace != "": aliases, exists = config.ResolveAliasesByFirstWord(command.Namespace) } if exists { diff --git a/internal/core/command_interceptor.go b/internal/core/command_interceptor.go index 6dca7e3665..6f94a74503 100644 --- a/internal/core/command_interceptor.go +++ b/internal/core/command_interceptor.go @@ -103,8 +103,7 @@ func sdkStdErrorInterceptor(ctx context.Context, args interface{}, runner Comman } case *scw.ResourceExpiredError: var hint string - switch resourceName := sdkError.Resource; resourceName { - case "account_token": + if sdkError.Resource == "account_token" { hint = "Try to generate a new token here https://console.scaleway.com/iam/api-keys" } @@ -124,8 +123,7 @@ func sdkStdTypeInterceptor(ctx context.Context, args interface{}, runner Command if err != nil { return res, err } - switch sdkValue := res.(type) { - case *scw.File: + if sdkValue, ok := res.(*scw.File); ok { ExtractLogger(ctx).Debug("Intercepting scw.File type, rendering as string") fileContent, err := io.ReadAll(sdkValue.Content) if err != nil { diff --git a/internal/core/reflect_test.go b/internal/core/reflect_test.go index 753a844794..68f6dc686f 100644 --- a/internal/core/reflect_test.go +++ b/internal/core/reflect_test.go @@ -91,10 +91,8 @@ func Test_getValuesForFieldByName(t *testing.T) { values, err := core.GetValuesForFieldByName(reflect.ValueOf(tc.cmdArgs), strings.Split(tc.fieldName, ".")) if err != nil { assert.Equal(t, tc.expectedError, err.Error()) - } else { - if tc.expectedValues != nil && !reflect.DeepEqual(tc.expectedValues[0].Interface(), values[0].Interface()) { - t.Errorf("Expected %v, got %v", tc.expectedValues[0].Interface(), values[0].Interface()) - } + } else if tc.expectedValues != nil && !reflect.DeepEqual(tc.expectedValues[0].Interface(), values[0].Interface()) { + t.Errorf("Expected %v, got %v", tc.expectedValues[0].Interface(), values[0].Interface()) } }, }, @@ -122,10 +120,8 @@ func Test_getValuesForFieldByName(t *testing.T) { values, err := core.GetValuesForFieldByName(reflect.ValueOf(tc.cmdArgs), strings.Split(tc.fieldName, ".")) if err != nil { assert.Equal(t, tc.expectedError, err.Error()) - } else { - if tc.expectedValues != nil && !reflect.DeepEqual(tc.expectedValues[0].Interface(), values[0].Interface()) { - t.Errorf("Expected %v, got %v", tc.expectedValues[0].Interface(), values[0].Interface()) - } + } else if tc.expectedValues != nil && !reflect.DeepEqual(tc.expectedValues[0].Interface(), values[0].Interface()) { + t.Errorf("Expected %v, got %v", tc.expectedValues[0].Interface(), values[0].Interface()) } }, }, @@ -166,10 +162,8 @@ func Test_getValuesForFieldByName(t *testing.T) { values, err := core.GetValuesForFieldByName(reflect.ValueOf(tc.cmdArgs), strings.Split(tc.fieldName, ".")) if err != nil { assert.Equal(t, nil, err.Error()) - } else { - if tc.expectedValues != nil && !reflect.DeepEqual(tc.expectedValues[0].Interface(), values[0].Interface()) { - t.Errorf("Expected %v, got %v", tc.expectedValues[0].Interface(), values[0].Interface()) - } + } else if tc.expectedValues != nil && !reflect.DeepEqual(tc.expectedValues[0].Interface(), values[0].Interface()) { + t.Errorf("Expected %v, got %v", tc.expectedValues[0].Interface(), values[0].Interface()) } }, }, diff --git a/internal/core/shell.go b/internal/core/shell.go index f1969b3423..ef91d2bfb8 100644 --- a/internal/core/shell.go +++ b/internal/core/shell.go @@ -77,11 +77,12 @@ func ArgIsOption(arg string) bool { } func argIsPositional(cmd *Command, arg string) bool { - if cmd.Verb != "" && cmd.Verb == arg { + switch { + case cmd.Verb != "" && cmd.Verb == arg: return false - } else if cmd.Resource != "" && cmd.Resource == arg { + case cmd.Resource != "" && cmd.Resource == arg: return false - } else if cmd.Namespace != "" && cmd.Resource == arg { + case cmd.Namespace != "" && cmd.Resource == arg: return false } diff --git a/internal/core/testing.go b/internal/core/testing.go index e95199b743..6488129718 100644 --- a/internal/core/testing.go +++ b/internal/core/testing.go @@ -204,7 +204,7 @@ func getTestFilePath(t *testing.T, suffix string) string { specialChars := regexp.MustCompile(`[\\?%*:|"<>. ]`) // Replace nested tests separators. - fileName := strings.Replace(t.Name(), "/", "-", -1) + fileName := strings.ReplaceAll(t.Name(), "/", "-") fileName = strcase.ToBashArg(fileName) @@ -712,7 +712,7 @@ func removeRandomPrefixFromOutput(output string) string { end := strings.IndexByte(output[begin:], '\n') actualBucketName := output[begin : begin+end] normalizedBucketName := strings.TrimRight(actualBucketName, "0123456789") - return strings.Replace(output, actualBucketName, normalizedBucketName, -1) + return strings.ReplaceAll(output, actualBucketName, normalizedBucketName) } // TestCheckError asserts error diff --git a/internal/gofields/gofields.go b/internal/gofields/gofields.go index 58ccadc150..2948315d91 100644 --- a/internal/gofields/gofields.go +++ b/internal/gofields/gofields.go @@ -145,7 +145,7 @@ func listFields(t reflect.Type, parents []string, filter ListFieldFilter) []stri fieldParents := parents if !field.Anonymous { - fieldParents = append(parents, field.Name) + fieldParents = append(parents, field.Name) //nolint:gocritic } res = append(res, listFields(field.Type, fieldParents, filter)...) diff --git a/internal/human/marshal_func.go b/internal/human/marshal_func.go index 94e10c48f3..f03813653d 100644 --- a/internal/human/marshal_func.go +++ b/internal/human/marshal_func.go @@ -172,8 +172,7 @@ func defaultMarshalerFunc(i interface{}, _ *MarshalOpt) (string, error) { i = "-" } - switch v := i.(type) { - case string: + if v, ok := i.(string); ok { if v == "" { i = "-" } diff --git a/internal/human/marshal_test.go b/internal/human/marshal_test.go index 6e7dd7283b..96c2cecd88 100644 --- a/internal/human/marshal_test.go +++ b/internal/human/marshal_test.go @@ -81,7 +81,7 @@ func TestMarshal(t *testing.T) { // Format expected to allow indentation when writing test expected := tc.result - expected = strings.Replace(expected, "\t", "", -1) + expected = strings.ReplaceAll(expected, "\t", "") expected = strings.Trim(expected, "\n") if tc.result != "" { diff --git a/internal/interactive/list.go b/internal/interactive/list.go index 65d60a8e2e..51b1d651b6 100644 --- a/internal/interactive/list.go +++ b/internal/interactive/list.go @@ -28,9 +28,8 @@ func (m *ListPrompt) Init() tea.Cmd { } func (m *ListPrompt) Update(msg tea.Msg) (tea.Model, tea.Cmd) { - switch msg := msg.(type) { - // Key is pressed - case tea.KeyMsg: + if msg, ok := msg.(tea.KeyMsg); ok { + // Key is pressed switch msg.String() { case "ctrl+c", "q": m.cancelled = true diff --git a/internal/interactive/prompt.go b/internal/interactive/prompt.go index 36275233c2..c5e6ccc6c7 100644 --- a/internal/interactive/prompt.go +++ b/internal/interactive/prompt.go @@ -36,9 +36,9 @@ func PromptBoolWithConfig(config *PromptBoolConfig) (bool, error) { for { prompt := terminal.Style(config.Prompt, color.Bold) if config.DefaultValue { - prompt = prompt + " (Y/n): " + prompt += " (Y/n): " } else { - prompt = prompt + " (y/N): " + prompt += " (y/N): " } str, err := Readline(&ReadlineConfig{ diff --git a/internal/namespaces/autocomplete/errors.go b/internal/namespaces/autocomplete/errors.go index 14b26e6c36..369296ae6b 100644 --- a/internal/namespaces/autocomplete/errors.go +++ b/internal/namespaces/autocomplete/errors.go @@ -13,9 +13,9 @@ func unsupportedShellError(shell string) *core.CliError { } } -func unsupportedOsError(OS string) *core.CliError { +func unsupportedOsError(os string) *core.CliError { return &core.CliError{ - Err: fmt.Errorf("unsupported OS '%v'", OS), + Err: fmt.Errorf("unsupported OS '%v'", os), } } diff --git a/internal/namespaces/baremetal/v1/custom_offer.go b/internal/namespaces/baremetal/v1/custom_offer.go index b68d62eeab..01abbfb498 100644 --- a/internal/namespaces/baremetal/v1/custom_offer.go +++ b/internal/namespaces/baremetal/v1/custom_offer.go @@ -41,8 +41,8 @@ func listOfferMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error Title: "PrivateBandwidth(Mbit/s)", }, } - baremetalOffer.PrivateBandwidth = baremetalOffer.PrivateBandwidth / 1000000 - baremetalOffer.Bandwidth = baremetalOffer.Bandwidth / 1000000 + baremetalOffer.PrivateBandwidth /= 1000000 + baremetalOffer.Bandwidth /= 1000000 str, err := human.Marshal(baremetalOffer, opt) if err != nil { return "", err diff --git a/internal/namespaces/billing/v2beta1/custom_invoice_download.go b/internal/namespaces/billing/v2beta1/custom_invoice_download.go index 7c9557a70e..e785a8b4c6 100644 --- a/internal/namespaces/billing/v2beta1/custom_invoice_download.go +++ b/internal/namespaces/billing/v2beta1/custom_invoice_download.go @@ -138,8 +138,7 @@ func invoiceDownloadBuilder(command *core.Command) *core.Command { } func addDownloadExt(fileName, contentType string) string { - switch contentType { - case "application/pdf": + if contentType == "application/pdf" { fileName += ".pdf" } @@ -147,12 +146,7 @@ func addDownloadExt(fileName, contentType string) string { } func checkDownloadInvoiceExt(ext string) bool { - switch ext { - case ".pdf": - return true - } - - return false + return ext == ".pdf" } func billingDownloadRun(ctx context.Context, argsI interface{}) (interface{}, error) { diff --git a/internal/namespaces/billing/v2beta1/custom_invoice_export.go b/internal/namespaces/billing/v2beta1/custom_invoice_export.go index ccb3378e40..a07f5cfe21 100644 --- a/internal/namespaces/billing/v2beta1/custom_invoice_export.go +++ b/internal/namespaces/billing/v2beta1/custom_invoice_export.go @@ -184,8 +184,7 @@ func billingExportRun(ctx context.Context, argsI interface{}) (interface{}, erro } func addExportExt(fileName, contentType string) string { - switch contentType { - case "text/csv": + if contentType == "text/csv" { fileName += ".csv" } @@ -193,10 +192,5 @@ func addExportExt(fileName, contentType string) string { } func checkExportInvoiceExt(ext string) bool { - switch ext { - case ".csv": - return true - } - - return false + return ext == ".csv" } diff --git a/internal/namespaces/init/prompt.go b/internal/namespaces/init/prompt.go index 9bcf7c96f1..cf29cfc235 100644 --- a/internal/namespaces/init/prompt.go +++ b/internal/namespaces/init/prompt.go @@ -136,8 +136,7 @@ func promptSecretKey(ctx context.Context) (string, error) { Ctx: ctx, PromptFunc: func(value string) string { secretKey := "secret-key" - switch { - case validation.IsUUID(value): + if validation.IsUUID(value) { secretKey = terminal.Style(secretKey, color.FgBlue) } return terminal.Style(fmt.Sprintf("Enter a valid %s: ", secretKey), color.Bold) @@ -169,8 +168,7 @@ func promptAccessKey(ctx context.Context) (string, error) { Ctx: ctx, PromptFunc: func(value string) string { accessKey := "access-key" - switch { - case validation.IsAccessKey(value): + if validation.IsAccessKey(value) { accessKey = terminal.Style(accessKey, color.FgBlue) } return terminal.Style(fmt.Sprintf("Enter a valid %s: ", accessKey), color.Bold) diff --git a/internal/namespaces/instance/v1/custom_server_create.go b/internal/namespaces/instance/v1/custom_server_create.go index ff85a2715d..440715d2d4 100644 --- a/internal/namespaces/instance/v1/custom_server_create.go +++ b/internal/namespaces/instance/v1/custom_server_create.go @@ -45,7 +45,7 @@ type instanceCreateServerRequest struct { CloudInit string BootType string - // Deprecated, use project-id instead + // Deprecated: use project-id instead OrganizationID *string } @@ -513,7 +513,7 @@ func buildVolumeTemplateFromSnapshot(api *instance.API, zone scw.Zone, snapshotU }, nil } -func validateImageServerTypeCompatibility(image *instance.Image, serverType *instance.ServerType, CommercialType string) error { +func validateImageServerTypeCompatibility(image *instance.Image, serverType *instance.ServerType, commercialType string) error { // An instance might not have any constraints on the local volume size if serverType.VolumesConstraint.MaxSize == 0 { return nil @@ -524,7 +524,7 @@ func validateImageServerTypeCompatibility(image *instance.Image, serverType *ins humanize.Bytes(uint64(image.RootVolume.Size)), humanize.Bytes(uint64(serverType.VolumesConstraint.MinSize)), humanize.Bytes(uint64(serverType.VolumesConstraint.MaxSize)), - CommercialType, + commercialType, ) } @@ -641,7 +641,7 @@ func instanceServerCreateImageAutoCompleteFunc(ctx context.Context, prefix strin completeListImagesCache = res } - prefix = strings.ToLower(strings.Replace(prefix, "-", "_", -1)) + prefix = strings.ToLower(strings.ReplaceAll(prefix, "-", "_")) for _, image := range completeListImagesCache.Images { if strings.HasPrefix(image.Label, prefix) { diff --git a/internal/namespaces/instance/v1/custom_server_create_builder.go b/internal/namespaces/instance/v1/custom_server_create_builder.go index 4b72acd802..c545d2820d 100644 --- a/internal/namespaces/instance/v1/custom_server_create_builder.go +++ b/internal/namespaces/instance/v1/custom_server_create_builder.go @@ -144,7 +144,7 @@ func (sb *ServerBuilder) AddImage(image string) (*ServerBuilder, error) { case image == "none": return sb, nil case !validation.IsUUID(image): - imageLabel := strings.Replace(image, "-", "_", -1) + imageLabel := strings.ReplaceAll(image, "-", "_") localImage, err := sb.apiMarketplace.GetLocalImageByLabel(&marketplace.GetLocalImageByLabelRequest{ ImageLabel: imageLabel, diff --git a/internal/namespaces/instance/v1/custom_ssh_key.go b/internal/namespaces/instance/v1/custom_ssh_key.go index 1900ec8961..faced533fd 100644 --- a/internal/namespaces/instance/v1/custom_ssh_key.go +++ b/internal/namespaces/instance/v1/custom_ssh_key.go @@ -112,7 +112,8 @@ Lookup /root/.ssh/authorized_keys on your server for more information`, } } - tags := append(server.Server.Tags, formattedKey) + tags := server.Server.Tags + tags = append(tags, formattedKey) _, err = api.UpdateServer(&instance.UpdateServerRequest{ Zone: args.Zone, diff --git a/internal/namespaces/instance/v1/custom_ssh_key_test.go b/internal/namespaces/instance/v1/custom_ssh_key_test.go index 98cc285d0b..534c904255 100644 --- a/internal/namespaces/instance/v1/custom_ssh_key_test.go +++ b/internal/namespaces/instance/v1/custom_ssh_key_test.go @@ -15,7 +15,8 @@ import ( func addSSHKey(serverKey string, sshKey string) core.BeforeFunc { return func(ctx *core.BeforeFuncCtx) error { server := ctx.Meta[serverKey].(*instanceSDK.Server) - tags := append(server.Tags, instance.FormatSSHKeyToTag(sshKey)) + tags := server.Tags + tags = append(tags, instance.FormatSSHKeyToTag(sshKey)) resp, err := instanceSDK.NewAPI(ctx.Client).UpdateServer(&instanceSDK.UpdateServerRequest{ Zone: server.Zone, diff --git a/internal/namespaces/k8s/v1/custom_node.go b/internal/namespaces/k8s/v1/custom_node.go index 7e70c5f558..cd8be2dd75 100644 --- a/internal/namespaces/k8s/v1/custom_node.go +++ b/internal/namespaces/k8s/v1/custom_node.go @@ -43,8 +43,7 @@ func waitForNodeFunc(action int) core.WaitFunc { Timeout: scw.TimeDurationPtr(nodeActionTimeout), RetryInterval: core.DefaultRetryInterval, }) - switch action { - case nodeActionReboot: + if action == nodeActionReboot { return node, err } return nil, err diff --git a/internal/namespaces/rdb/v1/custom_endpoint.go b/internal/namespaces/rdb/v1/custom_endpoint.go index 689b075ff0..e631216dd2 100644 --- a/internal/namespaces/rdb/v1/custom_endpoint.go +++ b/internal/namespaces/rdb/v1/custom_endpoint.go @@ -250,7 +250,8 @@ func endpointListCommand() *core.Command { func endpointRequestFromCustom(customEndpoints []*rdbEndpointSpecCustom) ([]*rdb.EndpointSpec, error) { endpoints := []*rdb.EndpointSpec(nil) for _, customEndpoint := range customEndpoints { - if customEndpoint.PrivateNetwork != nil && customEndpoint.PrivateNetwork.EndpointSpecPrivateNetwork != nil { + switch { + case customEndpoint.PrivateNetwork != nil && customEndpoint.PrivateNetwork.EndpointSpecPrivateNetwork != nil: ipamConfig := &rdb.EndpointSpecPrivateNetworkIpamConfig{} if !customEndpoint.PrivateNetwork.EnableIpam || customEndpoint.PrivateNetwork.ServiceIP != nil { ipamConfig = nil @@ -262,11 +263,11 @@ func endpointRequestFromCustom(customEndpoints []*rdbEndpointSpecCustom) ([]*rdb IpamConfig: ipamConfig, }, }) - } else if customEndpoint.LoadBalancer { + case customEndpoint.LoadBalancer: endpoints = append(endpoints, &rdb.EndpointSpec{ LoadBalancer: &rdb.EndpointSpecLoadBalancer{}, }) - } else { + default: return nil, errors.New("endpoint must be either a load-balancer or a private network") } } diff --git a/internal/namespaces/rdb/v1/custom_url.go b/internal/namespaces/rdb/v1/custom_url.go index c75e88697f..ffaf12d0a9 100644 --- a/internal/namespaces/rdb/v1/custom_url.go +++ b/internal/namespaces/rdb/v1/custom_url.go @@ -68,11 +68,12 @@ func generateURL(ctx context.Context, argsI interface{}) (interface{}, error) { return nil, fmt.Errorf("failed to get instance %q", args.InstanceID) } - if strings.HasPrefix(instance.Engine, string(PostgreSQL)) { + switch { + case strings.HasPrefix(instance.Engine, string(PostgreSQL)): u.Scheme = "postgresql" - } else if strings.HasPrefix(instance.Engine, string(MySQL)) { + case strings.HasPrefix(instance.Engine, string(MySQL)): u.Scheme = "mysql" - } else { + default: return nil, fmt.Errorf("unknown engine %q", instance.Engine) } diff --git a/internal/namespaces/redis/v1/custom_cluster_test.go b/internal/namespaces/redis/v1/custom_cluster_test.go index 2c40e1ce6a..8c591a9348 100644 --- a/internal/namespaces/redis/v1/custom_cluster_test.go +++ b/internal/namespaces/redis/v1/custom_cluster_test.go @@ -275,13 +275,14 @@ func checkEndpoints(t *testing.T, endpoints []*redisSDK.Endpoint, nbExpectedPub, "private-ipam": nbExpectedPrivIpam, } for _, endpoint := range endpoints { - if endpoint.PrivateNetwork == nil { + switch { + case endpoint.PrivateNetwork == nil: expectedEndpoints["public"]-- - } else if endpoint.PrivateNetwork.ProvisioningMode == redisSDK.PrivateNetworkProvisioningModeStatic { + case endpoint.PrivateNetwork.ProvisioningMode == redisSDK.PrivateNetworkProvisioningModeStatic: expectedEndpoints["private-static"]-- - } else if endpoint.PrivateNetwork.ProvisioningMode == redisSDK.PrivateNetworkProvisioningModeIpam { + case endpoint.PrivateNetwork.ProvisioningMode == redisSDK.PrivateNetworkProvisioningModeIpam: expectedEndpoints["private-ipam"]-- - } else { + default: t.Error("unknown endpoint type") } } diff --git a/internal/passwordgenerator/password_generator_test.go b/internal/passwordgenerator/password_generator_test.go index 78f8748630..28d22c3312 100644 --- a/internal/passwordgenerator/password_generator_test.go +++ b/internal/passwordgenerator/password_generator_test.go @@ -53,7 +53,7 @@ func isPassword(s string) bool { hasUpperCase = true case value >= 'a' && value <= 'z': hasLowercase = true - case strings.Contains(passwordgenerator.SpecialSymbols, string(value)): + case strings.Contains(passwordgenerator.SpecialSymbols, string(value)): //nolint:gocritic hasSymbol = true } }