Skip to content

Commit

Permalink
chore: line length satitisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
manadart committed Nov 29, 2024
1 parent d2f2609 commit 4ae0453
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 38 deletions.
4 changes: 3 additions & 1 deletion domain/leaseservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
76 changes: 42 additions & 34 deletions domain/leaseservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions domain/secret/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4ae0453

Please sign in to comment.