Skip to content

Commit 58fd425

Browse files
committed
[#800] Cover a function branch
1 parent 62e7f47 commit 58fd425

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

backend/server/apps/manager_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,35 @@ func TestLockUnlock(t *testing.T) {
376376
require.NoError(t, err)
377377
}
378378

379+
// Test that the context passed to the Unlock method must contain the lock key.
380+
// Otherwise, no daemons are unlocked.
381+
func TestUnlockForMissingKey(t *testing.T) {
382+
// Arrange
383+
locker := config.NewDaemonLocker()
384+
manager := NewManager(&appstest.ManagerAccessorsWrapper{
385+
DaemonLocker: locker,
386+
})
387+
require.NotNil(t, manager)
388+
389+
lockCtx, _ := manager.CreateContext(123)
390+
lockCtx, _ = manager.Lock(lockCtx, 1, 2, 3)
391+
392+
// Context with no lock key.
393+
unlockCtx := context.WithValue(
394+
context.Background(),
395+
config.DaemonsContextKey,
396+
lockCtx.Value(config.DaemonsContextKey),
397+
)
398+
399+
// Act
400+
manager.Unlock(unlockCtx)
401+
402+
// Assert
403+
for _, daemonID := range []int64{1, 2, 3} {
404+
require.True(t, locker.IsLocked(daemonID))
405+
}
406+
}
407+
379408
// Test that the commit call is routed to the Kea module when the
380409
// transaction target is dbmodel.AppTypeKea.
381410
func TestCommitKeaModule(t *testing.T) {

0 commit comments

Comments
 (0)