diff --git a/.golangci.yml b/.golangci.yml index 95cb581d08..6f11113279 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -40,7 +40,6 @@ issues: exclude-rules: - path: '_test.go' linters: - - unparam # Tests might have unused function parameters. - lll - dupl - nestif diff --git a/pkg/controller/controller_test.go b/pkg/controller/controller_test.go index b946b3ce4a..6f5b8604a0 100644 --- a/pkg/controller/controller_test.go +++ b/pkg/controller/controller_test.go @@ -153,7 +153,7 @@ func (s *ControllerSuite) TestWatch(c *check.C) { time.Sleep(5 * time.Second) } -func (s *ControllerSuite) waitOnActionSetState(c *check.C, as *crv1alpha1.ActionSet, state crv1alpha1.State) error { +func (s *ControllerSuite) waitOnActionSetState(as *crv1alpha1.ActionSet, state crv1alpha1.State) error { ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second) defer cancel() err := poll.Wait(ctx, func(context.Context) (bool, error) { @@ -179,7 +179,7 @@ func (s *ControllerSuite) waitOnActionSetState(c *check.C, as *crv1alpha1.Action return errors.Wrapf(err, "State '%s' never reached", state) } -func (s *ControllerSuite) waitOnDeferPhaseState(c *check.C, as *crv1alpha1.ActionSet, state crv1alpha1.State) error { +func (s *ControllerSuite) waitOnDeferPhaseState(as *crv1alpha1.ActionSet, state crv1alpha1.State) error { ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) defer cancel() err := poll.Wait(ctx, func(ctx context.Context) (bool, error) { @@ -474,7 +474,7 @@ func (s *ControllerSuite) TestEmptyActionSetStatus(c *check.C) { c.Assert(err, check.IsNil) }() - err = s.waitOnActionSetState(c, as, crv1alpha1.StateComplete) + err = s.waitOnActionSetState(as, crv1alpha1.StateComplete) c.Assert(err, check.IsNil) } @@ -502,7 +502,7 @@ func (s *ControllerSuite) TestSynchronousFailure(c *check.C) { c.Assert(err, check.IsNil) }() - err = s.waitOnActionSetState(c, as, crv1alpha1.StateFailed) + err = s.waitOnActionSetState(as, crv1alpha1.StateFailed) c.Assert(err, check.IsNil) } @@ -663,7 +663,7 @@ func (s *ControllerSuite) TestExecActionSet(c *check.C) { } if !cancel { - err = s.waitOnActionSetState(c, as, final) + err = s.waitOnActionSetState(as, final) c.Assert(err, check.IsNil, check.Commentf("Failed case: %s", tc.name)) expectedValue := oldValue + 1 err = waitForMetrics(s.ctrl.metrics.actionSetResolutionCounterVec, []string{tc.metricResolution}, expectedValue, time.Second) @@ -774,14 +774,14 @@ func (s *ControllerSuite) TestDeferPhase(c *check.C) { as := testutil.NewTestActionSet(s.namespace, bp.GetName(), "Deployment", s.deployment.GetName(), s.namespace, kanister.DefaultVersion, "backup") as, err = s.crCli.ActionSets(s.namespace).Create(ctx, as, metav1.CreateOptions{}) c.Assert(err, check.IsNil) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateRunning) + err = s.waitOnActionSetState(as, crv1alpha1.StateRunning) c.Assert(err, check.IsNil) // make sure deferPhase is also run successfully - err = s.waitOnDeferPhaseState(c, as, crv1alpha1.StateComplete) + err = s.waitOnDeferPhaseState(as, crv1alpha1.StateComplete) c.Assert(err, check.IsNil) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateComplete) + err = s.waitOnActionSetState(as, crv1alpha1.StateComplete) c.Assert(err, check.IsNil) as, err = s.crCli.ActionSets(s.namespace).Get(ctx, as.Name, metav1.GetOptions{}) @@ -792,9 +792,9 @@ func (s *ControllerSuite) TestDeferPhase(c *check.C) { ras := testutil.NewTestRestoreActionSet(s.namespace, bp.GetName(), s.deployment.GetName(), as.Status.Actions[0].Artifacts) ras, err = s.crCli.ActionSets(s.namespace).Create(ctx, ras, metav1.CreateOptions{}) c.Assert(err, check.IsNil) - err = s.waitOnActionSetState(c, ras, crv1alpha1.StateRunning) + err = s.waitOnActionSetState(ras, crv1alpha1.StateRunning) c.Assert(err, check.IsNil) - err = s.waitOnActionSetState(c, ras, crv1alpha1.StateComplete) + err = s.waitOnActionSetState(ras, crv1alpha1.StateComplete) c.Assert(err, check.IsNil) as, err = s.crCli.ActionSets(s.namespace).Get(ctx, as.Name, metav1.GetOptions{}) @@ -824,14 +824,14 @@ func (s *ControllerSuite) TestDeferPhaseCoreErr(c *check.C) { as, err = s.crCli.ActionSets(s.namespace).Create(ctx, as, metav1.CreateOptions{}) c.Assert(err, check.IsNil) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateRunning) + err = s.waitOnActionSetState(as, crv1alpha1.StateRunning) c.Assert(err, check.IsNil) // wait for deferPhase to be completed, because actionset status would be set to failed as soon as a main phase fails - err = s.waitOnDeferPhaseState(c, as, crv1alpha1.StateComplete) + err = s.waitOnDeferPhaseState(as, crv1alpha1.StateComplete) c.Assert(err, check.IsNil) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateFailed) + err = s.waitOnActionSetState(as, crv1alpha1.StateFailed) c.Assert(err, check.IsNil) // get the actionset again to have updated status @@ -860,14 +860,14 @@ func (s *ControllerSuite) TestDeferPhaseDeferErr(c *check.C) { as, err = s.crCli.ActionSets(s.namespace).Create(ctx, as, metav1.CreateOptions{}) c.Assert(err, check.IsNil) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateRunning) + err = s.waitOnActionSetState(as, crv1alpha1.StateRunning) c.Assert(err, check.IsNil) // wait for deferPhase to fail - err = s.waitOnDeferPhaseState(c, as, crv1alpha1.StateFailed) + err = s.waitOnDeferPhaseState(as, crv1alpha1.StateFailed) c.Assert(err, check.IsNil) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateFailed) + err = s.waitOnActionSetState(as, crv1alpha1.StateFailed) c.Assert(err, check.IsNil) // get the actionset again to have updated status @@ -895,13 +895,13 @@ func (s *ControllerSuite) TestPhaseOutputAsArtifact(c *check.C) { as, err = s.crCli.ActionSets(s.namespace).Create(ctx, as, metav1.CreateOptions{}) c.Assert(err, check.IsNil) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateRunning) + err = s.waitOnActionSetState(as, crv1alpha1.StateRunning) c.Assert(err, check.IsNil) // Check if the func returned expected output c.Assert(testutil.OutputFuncOut(), check.DeepEquals, map[string]interface{}{"key": "myValue"}) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateComplete) + err = s.waitOnActionSetState(as, crv1alpha1.StateComplete) c.Assert(err, check.IsNil) // Check if the artifacts got updated correctly @@ -932,7 +932,7 @@ func (s *ControllerSuite) TestPhaseOutputParallelActions(c *check.C) { as, err = s.crCli.ActionSets(s.namespace).Create(ctx, as, metav1.CreateOptions{}) c.Assert(err, check.IsNil) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateRunning) + err = s.waitOnActionSetState(as, crv1alpha1.StateRunning) c.Assert(err, check.IsNil) // Check if the func returned expected output @@ -940,7 +940,7 @@ func (s *ControllerSuite) TestPhaseOutputParallelActions(c *check.C) { testutil.ReleaseWaitFunc() - err = s.waitOnActionSetState(c, as, crv1alpha1.StateComplete) + err = s.waitOnActionSetState(as, crv1alpha1.StateComplete) c.Assert(err, check.IsNil) // Check if the artifacts got updated correctly @@ -969,13 +969,13 @@ func (s *ControllerSuite) TestPhaseOutputAsKopiaSnapshot(c *check.C) { as, err = s.crCli.ActionSets(s.namespace).Create(ctx, as, metav1.CreateOptions{}) c.Assert(err, check.IsNil) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateRunning) + err = s.waitOnActionSetState(as, crv1alpha1.StateRunning) c.Assert(err, check.IsNil) // Check if the func returned expected output c.Assert(testutil.OutputFuncOut(), check.DeepEquals, map[string]interface{}{"key": "myValue"}) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateComplete) + err = s.waitOnActionSetState(as, crv1alpha1.StateComplete) c.Assert(err, check.IsNil) // Check if the artifacts got updated correctly @@ -1020,13 +1020,13 @@ func (s *ControllerSuite) TestActionSetExecWithoutProfile(c *check.C) { as, err = s.crCli.ActionSets(s.namespace).Create(ctx, as, metav1.CreateOptions{}) c.Assert(err, check.IsNil) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateRunning) + err = s.waitOnActionSetState(as, crv1alpha1.StateRunning) c.Assert(err, check.IsNil) // Check if the func returned expected output c.Assert(testutil.OutputFuncOut(), check.DeepEquals, map[string]interface{}{"key": "myValue"}) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateComplete) + err = s.waitOnActionSetState(as, crv1alpha1.StateComplete) c.Assert(err, check.IsNil) // Check if the artifacts got updated correctly @@ -1051,12 +1051,12 @@ func (s *ControllerSuite) TestRenderArtifactsFailure(c *check.C) { as, err = s.crCli.ActionSets(s.namespace).Create(ctx, as, metav1.CreateOptions{}) c.Assert(err, check.IsNil) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateRunning) + err = s.waitOnActionSetState(as, crv1alpha1.StateRunning) c.Assert(err, check.IsNil) c.Assert(testutil.OutputFuncOut(), check.DeepEquals, map[string]interface{}{"key": "myValue"}) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateFailed) + err = s.waitOnActionSetState(as, crv1alpha1.StateFailed) c.Assert(err, check.IsNil) } @@ -1073,7 +1073,7 @@ func (s *ControllerSuite) TestProgressRunningPhase(c *check.C) { as := testutil.NewTestActionSet(s.namespace, bp.GetName(), "Deployment", s.deployment.GetName(), s.namespace, kanister.DefaultVersion, "backup") as, err = s.crCli.ActionSets(s.namespace).Create(ctx, as, metav1.CreateOptions{}) c.Assert(err, check.IsNil) - err = s.waitOnActionSetState(c, as, crv1alpha1.StateRunning) + err = s.waitOnActionSetState(as, crv1alpha1.StateRunning) c.Assert(err, check.IsNil) runningPhases := sets.Set[string]{} diff --git a/pkg/controllers/repositoryserver/repositoryserver_controller_test.go b/pkg/controllers/repositoryserver/repositoryserver_controller_test.go index 67832d59ec..90b6e9f5fa 100644 --- a/pkg/controllers/repositoryserver/repositoryserver_controller_test.go +++ b/pkg/controllers/repositoryserver/repositoryserver_controller_test.go @@ -279,7 +279,7 @@ func (s *RepoServerControllerSuite) TestRepositoryServerStatusIsServerReady(c *c err = testutil.CreateTestKopiaRepository(ctx, s.kubeCli, repoServerCRCreated, testutil.GetDefaultS3CompliantStorageLocation()) c.Assert(err, check.IsNil) - _, err = s.waitOnRepositoryServerState(c, repoServerCRCreated.Name) + _, err = s.waitOnRepositoryServerState(repoServerCRCreated.Name) c.Assert(err, check.IsNil) err = s.crCli.RepositoryServers(s.repoServerControllerNamespace).Delete(context.Background(), repoServerCRCreated.Name, metav1.DeleteOptions{}) @@ -294,7 +294,7 @@ func (s *RepoServerControllerSuite) TestRepositoryServerCRStateWithoutSecrets(c repoServerCRCreated, err := s.crCli.RepositoryServers(s.repoServerControllerNamespace).Create(ctx, &repoServerCR, metav1.CreateOptions{}) c.Assert(err, check.IsNil) - state, err := s.waitOnRepositoryServerState(c, repoServerCRCreated.Name) + state, err := s.waitOnRepositoryServerState(repoServerCRCreated.Name) c.Assert(err, check.NotNil) c.Assert(state, check.Equals, crv1alpha1.Failed) @@ -348,7 +348,7 @@ func (s *RepoServerControllerSuite) TestInvalidRepositoryPassword(c *check.C) { repoServerCRCreated, err := s.crCli.RepositoryServers(s.repoServerControllerNamespace).Create(ctx, &repoServerCR, metav1.CreateOptions{}) c.Assert(err, check.IsNil) - state, err := s.waitOnRepositoryServerState(c, repoServerCRCreated.Name) + state, err := s.waitOnRepositoryServerState(repoServerCRCreated.Name) c.Assert(err, check.NotNil) c.Assert(state, check.Equals, crv1alpha1.Failed) @@ -373,7 +373,7 @@ func (s *RepoServerControllerSuite) TestInvalidStorageLocation(c *check.C) { repoServerCRCreated, err := s.crCli.RepositoryServers(s.repoServerControllerNamespace).Create(ctx, &repoServerCR, metav1.CreateOptions{}) c.Assert(err, check.IsNil) - state, err := s.waitOnRepositoryServerState(c, repoServerCRCreated.Name) + state, err := s.waitOnRepositoryServerState(repoServerCRCreated.Name) c.Assert(err, check.NotNil) c.Assert(state, check.Equals, crv1alpha1.Failed) @@ -398,7 +398,7 @@ func (s *RepoServerControllerSuite) TestInvalidStorageLocationCredentials(c *che repoServerCRCreated, err := s.crCli.RepositoryServers(s.repoServerControllerNamespace).Create(ctx, &repoServerCR, metav1.CreateOptions{}) c.Assert(err, check.IsNil) - state, err := s.waitOnRepositoryServerState(c, repoServerCRCreated.Name) + state, err := s.waitOnRepositoryServerState(repoServerCRCreated.Name) c.Assert(err, check.NotNil) c.Assert(state, check.Equals, crv1alpha1.Failed) @@ -486,7 +486,7 @@ func (s *RepoServerControllerSuite) waitForRepoServerInfoUpdateInCR(repoServerNa return err } -func (s *RepoServerControllerSuite) waitOnRepositoryServerState(c *check.C, reposerverName string) (crv1alpha1.RepositoryServerProgress, error) { +func (s *RepoServerControllerSuite) waitOnRepositoryServerState(reposerverName string) (crv1alpha1.RepositoryServerProgress, error) { ctxTimeout := 10 * time.Minute ctx, cancel := context.WithTimeout(context.Background(), ctxTimeout) defer cancel() diff --git a/pkg/kopia/cli/repository/storage/s3/s3_test.go b/pkg/kopia/cli/repository/storage/s3/s3_test.go index 1bb9c77cf4..be0978767c 100644 --- a/pkg/kopia/cli/repository/storage/s3/s3_test.go +++ b/pkg/kopia/cli/repository/storage/s3/s3_test.go @@ -30,6 +30,7 @@ import ( func TestNewS3(t *testing.T) { check.TestingT(t) } +//nolint:unparam func newLocation(prefix, endpoint, region, bucket string, skipSSLVerify bool) internal.Location { return internal.Location{ "prefix": []byte(prefix), diff --git a/pkg/kube/snapshot/snapshot_test.go b/pkg/kube/snapshot/snapshot_test.go index 4cfc17145c..76130c83f0 100644 --- a/pkg/kube/snapshot/snapshot_test.go +++ b/pkg/kube/snapshot/snapshot_test.go @@ -470,11 +470,11 @@ func (s *SnapshotTestSuite) TestWaitOnReadyToUse(c *check.C) { timeout := 500 * time.Millisecond bgTimeout := 5 * time.Second // We don't have readyToUse and no error, waiting indefinitely - err = waitOnReadyToUseWithTimeout(c, ctx, fakeSs, snapshotName, defaultNamespace, timeout) + err = waitOnReadyToUseWithTimeout(ctx, fakeSs, snapshotName, timeout) c.Assert(err, check.NotNil) c.Assert(err.Error(), check.Matches, ".*context deadline exceeded*") - reply := waitOnReadyToUseInBackground(c, ctx, fakeSs, snapshotName, defaultNamespace, bgTimeout) + reply := waitOnReadyToUseInBackground(ctx, fakeSs, snapshotName, bgTimeout) setReadyStatus(c, dynCli, volumeSnapshotGVR, snapshotName, defaultNamespace) select { case err = <-reply: @@ -490,7 +490,7 @@ func (s *SnapshotTestSuite) TestWaitOnReadyToUse(c *check.C) { setErrorStatus(c, dynCli, volumeSnapshotGVR, snapshotName, defaultNamespace, message) // If there is non-transient error, exit right away - err = waitOnReadyToUseWithTimeout(c, ctx, fakeSs, snapshotName, defaultNamespace, timeout) + err = waitOnReadyToUseWithTimeout(ctx, fakeSs, snapshotName, timeout) c.Assert(err, check.NotNil) c.Assert(err.Error(), check.Matches, ".*some error.*") @@ -499,11 +499,11 @@ func (s *SnapshotTestSuite) TestWaitOnReadyToUse(c *check.C) { setErrorStatus(c, dynCli, volumeSnapshotGVR, snapshotName, defaultNamespace, message) // If there is a transient error, wait with exp backoff which is long - err = waitOnReadyToUseWithTimeout(c, ctx, fakeSs, snapshotName, defaultNamespace, timeout) + err = waitOnReadyToUseWithTimeout(ctx, fakeSs, snapshotName, timeout) c.Assert(err, check.NotNil) c.Assert(err.Error(), check.Matches, ".*context deadline exceeded*") - reply = waitOnReadyToUseInBackground(c, ctx, fakeSs, snapshotName, defaultNamespace, bgTimeout) + reply = waitOnReadyToUseInBackground(ctx, fakeSs, snapshotName, bgTimeout) setReadyStatus(c, dynCli, volumeSnapshotGVR, snapshotName, defaultNamespace) select { case err = <-reply: @@ -518,27 +518,23 @@ func (s *SnapshotTestSuite) TestWaitOnReadyToUse(c *check.C) { // ---------------------------------------------------------------------------- func waitOnReadyToUseInBackground( - c *check.C, ctx context.Context, fakeSs snapshot.Snapshotter, snapshotName string, - namespace string, timeout time.Duration, ) chan error { reply := make(chan error) go func() { - err := waitOnReadyToUseWithTimeout(c, ctx, fakeSs, snapshotName, namespace, timeout) + err := waitOnReadyToUseWithTimeout(ctx, fakeSs, snapshotName, timeout) reply <- err }() return reply } func waitOnReadyToUseWithTimeout( - c *check.C, ctx context.Context, fakeSs snapshot.Snapshotter, snapshotName string, - namespace string, timeout time.Duration, ) error { deadline := time.Now().Add(timeout)