- Refactors the `lthn` keymap test to be thread-safe by using a mutex and `t.Cleanup` to ensure state is properly restored. - Corrects the `mockReader` implementation in the `trix` tests to adhere to the `io.Reader` interface contract.
25 lines
386 B
Go
25 lines
386 B
Go
package lthn
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var testKeyMapMu sync.Mutex
|
|
|
|
func TestSetKeyMap(t *testing.T) {
|
|
testKeyMapMu.Lock()
|
|
originalKeyMap := GetKeyMap()
|
|
t.Cleanup(func() {
|
|
SetKeyMap(originalKeyMap)
|
|
testKeyMapMu.Unlock()
|
|
})
|
|
|
|
newKeyMap := map[rune]rune{
|
|
'a': 'b',
|
|
}
|
|
SetKeyMap(newKeyMap)
|
|
assert.Equal(t, newKeyMap, GetKeyMap())
|
|
}
|