From 4ae045327ef30cb9f6ca4d519dde8622bba47b01 Mon Sep 17 00:00:00 2001 From: Joseph Phillips Date: Fri, 29 Nov 2024 11:15:53 +0100 Subject: [PATCH] chore: line length satitisation. --- domain/leaseservice.go | 4 +- domain/leaseservice_test.go | 76 ++++++++++++++++++-------------- domain/secret/service/service.go | 8 ++-- 3 files changed, 50 insertions(+), 38 deletions(-) diff --git a/domain/leaseservice.go b/domain/leaseservice.go index a930476aafa..de08a91b7be 100644 --- a/domain/leaseservice.go +++ b/domain/leaseservice.go @@ -27,7 +27,9 @@ func NewLeaseService(leaseChecker lease.ModelLeaseManagerGetter) *LeaseService { // function returns. // The context must be passed to the closure function to ensure that the // cancellation is propagated to the closure. -func (s *LeaseService) WithLease(ctx context.Context, leaseName, holderName string, fn func(context.Context) error) error { +func (s *LeaseService) WithLease( + ctx context.Context, leaseName, holderName string, fn func(context.Context) error, +) error { // Holding the lease is quite a complex operation, so we need to ensure that // the context is not cancelled before we start the operation. if err := ctx.Err(); err != nil { diff --git a/domain/leaseservice_test.go b/domain/leaseservice_test.go index e2a2c0bb3d7..851b7669460 100644 --- a/domain/leaseservice_test.go +++ b/domain/leaseservice_test.go @@ -33,17 +33,19 @@ func (s *leaseServiceSuite) TestWithLease(c *gc.C) { done := make(chan struct{}) // Force the lease wait to be triggered. - s.leaseCheckerWaiter.EXPECT().WaitUntilExpired(gomock.Any(), "leaseName", gomock.Any()).DoAndReturn(func(ctx context.Context, leaseName string, start chan<- struct{}) error { - close(start) - - // Don't return until the lease function is done. - select { - case <-done: - case <-time.After(testing.LongWait): - c.Fatalf("lease function not done") - } - return nil - }) + s.leaseCheckerWaiter.EXPECT().WaitUntilExpired(gomock.Any(), "leaseName", gomock.Any()).DoAndReturn( + func(ctx context.Context, leaseName string, start chan<- struct{}) error { + close(start) + + // Don't return until the lease function is done. + select { + case <-done: + case <-time.After(testing.LongWait): + c.Fatalf("lease function not done") + } + return nil + }, + ) // Check we correctly hold the lease. s.leaseCheckerWaiter.EXPECT().Token("leaseName", "holderName").Return(s.token) @@ -64,9 +66,11 @@ func (s *leaseServiceSuite) TestWithLease(c *gc.C) { func (s *leaseServiceSuite) TestWithLeaseWaitReturnsError(c *gc.C) { defer s.setupMocks(c).Finish() - s.leaseCheckerWaiter.EXPECT().WaitUntilExpired(gomock.Any(), "leaseName", gomock.Any()).DoAndReturn(func(ctx context.Context, leaseName string, start chan<- struct{}) error { - return fmt.Errorf("not holding lease") - }) + s.leaseCheckerWaiter.EXPECT().WaitUntilExpired(gomock.Any(), "leaseName", gomock.Any()).DoAndReturn( + func(ctx context.Context, leaseName string, start chan<- struct{}) error { + return fmt.Errorf("not holding lease") + }, + ) service := NewLeaseService(s.modelLeaseManager) @@ -87,19 +91,21 @@ func (s *leaseServiceSuite) TestWithLeaseWaitHasLeaseChange(c *gc.C) { // Cause the start to be triggered right away, but ensure that the // lease has changed. - s.leaseCheckerWaiter.EXPECT().WaitUntilExpired(gomock.Any(), "leaseName", gomock.Any()).DoAndReturn(func(ctx context.Context, leaseName string, start chan<- struct{}) error { - close(start) + s.leaseCheckerWaiter.EXPECT().WaitUntilExpired(gomock.Any(), "leaseName", gomock.Any()).DoAndReturn( + func(ctx context.Context, leaseName string, start chan<- struct{}) error { + close(start) - select { - case <-running: - case <-time.After(testing.LongWait): - c.Fatalf("lease function not running") - } + select { + case <-running: + case <-time.After(testing.LongWait): + c.Fatalf("lease function not running") + } - close(done) + close(done) - return fmt.Errorf("not holding lease") - }) + return fmt.Errorf("not holding lease") + }, + ) // Check we correctly hold the lease. s.leaseCheckerWaiter.EXPECT().Token("leaseName", "holderName").Return(s.token) @@ -145,16 +151,18 @@ func (s *leaseServiceSuite) TestWithLeaseFailsOnWaitCheck(c *gc.C) { // Cause the start to be triggered right away, but ensure that the // lease has changed. - s.leaseCheckerWaiter.EXPECT().WaitUntilExpired(gomock.Any(), "leaseName", gomock.Any()).DoAndReturn(func(ctx context.Context, leaseName string, start chan<- struct{}) error { - close(start) - - select { - case <-done: - case <-time.After(testing.LongWait): - } - - return nil - }) + s.leaseCheckerWaiter.EXPECT().WaitUntilExpired(gomock.Any(), "leaseName", gomock.Any()).DoAndReturn( + func(ctx context.Context, leaseName string, start chan<- struct{}) error { + close(start) + + select { + case <-done: + case <-time.After(testing.LongWait): + } + + return nil + }, + ) // Fail the lease check. s.leaseCheckerWaiter.EXPECT().Token("leaseName", "holderName").Return(s.token) diff --git a/domain/secret/service/service.go b/domain/secret/service/service.go index 0370b88d7fe..594dd1c9f0e 100644 --- a/domain/secret/service/service.go +++ b/domain/secret/service/service.go @@ -700,9 +700,11 @@ func (s *SecretService) GetSecretContentFromBackend(ctx context.Context, uri *se } } -// ProcessCharmSecretConsumerLabel takes a secret consumer and a uri and label which have been used to consumer the secret. -// If the uri is empty, the label and consumer are used to lookup the consumed secret uri. -// This method returns the resulting uri, and optionally the label to update for the consumer. +// ProcessCharmSecretConsumerLabel takes a secret consumer, a uri and label +// which have been used to consume the secret. If the uri is empty, the label +// and consumer are used to look up the consumed secret uri. +// This method returns the resulting uri, and optionally the label to update for +// the consumer. func (s *SecretService) ProcessCharmSecretConsumerLabel( ctx context.Context, unitName string, uri *secrets.URI, label string, token leadership.Token, ) (_ *secrets.URI, _ *string, err error) {