From f1997376ee007d152fcde9da16a376bd247ca888 Mon Sep 17 00:00:00 2001 From: pkositsyn Date: Mon, 22 Feb 2021 01:35:45 +0300 Subject: [PATCH] Add test to make sure passed keys are not modified in keylock --- keylock/keylock_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/keylock/keylock_test.go b/keylock/keylock_test.go index 762a855..4888ac8 100644 --- a/keylock/keylock_test.go +++ b/keylock/keylock_test.go @@ -83,6 +83,20 @@ func TestKeyLock_DeadlockFree(t *testing.T) { wg.Wait() } +func TestKeyLock_NoMutates(t *testing.T) { + defer goleak.VerifyNone(t) + l := keylock.New() + + keys := []string{"b", "c", "a"} + passedKeys := make([]string, len(keys)) + copy(passedKeys, keys) + + _, unlock := l.LockKeys(passedKeys, nil) + unlock() + + require.Equal(t, keys, passedKeys, "passed keys shouldn't be mutated") +} + func TestKeyLock_SingleKeyStress(t *testing.T) { const ( N = 1000