Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable linter unparam for test files #3162

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ issues:
exclude-rules:
- path: '_test.go'
linters:
- unparam # Tests might have unused function parameters.
- lll
- dupl
- nestif
Expand Down
54 changes: 27 additions & 27 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{})
Expand All @@ -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{})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -932,15 +932,15 @@ 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
c.Assert(testutil.OutputFuncOut(), check.DeepEquals, map[string]interface{}{"key": "myValue"})

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
}

Expand All @@ -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]{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions pkg/kopia/cli/repository/storage/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
16 changes: 6 additions & 10 deletions pkg/kube/snapshot/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.*")

Expand All @@ -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:
Expand All @@ -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)
Expand Down