diff --git a/.golangci.yml b/.golangci.yml index 544bf7e0d..f20d084de 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,6 +2,16 @@ run: timeout: 10m linters: enable: - - misspell + - copyloopvar + - errcheck + - errname + - errorlint + - goconst - gofmt + - gofumpt + - govet + - misspell + - nilerr + - staticcheck - unconvert + - unused diff --git a/cmd/beekeeper/cmd/cmd.go b/cmd/beekeeper/cmd/cmd.go index 78760121e..6ef136f39 100644 --- a/cmd/beekeeper/cmd/cmd.go +++ b/cmd/beekeeper/cmd/cmd.go @@ -325,7 +325,7 @@ func (c *command) setK8S() (err error) { k8s.WithKubeconfigPath(kubeconfigPath), } - if c.k8sClient, err = k8s.NewClient(options...); err != nil && err != k8s.ErrKubeconfigNotSet { + if c.k8sClient, err = k8s.NewClient(options...); err != nil && !errors.Is(err, k8s.ErrKubeconfigNotSet) { return fmt.Errorf("creating Kubernetes client: %w", err) } } diff --git a/mocks/k8s/app.go b/mocks/k8s/app.go index 065a08afe..a5a2207d3 100644 --- a/mocks/k8s/app.go +++ b/mocks/k8s/app.go @@ -5,6 +5,12 @@ import ( rest "k8s.io/client-go/rest" ) +const ( + CreateBad string = "create_bad" + UpdateBad string = "update_bad" + DeleteBad string = "delete_bad" +) + // compile simulation whether ClientsetMock implements interface var _ v1.AppsV1Interface = (*AppV1)(nil) diff --git a/mocks/k8s/configmap.go b/mocks/k8s/configmap.go index 7aee76d31..f3bf959d3 100644 --- a/mocks/k8s/configmap.go +++ b/mocks/k8s/configmap.go @@ -30,7 +30,7 @@ func (*ConfigMap) Apply(ctx context.Context, configMap *cofnigcorev1.ConfigMapAp // Create implements v1.ConfigMapInterface func (c *ConfigMap) Create(ctx context.Context, configMap *v1.ConfigMap, opts metav1.CreateOptions) (*v1.ConfigMap, error) { - if configMap.ObjectMeta.Name == "create_bad" { + if configMap.ObjectMeta.Name == CreateBad { return nil, fmt.Errorf("mock error: cannot create config map") } else { return nil, fmt.Errorf("mock error: unknown") @@ -39,7 +39,7 @@ func (c *ConfigMap) Create(ctx context.Context, configMap *v1.ConfigMap, opts me // Delete implements v1.ConfigMapInterface func (c *ConfigMap) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - if name == "delete_bad" { + if name == DeleteBad { return fmt.Errorf("mock error: cannot delete config map") } else { return errors.NewNotFound(schema.GroupResource{}, name) @@ -68,7 +68,7 @@ func (*ConfigMap) Patch(ctx context.Context, name string, pt types.PatchType, da // Update implements v1.ConfigMapInterface func (c *ConfigMap) Update(ctx context.Context, configMap *v1.ConfigMap, opts metav1.UpdateOptions) (*v1.ConfigMap, error) { - if configMap.ObjectMeta.Name == "update_bad" { + if configMap.ObjectMeta.Name == UpdateBad { return nil, errors.NewBadRequest("mock error: cannot update config map") } else { return nil, errors.NewNotFound(schema.GroupResource{}, configMap.ObjectMeta.Name) diff --git a/mocks/k8s/ingress.go b/mocks/k8s/ingress.go index bbaa652eb..d5d6e22df 100644 --- a/mocks/k8s/ingress.go +++ b/mocks/k8s/ingress.go @@ -35,7 +35,7 @@ func (*Ingress) ApplyStatus(ctx context.Context, ingress *networkingv1.IngressAp // Create implements v1.IngressInterface func (*Ingress) Create(ctx context.Context, ingress *netv1.Ingress, opts metav1.CreateOptions) (*netv1.Ingress, error) { - if ingress.ObjectMeta.Name == "create_bad" { + if ingress.ObjectMeta.Name == CreateBad { return nil, fmt.Errorf("mock error: cannot create ingress") } else { return nil, fmt.Errorf("mock error: unknown") @@ -44,7 +44,7 @@ func (*Ingress) Create(ctx context.Context, ingress *netv1.Ingress, opts metav1. // Delete implements v1.IngressInterface func (*Ingress) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - if name == "delete_bad" { + if name == DeleteBad { return fmt.Errorf("mock error: cannot delete ingress") } else { return errors.NewNotFound(schema.GroupResource{}, name) @@ -73,7 +73,7 @@ func (*Ingress) Patch(ctx context.Context, name string, pt types.PatchType, data // Update implements v1.IngressInterface func (*Ingress) Update(ctx context.Context, ingress *netv1.Ingress, opts metav1.UpdateOptions) (*netv1.Ingress, error) { - if ingress.ObjectMeta.Name == "update_bad" { + if ingress.ObjectMeta.Name == UpdateBad { return nil, errors.NewBadRequest("mock error: cannot update ingress") } else { return nil, errors.NewNotFound(schema.GroupResource{}, ingress.ObjectMeta.Name) diff --git a/mocks/k8s/persistentvolumeclaim.go b/mocks/k8s/persistentvolumeclaim.go index 15f059621..27f6159bf 100644 --- a/mocks/k8s/persistentvolumeclaim.go +++ b/mocks/k8s/persistentvolumeclaim.go @@ -35,7 +35,7 @@ func (*Pvc) ApplyStatus(ctx context.Context, persistentVolumeClaim *configcorev1 // Create implements v1.PersistentVolumeClaimInterface func (*Pvc) Create(ctx context.Context, persistentVolumeClaim *v1.PersistentVolumeClaim, opts metav1.CreateOptions) (*v1.PersistentVolumeClaim, error) { - if persistentVolumeClaim.ObjectMeta.Name == "create_bad" { + if persistentVolumeClaim.ObjectMeta.Name == CreateBad { return nil, fmt.Errorf("mock error: cannot create pvc") } else { return nil, fmt.Errorf("mock error: unknown") @@ -44,7 +44,7 @@ func (*Pvc) Create(ctx context.Context, persistentVolumeClaim *v1.PersistentVolu // Delete implements v1.PersistentVolumeClaimInterface func (*Pvc) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - if name == "delete_bad" { + if name == DeleteBad { return fmt.Errorf("mock error: cannot delete pvc") } else { return errors.NewNotFound(schema.GroupResource{}, name) @@ -73,7 +73,7 @@ func (*Pvc) Patch(ctx context.Context, name string, pt types.PatchType, data []b // Update implements v1.PersistentVolumeClaimInterface func (*Pvc) Update(ctx context.Context, persistentVolumeClaim *v1.PersistentVolumeClaim, opts metav1.UpdateOptions) (*v1.PersistentVolumeClaim, error) { - if persistentVolumeClaim.ObjectMeta.Name == "update_bad" { + if persistentVolumeClaim.ObjectMeta.Name == UpdateBad { return nil, errors.NewBadRequest("mock error: cannot update pvc") } else { return nil, errors.NewNotFound(schema.GroupResource{}, persistentVolumeClaim.ObjectMeta.Name) diff --git a/mocks/k8s/pod.go b/mocks/k8s/pod.go index 9328f0b95..2c5a74550 100644 --- a/mocks/k8s/pod.go +++ b/mocks/k8s/pod.go @@ -103,7 +103,7 @@ func (*Pod) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface // Create implements v1.PodInterface func (*Pod) Create(ctx context.Context, pod *v1.Pod, opts metav1.CreateOptions) (*v1.Pod, error) { - if pod.ObjectMeta.Name == "create_bad" { + if pod.ObjectMeta.Name == CreateBad { return nil, fmt.Errorf("mock error: cannot create pod") } else { return nil, fmt.Errorf("mock error: unknown") @@ -112,7 +112,7 @@ func (*Pod) Create(ctx context.Context, pod *v1.Pod, opts metav1.CreateOptions) // Delete implements v1.PodInterface func (*Pod) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - if name == "delete_bad" { + if name == DeleteBad { return fmt.Errorf("mock error: cannot delete pod") } else { return errors.NewNotFound(schema.GroupResource{}, name) @@ -121,7 +121,7 @@ func (*Pod) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) // Update implements v1.PodInterface func (*Pod) Update(ctx context.Context, pod *v1.Pod, opts metav1.UpdateOptions) (*v1.Pod, error) { - if pod.ObjectMeta.Name == "update_bad" { + if pod.ObjectMeta.Name == UpdateBad { return nil, errors.NewBadRequest("mock error: cannot update pod") } else { return nil, errors.NewNotFound(schema.GroupResource{}, pod.ObjectMeta.Name) diff --git a/mocks/k8s/secret.go b/mocks/k8s/secret.go index d8eebb4c4..efe12b0d8 100644 --- a/mocks/k8s/secret.go +++ b/mocks/k8s/secret.go @@ -30,7 +30,7 @@ func (*Secret) Apply(ctx context.Context, secret *configcorev1.SecretApplyConfig // Create implements v1.SecretInterface func (*Secret) Create(ctx context.Context, secret *v1.Secret, opts metav1.CreateOptions) (*v1.Secret, error) { - if secret.ObjectMeta.Name == "create_bad" { + if secret.ObjectMeta.Name == CreateBad { return nil, fmt.Errorf("mock error: cannot create secret") } else { return nil, fmt.Errorf("mock error: unknown") @@ -39,7 +39,7 @@ func (*Secret) Create(ctx context.Context, secret *v1.Secret, opts metav1.Create // Delete implements v1.SecretInterface func (*Secret) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - if name == "delete_bad" { + if name == DeleteBad { return fmt.Errorf("mock error: cannot delete secret") } else { return errors.NewNotFound(schema.GroupResource{}, name) @@ -68,7 +68,7 @@ func (*Secret) Patch(ctx context.Context, name string, pt types.PatchType, data // Update implements v1.SecretInterface func (*Secret) Update(ctx context.Context, secret *v1.Secret, opts metav1.UpdateOptions) (*v1.Secret, error) { - if secret.ObjectMeta.Name == "update_bad" { + if secret.ObjectMeta.Name == UpdateBad { return nil, errors.NewBadRequest("mock error: cannot update secret") } else { return nil, errors.NewNotFound(schema.GroupResource{}, secret.ObjectMeta.Name) diff --git a/mocks/k8s/service.go b/mocks/k8s/service.go index 5c6d4e18c..97c377157 100644 --- a/mocks/k8s/service.go +++ b/mocks/k8s/service.go @@ -41,7 +41,7 @@ func (*Service) ApplyStatus(ctx context.Context, service *configcorev1.ServiceAp // Create implements v1.ServiceInterface func (*Service) Create(ctx context.Context, service *v1.Service, opts metav1.CreateOptions) (*v1.Service, error) { - if service.ObjectMeta.Name == "create_bad" { + if service.ObjectMeta.Name == CreateBad { return nil, fmt.Errorf("mock error: cannot create service") } else { return nil, fmt.Errorf("mock error: unknown") @@ -50,7 +50,7 @@ func (*Service) Create(ctx context.Context, service *v1.Service, opts metav1.Cre // Delete implements v1.ServiceInterface func (*Service) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - if name == "delete_bad" { + if name == DeleteBad { return fmt.Errorf("mock error: cannot delete service") } else { return errors.NewNotFound(schema.GroupResource{}, name) @@ -59,9 +59,9 @@ func (*Service) Delete(ctx context.Context, name string, opts metav1.DeleteOptio // Get implements v1.ServiceInterface func (*Service) Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.Service, error) { - if name == "create_bad" { + if name == CreateBad { return nil, errors.NewNotFound(schema.GroupResource{}, name) - } else if name == "update_bad" { + } else if name == UpdateBad { return &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: "test", @@ -83,7 +83,7 @@ func (*Service) Patch(ctx context.Context, name string, pt types.PatchType, data // Update implements v1.ServiceInterface func (*Service) Update(ctx context.Context, service *v1.Service, opts metav1.UpdateOptions) (*v1.Service, error) { - if service.ObjectMeta.Name == "update_bad" { + if service.ObjectMeta.Name == UpdateBad { return nil, errors.NewBadRequest("mock error: cannot update service") } else { return nil, errors.NewNotFound(schema.GroupResource{}, service.ObjectMeta.Name) diff --git a/mocks/k8s/serviceaccount.go b/mocks/k8s/serviceaccount.go index 0281e0dc6..df02a07ea 100644 --- a/mocks/k8s/serviceaccount.go +++ b/mocks/k8s/serviceaccount.go @@ -31,7 +31,7 @@ func (*ServiceAccount) Apply(ctx context.Context, serviceAccount *configcorev1.S // Create implements v1.ServiceAccountInterface func (*ServiceAccount) Create(ctx context.Context, serviceAccount *v1.ServiceAccount, opts metav1.CreateOptions) (*v1.ServiceAccount, error) { - if serviceAccount.ObjectMeta.Name == "create_bad" { + if serviceAccount.ObjectMeta.Name == CreateBad { return nil, fmt.Errorf("mock error: cannot create service account") } else { return nil, fmt.Errorf("mock error: unknown") @@ -45,7 +45,7 @@ func (*ServiceAccount) CreateToken(ctx context.Context, serviceAccountName strin // Delete implements v1.ServiceAccountInterface func (*ServiceAccount) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - if name == "delete_bad" { + if name == DeleteBad { return fmt.Errorf("mock error: cannot delete service account") } else { return errors.NewNotFound(schema.GroupResource{}, name) @@ -74,7 +74,7 @@ func (*ServiceAccount) Patch(ctx context.Context, name string, pt types.PatchTyp // Update implements v1.ServiceAccountInterface func (*ServiceAccount) Update(ctx context.Context, serviceAccount *v1.ServiceAccount, opts metav1.UpdateOptions) (*v1.ServiceAccount, error) { - if serviceAccount.ObjectMeta.Name == "update_bad" { + if serviceAccount.ObjectMeta.Name == UpdateBad { return nil, errors.NewBadRequest("mock error: cannot update service account") } else { return nil, errors.NewNotFound(schema.GroupResource{}, serviceAccount.ObjectMeta.Name) diff --git a/mocks/k8s/statefulset.go b/mocks/k8s/statefulset.go index d9328d07d..7c72a43b6 100644 --- a/mocks/k8s/statefulset.go +++ b/mocks/k8s/statefulset.go @@ -46,7 +46,7 @@ func (*StatefulSet) ApplyStatus(ctx context.Context, statefulSet *configappsv1.S // Create implements v1.StatefulSetInterface func (*StatefulSet) Create(ctx context.Context, statefulSet *v1.StatefulSet, opts metav1.CreateOptions) (*v1.StatefulSet, error) { - if statefulSet.ObjectMeta.Name == "create_bad" { + if statefulSet.ObjectMeta.Name == CreateBad { return nil, fmt.Errorf("mock error: cannot create statefulset") } else { return nil, fmt.Errorf("mock error: unknown") @@ -55,7 +55,7 @@ func (*StatefulSet) Create(ctx context.Context, statefulSet *v1.StatefulSet, opt // Delete implements v1.StatefulSetInterface func (*StatefulSet) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - if name == "delete_bad" { + if name == DeleteBad { return fmt.Errorf("mock error: cannot delete statefulset") } else { return errors.NewNotFound(schema.GroupResource{}, name) @@ -96,7 +96,7 @@ func (*StatefulSet) Patch(ctx context.Context, name string, pt types.PatchType, // Update implements v1.StatefulSetInterface func (*StatefulSet) Update(ctx context.Context, statefulSet *v1.StatefulSet, opts metav1.UpdateOptions) (*v1.StatefulSet, error) { - if statefulSet.ObjectMeta.Name == "update_bad" { + if statefulSet.ObjectMeta.Name == UpdateBad { return nil, errors.NewBadRequest("mock error: cannot update statefulset") } else { return nil, errors.NewNotFound(schema.GroupResource{}, statefulSet.ObjectMeta.Name) diff --git a/pkg/bee/api/api.go b/pkg/bee/api/api.go index e5819d929..ea44bf3f6 100644 --- a/pkg/bee/api/api.go +++ b/pkg/bee/api/api.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -283,7 +284,7 @@ func responseErrorHandler(r *http.Response) (err error) { var e messageResponse if strings.Contains(r.Header.Get("Content-Type"), "application/json") { - if err = json.NewDecoder(r.Body).Decode(&e); err != nil && err != io.EOF { + if err = json.NewDecoder(r.Body).Decode(&e); err != nil && !errors.Is(err, io.EOF) { return err } } diff --git a/pkg/bee/api/pinning.go b/pkg/bee/api/pinning.go index 3543d83e9..ee3d1b5b0 100644 --- a/pkg/bee/api/pinning.go +++ b/pkg/bee/api/pinning.go @@ -2,6 +2,7 @@ package api import ( "context" + "fmt" "net/http" "github.com/ethersphere/bee/v2/pkg/swarm" @@ -41,9 +42,9 @@ func (ps *PinningService) GetPinnedRootHash(ctx context.Context, ref swarm.Addre }{} err := ps.client.requestJSON(ctx, http.MethodGet, pinsPath(ref.String()), nil, &res) if err != nil { - return swarm.ZeroAddress, nil + return swarm.ZeroAddress, fmt.Errorf("get pinned root hash: %w", err) } - return res.Reference, err + return res.Reference, nil } // GetPins returns all references of pinned root hashes. @@ -53,7 +54,7 @@ func (ps *PinningService) GetPins(ctx context.Context) ([]swarm.Address, error) }{} err := ps.client.requestJSON(ctx, http.MethodGet, pinsBasePath, nil, &res) if err != nil { - return nil, nil + return nil, fmt.Errorf("get pins: %w", err) } - return res.References, err + return res.References, nil } diff --git a/pkg/bee/chunk.go b/pkg/bee/chunk.go index 53164d401..a55cee6a1 100644 --- a/pkg/bee/chunk.go +++ b/pkg/bee/chunk.go @@ -122,7 +122,6 @@ func (c *Chunk) ClosestNodeFromMap(nodes map[string]swarm.Address, skipNodes ... next: for i, a := range addresses { - for _, skip := range skipNodes { if a.Equal(skip) { continue next diff --git a/pkg/beekeeper/beekeeper.go b/pkg/beekeeper/beekeeper.go index cb54354f0..cf07c4726 100644 --- a/pkg/beekeeper/beekeeper.go +++ b/pkg/beekeeper/beekeeper.go @@ -94,8 +94,6 @@ func RunConcurrently(ctx context.Context, cluster orchestration.Cluster, action waitDeleted := false for j, u := range s { - j, u := j, u - if u.Actions.DeleteCount > 0 { waitDeleted = true } @@ -265,7 +263,6 @@ func updateNodeGroupConcurrently(ctx context.Context, ng orchestration.NodeGroup // add nodes for _, n := range toAdd { - n := n updateSemaphore <- struct{}{} updateGroup.Go(func() error { defer func() { @@ -290,7 +287,6 @@ func updateNodeGroupConcurrently(ctx context.Context, ng orchestration.NodeGroup // delete nodes for _, n := range toDelete { - n := n updateSemaphore <- struct{}{} updateGroup.Go(func() error { defer func() { @@ -315,7 +311,6 @@ func updateNodeGroupConcurrently(ctx context.Context, ng orchestration.NodeGroup // start nodes for _, n := range toStart { - n := n updateSemaphore <- struct{}{} updateGroup.Go(func() error { defer func() { @@ -340,7 +335,6 @@ func updateNodeGroupConcurrently(ctx context.Context, ng orchestration.NodeGroup // stop nodes for _, n := range toStop { - n := n updateSemaphore <- struct{}{} updateGroup.Go(func() error { defer func() { diff --git a/pkg/check/balances/balances.go b/pkg/check/balances/balances.go index 007705be3..206ee9427 100644 --- a/pkg/check/balances/balances.go +++ b/pkg/check/balances/balances.go @@ -90,7 +90,7 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int // initial validation if err := validateBalances(balances, c.logger); err != nil { - return fmt.Errorf("invalid initial balances: %v", err) + return fmt.Errorf("invalid initial balances: %w", err) } c.logger.Info("Balances are valid") diff --git a/pkg/check/networkavailability/check.go b/pkg/check/networkavailability/check.go index 8971f3a47..93b61f945 100644 --- a/pkg/check/networkavailability/check.go +++ b/pkg/check/networkavailability/check.go @@ -100,7 +100,6 @@ iteration: // upload var chunks []swarm.Chunk for _, n := range neighborhoods(int(storageRadius)) { - batch, err := uploadClient.GetOrCreateMutableBatch(ctx, o.PostageAmount, o.PostageDepth, "net-avail-check") if err != nil { c.logger.Errorf("create batch failed failed") @@ -129,7 +128,6 @@ iteration: c.logger.Infof("uploaded to %d neighborhoods, starting downloading", len(chunks)) for _, ch := range chunks { - t := time.Now() c.metrics.DownloadAttempts.Inc() diff --git a/pkg/check/pullsync/pullsync.go b/pkg/check/pullsync/pullsync.go index 29b3bfd18..3cd5980fe 100644 --- a/pkg/check/pullsync/pullsync.go +++ b/pkg/check/pullsync/pullsync.go @@ -87,7 +87,6 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int sortedNodes := cluster.NodeNames() for i := 0; i < o.UploadNodeCount; i++ { - nodeName := sortedNodes[i] client := clients[nodeName] diff --git a/pkg/check/retrieval/retrieval.go b/pkg/check/retrieval/retrieval.go index cc2365b60..b091fa9b9 100644 --- a/pkg/check/retrieval/retrieval.go +++ b/pkg/check/retrieval/retrieval.go @@ -79,7 +79,6 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int for i := 0; i < o.UploadNodeCount; i++ { uploadNode := clients[nodes[i]] - downloadNodeIndex := (i + 1) % len(nodes) // download from the next node downloadNode := clients[nodes[downloadNodeIndex]] diff --git a/pkg/check/smoke/load.go b/pkg/check/smoke/load.go index 16232dbf9..b81590641 100644 --- a/pkg/check/smoke/load.go +++ b/pkg/check/smoke/load.go @@ -104,8 +104,6 @@ func (c *LoadCheck) Run(ctx context.Context, cluster orchestration.Cluster, opts upload.Add(1) for _, txName := range txNames { - txName := txName - go func() { defer once.Do(func() { upload.Done() @@ -163,7 +161,6 @@ func (c *LoadCheck) Run(ctx context.Context, cluster orchestration.Cluster, opts var wg sync.WaitGroup for _, rxName := range rxNames { - rxName := rxName wg.Add(1) go func() { defer wg.Done() diff --git a/pkg/check/stake/stake.go b/pkg/check/stake/stake.go index df83a0d5a..a30953dc8 100644 --- a/pkg/check/stake/stake.go +++ b/pkg/check/stake/stake.go @@ -92,7 +92,7 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int _, err = client.DepositStake(ctx, o.InsufficientAmount) if !api.IsHTTPStatusErrorCode(err, 400) { - return fmt.Errorf("deposit insufficient stake amount: expected code %v, got %v", 400, err) + return fmt.Errorf("deposit insufficient stake amount: expected code %v, got %w", 400, err) } if err := expectStakeAmountIs(ctx, client, zero); err != nil { diff --git a/pkg/k8s/configmap/configmap_test.go b/pkg/k8s/configmap/configmap_test.go index f168f6b4f..e12b053ab 100644 --- a/pkg/k8s/configmap/configmap_test.go +++ b/pkg/k8s/configmap/configmap_test.go @@ -53,13 +53,13 @@ func TestSet(t *testing.T) { }, { name: "create_error", - configName: "create_bad", + configName: mock.CreateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("creating configmap create_bad in namespace test: mock error: cannot create config map"), }, { name: "update_error", - configName: "update_bad", + configName: mock.UpdateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("updating configmap update_bad in namespace test: mock error: cannot update config map"), }, @@ -92,7 +92,6 @@ func TestSet(t *testing.T) { if !reflect.DeepEqual(response, expected) { t.Errorf("response expected: %q, got: %q", response, expected) } - } else { if err == nil { t.Fatalf("error not happened, expected: %s", test.errorMsg.Error()) @@ -137,7 +136,7 @@ func TestDelete(t *testing.T) { }, { name: "delete_error", - configName: "delete_bad", + configName: mock.DeleteBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("deleting configmap delete_bad in namespace test: mock error: cannot delete config map"), }, diff --git a/pkg/k8s/containers/containers_test.go b/pkg/k8s/containers/containers_test.go index 457985e48..1a497f23d 100644 --- a/pkg/k8s/containers/containers_test.go +++ b/pkg/k8s/containers/containers_test.go @@ -37,7 +37,7 @@ func TestToK8S_Containers(t *testing.T) { } func TestToK8S(t *testing.T) { - var trueBoolPointer bool = true + optional := true testTable := []struct { name string @@ -127,14 +127,14 @@ func TestToK8S(t *testing.T) { Name: "configMapName", }, Key: "key", - Optional: &trueBoolPointer, + Optional: &optional, }, SecretKeyRef: &v1.SecretKeySelector{ LocalObjectReference: v1.LocalObjectReference{ Name: "secretName", }, Key: "key", - Optional: &trueBoolPointer, + Optional: &optional, }, }, }, @@ -168,13 +168,13 @@ func TestToK8S(t *testing.T) { LocalObjectReference: v1.LocalObjectReference{ Name: "configMapName", }, - Optional: &trueBoolPointer, + Optional: &optional, }, SecretRef: &v1.SecretEnvSource{ LocalObjectReference: v1.LocalObjectReference{ Name: "secretName", }, - Optional: &trueBoolPointer, + Optional: &optional, }, }, } @@ -719,7 +719,7 @@ func TestToK8S(t *testing.T) { Drop: []v1.Capability{"drop"}, }, Privileged: func() *bool { - var pointerBool bool = true + pointerBool := true return &pointerBool }(), SELinuxOptions: &v1.SELinuxOptions{ @@ -751,15 +751,15 @@ func TestToK8S(t *testing.T) { return &pointerInt64 }(), RunAsNonRoot: func() *bool { - var pointerBool bool = true + pointerBool := true return &pointerBool }(), ReadOnlyRootFilesystem: func() *bool { - var pointerBool bool = true + pointerBool := true return &pointerBool }(), AllowPrivilegeEscalation: func() *bool { - var pointerBool bool = true + pointerBool := true return &pointerBool }(), ProcMount: func() *v1.ProcMountType { diff --git a/pkg/k8s/containers/handler.go b/pkg/k8s/containers/handler.go index 98b056845..9af4745af 100644 --- a/pkg/k8s/containers/handler.go +++ b/pkg/k8s/containers/handler.go @@ -26,9 +26,8 @@ func (h *LifecycleHandler) toK8S() v1.LifecycleHandler { return v1.LifecycleHandler{ TCPSocket: h.TCPSocket.toK8S(), } - } else { - return v1.LifecycleHandler{} } + return v1.LifecycleHandler{} } // ExecHandler represents Kubernetes ExecAction Handler diff --git a/pkg/k8s/containers/probe.go b/pkg/k8s/containers/probe.go index bcca5fb5f..c7ec005ba 100644 --- a/pkg/k8s/containers/probe.go +++ b/pkg/k8s/containers/probe.go @@ -19,9 +19,8 @@ func (p *Probe) toK8S() *v1.Probe { return p.HTTPGet.toK8S() } else if p.TCPSocket != nil { return p.TCPSocket.toK8S() - } else { - return nil } + return nil } // ExecProbe represents Kubernetes ExecHandler Probe diff --git a/pkg/k8s/customresource/ingressroute/ingressroute.go b/pkg/k8s/customresource/ingressroute/ingressroute.go index 0719c31e8..5f0412db2 100644 --- a/pkg/k8s/customresource/ingressroute/ingressroute.go +++ b/pkg/k8s/customresource/ingressroute/ingressroute.go @@ -9,7 +9,7 @@ import ( "k8s.io/client-go/rest" ) -// IngressRouteInterface has methods to work with IngressRoute resources. +// Interface has methods to work with IngressRoute resources. type IngressRouteInterface interface { List(ctx context.Context, opts metav1.ListOptions) (*IngressRouteList, error) Get(ctx context.Context, name string, options metav1.GetOptions) (*IngressRoute, error) diff --git a/pkg/k8s/customresource/ingressroute/types.go b/pkg/k8s/customresource/ingressroute/types.go index 03be8e87a..ae2d131bb 100644 --- a/pkg/k8s/customresource/ingressroute/types.go +++ b/pkg/k8s/customresource/ingressroute/types.go @@ -69,11 +69,11 @@ func (ir *IngressRoute) DeepCopyObject() runtime.Object { // DeepCopyInto copies all properties of this object into another object of the // same type that is provided as a pointer. -func (in *IngressRoute) DeepCopyInto(out *IngressRoute) { - out.TypeMeta = in.TypeMeta - out.ObjectMeta = in.ObjectMeta - out.Spec = in.Spec - copy(out.Spec.Routes, in.Spec.Routes) +func (ir *IngressRoute) DeepCopyInto(out *IngressRoute) { + out.TypeMeta = ir.TypeMeta + out.ObjectMeta = ir.ObjectMeta + out.Spec = ir.Spec + copy(out.Spec.Routes, ir.Spec.Routes) } func (r *Route) GetHost() string { diff --git a/pkg/k8s/ingress/client_test.go b/pkg/k8s/ingress/client_test.go index eb7e72e16..3cf1c5107 100644 --- a/pkg/k8s/ingress/client_test.go +++ b/pkg/k8s/ingress/client_test.go @@ -111,13 +111,13 @@ func TestSet(t *testing.T) { }, { name: "create_error", - ingressName: "create_bad", + ingressName: mock.CreateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("creating ingress create_bad in namespace test: mock error: cannot create ingress"), }, { name: "update_error", - ingressName: "update_bad", + ingressName: mock.UpdateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("updating ingress update_bad in namespace test: mock error: cannot update ingress"), }, @@ -192,7 +192,7 @@ func TestDelete(t *testing.T) { }, { name: "delete_error", - ingressName: "delete_bad", + ingressName: mock.DeleteBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("deleting ingress delete_bad in namespace test: mock error: cannot delete ingress"), }, diff --git a/pkg/k8s/namespace/namespace_test.go b/pkg/k8s/namespace/namespace_test.go index 229916ff3..6caf97a1f 100644 --- a/pkg/k8s/namespace/namespace_test.go +++ b/pkg/k8s/namespace/namespace_test.go @@ -199,7 +199,7 @@ func TestDelete(t *testing.T) { errorMsg: fmt.Errorf("namespace test is not managed by beekeeper, try kubectl"), }, { - name: "delete_bad", + name: mock.DeleteBad, nsName: "test", clientset: mock.NewClientset(), errorMsg: fmt.Errorf("deleting namespace test: mock error: namespace \"test\" can not be deleted"), diff --git a/pkg/k8s/persistentvolumeclaim/client.go b/pkg/k8s/persistentvolumeclaim/client.go index 975c4f849..69019eaea 100644 --- a/pkg/k8s/persistentvolumeclaim/client.go +++ b/pkg/k8s/persistentvolumeclaim/client.go @@ -26,7 +26,7 @@ func NewClient(clientset kubernetes.Interface) *Client { type Options struct { Annotations map[string]string Labels map[string]string - Spec PersistentVolumeClaimSpec + Spec Spec } // Set updates PersistentVolumeClaim or it creates it if it does not exist diff --git a/pkg/k8s/persistentvolumeclaim/client_test.go b/pkg/k8s/persistentvolumeclaim/client_test.go index 0b9eb6318..2cb919c0b 100644 --- a/pkg/k8s/persistentvolumeclaim/client_test.go +++ b/pkg/k8s/persistentvolumeclaim/client_test.go @@ -71,13 +71,13 @@ func TestSet(t *testing.T) { }, { name: "create_error", - pvcName: "create_bad", + pvcName: mock.CreateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("creating pvc create_bad in namespace test: mock error: cannot create pvc"), }, { name: "update_error", - pvcName: "update_bad", + pvcName: mock.UpdateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("updating pvc update_bad in namespace test: mock error: cannot update pvc"), }, @@ -153,7 +153,7 @@ func TestDelete(t *testing.T) { }, { name: "delete_error", - pvcName: "delete_bad", + pvcName: mock.DeleteBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("deleting pvc delete_bad in namespace test: mock error: cannot delete pvc"), }, diff --git a/pkg/k8s/persistentvolumeclaim/persistentvolumeclaim.go b/pkg/k8s/persistentvolumeclaim/persistentvolumeclaim.go index 5c189c93b..79643aa3a 100644 --- a/pkg/k8s/persistentvolumeclaim/persistentvolumeclaim.go +++ b/pkg/k8s/persistentvolumeclaim/persistentvolumeclaim.go @@ -28,7 +28,7 @@ type PersistentVolumeClaim struct { Namespace string Annotations map[string]string Labels map[string]string - Spec PersistentVolumeClaimSpec + Spec Spec } // toK8S converts PersistentVolumeClaim to Kuberntes client object @@ -44,8 +44,8 @@ func (pvc PersistentVolumeClaim) toK8S() v1.PersistentVolumeClaim { } } -// PersistentVolumeClaimSpec represents Kubernetes PersistentVolumeClaimSpec -type PersistentVolumeClaimSpec struct { +// Spec represents Kubernetes Spec +type Spec struct { Name string AccessModes AccessModes DataSource DataSource @@ -57,7 +57,7 @@ type PersistentVolumeClaimSpec struct { } // toK8S converts PersistentVolumeClaimSpec to Kuberntes client object -func (pvcs PersistentVolumeClaimSpec) toK8S() v1.PersistentVolumeClaimSpec { +func (pvcs Spec) toK8S() v1.PersistentVolumeClaimSpec { return v1.PersistentVolumeClaimSpec{ AccessModes: pvcs.AccessModes.toK8S(), DataSource: pvcs.DataSource.toK8S(), diff --git a/pkg/k8s/persistentvolumeclaim/persistentvolumeclaim_test.go b/pkg/k8s/persistentvolumeclaim/persistentvolumeclaim_test.go index caf22950e..8aa24b4a4 100644 --- a/pkg/k8s/persistentvolumeclaim/persistentvolumeclaim_test.go +++ b/pkg/k8s/persistentvolumeclaim/persistentvolumeclaim_test.go @@ -24,7 +24,7 @@ func TestToK8s(t *testing.T) { Namespace: "test", Annotations: map[string]string{"annotation_1": "annotation_value_1"}, Labels: map[string]string{"label_1": "label_value_1"}, - Spec: pvc.PersistentVolumeClaimSpec{ + Spec: pvc.Spec{ AccessModes: []pvc.AccessMode{"1", "2"}, RequestStorage: "1Gi", Selector: pvc.Selector{ @@ -94,7 +94,7 @@ func TestToK8s(t *testing.T) { name: "default_and_volume_mode_block", pvcs: pvc.PersistentVolumeClaims{ { - Spec: pvc.PersistentVolumeClaimSpec{ + Spec: pvc.Spec{ VolumeMode: "Block", }, }, diff --git a/pkg/k8s/pod/client_test.go b/pkg/k8s/pod/client_test.go index 01a52b97f..53ec77280 100644 --- a/pkg/k8s/pod/client_test.go +++ b/pkg/k8s/pod/client_test.go @@ -50,13 +50,13 @@ func TestSet(t *testing.T) { }, { name: "create_error", - podName: "create_bad", + podName: mock.CreateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("creating pod create_bad in namespace test: mock error: cannot create pod"), }, { name: "update_error", - podName: "update_bad", + podName: mock.UpdateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("updating pod update_bad in namespace test: mock error: cannot update pod"), }, @@ -132,7 +132,7 @@ func TestDelete(t *testing.T) { }, { name: "delete_error", - podName: "delete_bad", + podName: mock.DeleteBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("deleting pod delete_bad in namespace test: mock error: cannot delete pod"), }, diff --git a/pkg/k8s/secret/secret_test.go b/pkg/k8s/secret/secret_test.go index 48108106b..b603a4ec1 100644 --- a/pkg/k8s/secret/secret_test.go +++ b/pkg/k8s/secret/secret_test.go @@ -58,13 +58,13 @@ func TestSet(t *testing.T) { }, { name: "create_error", - secretName: "create_bad", + secretName: mock.CreateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("creating secret create_bad in namespace test: mock error: cannot create secret"), }, { name: "update_error", - secretName: "update_bad", + secretName: mock.UpdateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("updating secret update_bad in namespace test: mock error: cannot update secret"), }, @@ -98,7 +98,6 @@ func TestSet(t *testing.T) { if !reflect.DeepEqual(response, expected) { t.Errorf("response expected: %q, got: %q", response, expected) } - } else { if err == nil { t.Fatalf("error not happened, expected: %s", test.errorMsg.Error()) @@ -143,7 +142,7 @@ func TestDelete(t *testing.T) { }, { name: "delete_error", - secretName: "delete_bad", + secretName: mock.DeleteBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("deleting secret delete_bad in namespace test: mock error: cannot delete secret"), }, diff --git a/pkg/k8s/service/client_test.go b/pkg/k8s/service/client_test.go index 03d0c8264..ddd0afeb8 100644 --- a/pkg/k8s/service/client_test.go +++ b/pkg/k8s/service/client_test.go @@ -65,13 +65,13 @@ func TestSet(t *testing.T) { }, { name: "create_error", - serviceName: "create_bad", + serviceName: mock.CreateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("creating service create_bad in namespace test: mock error: cannot create service"), }, { name: "update_error", - serviceName: "update_bad", + serviceName: mock.UpdateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("updating service update_bad in namespace test: mock error: cannot update service"), }, @@ -108,7 +108,6 @@ func TestSet(t *testing.T) { if !reflect.DeepEqual(response, expected) { t.Errorf("response expected: %q, got: %q", response, expected) } - } else { if err == nil { t.Fatalf("error not happened, expected: %s", test.errorMsg.Error()) @@ -153,7 +152,7 @@ func TestDelete(t *testing.T) { }, { name: "delete_error", - serviceName: "delete_bad", + serviceName: mock.DeleteBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("deleting service delete_bad in namespace test: mock error: cannot delete service"), }, diff --git a/pkg/k8s/serviceaccount/serviceaccount_test.go b/pkg/k8s/serviceaccount/serviceaccount_test.go index a76c80cd6..8cafffdf1 100644 --- a/pkg/k8s/serviceaccount/serviceaccount_test.go +++ b/pkg/k8s/serviceaccount/serviceaccount_test.go @@ -55,13 +55,13 @@ func TestSet(t *testing.T) { }, { name: "create_error", - secretName: "create_bad", + secretName: mock.CreateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("creating service account create_bad in namespace test: mock error: cannot create service account"), }, { name: "update_error", - secretName: "update_bad", + secretName: mock.UpdateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("updating service account update_bad in namespace test: mock error: cannot update service account"), }, @@ -104,7 +104,6 @@ func TestSet(t *testing.T) { if !reflect.DeepEqual(response, expected) { t.Errorf("response expected: %q, got: %q", response, expected) } - } else { if err == nil { t.Fatalf("error not happened, expected: %s", test.errorMsg.Error()) @@ -149,7 +148,7 @@ func TestDelete(t *testing.T) { }, { name: "delete_error", - secretName: "delete_bad", + secretName: mock.DeleteBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("deleting service account delete_bad in namespace test: mock error: cannot delete service account"), }, diff --git a/pkg/k8s/statefulset/client_test.go b/pkg/k8s/statefulset/client_test.go index 21efd0e6f..1641c1b24 100644 --- a/pkg/k8s/statefulset/client_test.go +++ b/pkg/k8s/statefulset/client_test.go @@ -67,13 +67,13 @@ func TestSet(t *testing.T) { }, { name: "create_error", - statefulsetName: "create_bad", + statefulsetName: mock.CreateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("creating statefulset create_bad in namespace test: mock error: cannot create statefulset"), }, { name: "update_error", - statefulsetName: "update_bad", + statefulsetName: mock.UpdateBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("updating statefulset update_bad in namespace test: mock error: cannot update statefulset"), }, @@ -116,7 +116,6 @@ func TestSet(t *testing.T) { if !reflect.DeepEqual(response, expected) { t.Errorf("response expected: %q, got: %q", response, expected) } - } else { if err == nil { t.Fatalf("error not happened, expected: %s", test.errorMsg.Error()) @@ -161,7 +160,7 @@ func TestDelete(t *testing.T) { }, { name: "delete_error", - statefulsetName: "delete_bad", + statefulsetName: mock.DeleteBad, clientset: mock.NewClientset(), errorMsg: fmt.Errorf("deleting statefulset delete_bad in namespace test: mock error: cannot delete statefulset"), }, @@ -233,7 +232,6 @@ func TestReadyReplicas(t *testing.T) { if ready != test.expected { t.Errorf("response expected: %v, got: %v", test.expected, ready) } - } else { if err == nil { t.Fatalf("error not happened, expected: %s", test.errorMsg.Error()) diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index eb0485a2d..cb17cd31c 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -95,7 +95,7 @@ func (c *Client) Run(ctx context.Context) error { }() if err := c.K8sClient.Pods.WatchNewRunning(ctx, c.Namespace, c.LabelSelector, newPodIps); err != nil { - return fmt.Errorf("events watch: %v", err) + return fmt.Errorf("events watch: %w", err) } return nil diff --git a/pkg/orchestration/k8s/helpers.go b/pkg/orchestration/k8s/helpers.go index 3e1939fd4..328f73275 100644 --- a/pkg/orchestration/k8s/helpers.go +++ b/pkg/orchestration/k8s/helpers.go @@ -243,7 +243,7 @@ func setPersistentVolumeClaims(o setPersistentVolumeClaimsOptions) (pvcs pvc.Per if o.Enabled { pvcs = append(pvcs, pvc.PersistentVolumeClaim{ Name: "data", - Spec: pvc.PersistentVolumeClaimSpec{ + Spec: pvc.Spec{ AccessModes: pvc.AccessModes{ pvc.AccessMode("ReadWriteOnce"), }, diff --git a/pkg/orchestration/k8s/node_orchestrator.go b/pkg/orchestration/k8s/node_orchestrator.go index 807e74056..df1cb4fa9 100644 --- a/pkg/orchestration/k8s/node_orchestrator.go +++ b/pkg/orchestration/k8s/node_orchestrator.go @@ -105,7 +105,7 @@ func (n *nodeOrchestrator) Create(ctx context.Context, o orchestration.CreateOpt // api service portAPI, err := parsePort(o.Config.APIAddr) if err != nil { - return fmt.Errorf("parsing API port from config: %s", err) + return fmt.Errorf("parsing API port from config: %w", err) } apiSvc := fmt.Sprintf("%s-api", o.Name) @@ -185,14 +185,14 @@ func (n *nodeOrchestrator) Create(ctx context.Context, o orchestration.CreateOpt // p2p service portP2P, err := parsePort(o.Config.P2PAddr) if err != nil { - return fmt.Errorf("parsing P2P port from config: %s", err) + return fmt.Errorf("parsing P2P port from config: %w", err) } var nodePortP2P int32 if len(o.Config.NATAddr) > 0 { nodePortP2P, err = parsePort(o.Config.NATAddr) if err != nil { - return fmt.Errorf("parsing NAT address from config: %s", err) + return fmt.Errorf("parsing NAT address from config: %w", err) } } diff --git a/pkg/orchestration/k8s/nodegroup.go b/pkg/orchestration/k8s/nodegroup.go index 9cca79eeb..2efdf9bcb 100644 --- a/pkg/orchestration/k8s/nodegroup.go +++ b/pkg/orchestration/k8s/nodegroup.go @@ -3,6 +3,7 @@ package k8s import ( "context" "encoding/json" + "errors" "fmt" "net/url" "sort" @@ -703,7 +704,7 @@ func (g *NodeGroup) PregenerateSwarmKey(ctx context.Context, name string) (err e // TODO: filter by labels func (g *NodeGroup) RunningNodes(ctx context.Context) (running []string, err error) { allRunning, err := g.nodeOrchestrator.RunningNodes(ctx, g.clusterOpts.Namespace) - if err != nil && err != orchestration.ErrNotSet { + if err != nil && !errors.Is(err, orchestration.ErrNotSet) { return nil, fmt.Errorf("running nodes in namespace %s: %w", g.clusterOpts.Namespace, err) } @@ -883,7 +884,7 @@ func (g *NodeGroup) StopNode(ctx context.Context, name string) (err error) { // TODO: filter by labels func (g *NodeGroup) StoppedNodes(ctx context.Context) (stopped []string, err error) { allStopped, err := g.nodeOrchestrator.StoppedNodes(ctx, g.clusterOpts.Namespace) - if err != nil && err != orchestration.ErrNotSet { + if err != nil && !errors.Is(err, orchestration.ErrNotSet) { return nil, fmt.Errorf("stopped nodes in namespace %s: %w", g.clusterOpts.Namespace, err) } diff --git a/pkg/orchestration/utils/utils.go b/pkg/orchestration/utils/utils.go index a5c864f4f..e4cf5611e 100644 --- a/pkg/orchestration/utils/utils.go +++ b/pkg/orchestration/utils/utils.go @@ -44,7 +44,7 @@ type EncryptedKey struct { Address string `json:"address"` Crypto keyCripto `json:"crypto"` Version int `json:"version"` - Id string `json:"id"` + ID string `json:"id"` } type keyCripto struct { @@ -85,7 +85,7 @@ func encryptKey(k *ecdsa.PrivateKey, password string) ([]byte, error) { Address: hex.EncodeToString(addr), Crypto: *kc, Version: keyVersion, - Id: uuid.NewString(), + ID: uuid.NewString(), }) } diff --git a/pkg/random/random.go b/pkg/random/random.go index 24786f06e..ebbed55da 100644 --- a/pkg/random/random.go +++ b/pkg/random/random.go @@ -34,7 +34,7 @@ func Int64() int64 { // CryptoSource is used to create random source type CryptoSource struct{} -func (s CryptoSource) Seed(seed int64) {} +func (s CryptoSource) Seed(_ int64) {} func (s CryptoSource) Int63() int64 { return int64(s.Uint64() & ^uint64(1<<63)) diff --git a/pkg/random/random_test.go b/pkg/random/random_test.go index 3ad2bfc0f..2bc42c446 100644 --- a/pkg/random/random_test.go +++ b/pkg/random/random_test.go @@ -45,7 +45,6 @@ func TestPseudoGenerator(t *testing.T) { if num == g.Int63() { t.Errorf("calling method shouldn't return again the same number") } - } else { t.Error("pseudo generator returned nil") } @@ -78,7 +77,6 @@ func TestPseudoGenerators(t *testing.T) { if test.n <= 0 && g != nil { t.Error("result slice should be nil") } else if test.n > 0 { - if g == nil { t.Fatal("result slice shouldn't be nil") } @@ -142,7 +140,7 @@ func TestCryptoSource_Int63(t *testing.T) { } } -func TestCryptoSource_Seed(t *testing.T) { +func TestCryptoSource_Seed(_ *testing.T) { cs := random.CryptoSource{} cs.Seed(10) } @@ -155,7 +153,6 @@ func FuzzPseudoGenerators(f *testing.F) { } if n > 0 { - if g == nil { t.Fatal("result slice shouldn't be nil") } diff --git a/pkg/simulate/pushsync/pushsync.go b/pkg/simulate/pushsync/pushsync.go index 010b8f987..d211c36fe 100644 --- a/pkg/simulate/pushsync/pushsync.go +++ b/pkg/simulate/pushsync/pushsync.go @@ -113,7 +113,6 @@ func (s *Simulation) Run(ctx context.Context, cluster orchestration.Cluster, opt malfunctionEth := 0 for _, bucket := range buckets { - // STEP: freeze nodes in bucket for _, n := range bucket { node := clients[n] diff --git a/pkg/simulate/pushsync/pushsync_test.go b/pkg/simulate/pushsync/pushsync_test.go index 90714531c..0a615a494 100644 --- a/pkg/simulate/pushsync/pushsync_test.go +++ b/pkg/simulate/pushsync/pushsync_test.go @@ -7,7 +7,6 @@ import ( ) func TestGetIPFromUnderlays(t *testing.T) { - ips := []string{ "/ip4/127.0.0.1/udp/9090/quic", "/ip6/::1/tcp/3217", @@ -21,7 +20,6 @@ func TestGetIPFromUnderlays(t *testing.T) { } func TestTobuckets(t *testing.T) { - for _, tc := range []struct { name string base []string @@ -81,7 +79,6 @@ func TestTobuckets(t *testing.T) { } func isArrSame(a, b []string) bool { - if len(a) != len(b) { return false } diff --git a/pkg/simulate/upload/upload.go b/pkg/simulate/upload/upload.go index c8f2974e7..e933de2ba 100644 --- a/pkg/simulate/upload/upload.go +++ b/pkg/simulate/upload/upload.go @@ -114,8 +114,6 @@ func (s *Simulation) Run(ctx context.Context, cluster orchestration.Cluster, opt uGroup := new(errgroup.Group) uSemaphore := make(chan struct{}, concurrency) for i, n := range nodes { - i := i - n := n c := clients[n] uSemaphore <- struct{}{} diff --git a/pkg/swap/http.go b/pkg/swap/http.go index 7f9e3cf20..b830e864e 100644 --- a/pkg/swap/http.go +++ b/pkg/swap/http.go @@ -140,7 +140,6 @@ func responseErrorHandler(r *http.Response) (err error) { // decodeBadRequest parses the body of HTTP response that contains a list of // errors as the result of bad request data. func decodeBadRequest(r *http.Response) (err error) { - type badRequestResponse struct { Errors []string `json:"errors"` }