fix: avoid copying sync.Once in host key tests
sync.Once contains sync.noCopy and cannot be assigned by value.
Reset with a fresh sync.Once{} in defer instead of save/restore.
Also gitignore known_hosts.json runtime data.
This commit is contained in:
parent
93df6ce0ba
commit
321c701fd7
3 changed files with 5 additions and 10 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -4,6 +4,9 @@ towerops-agent
|
|||
cover.out
|
||||
cover.html
|
||||
|
||||
# Runtime data
|
||||
known_hosts.json
|
||||
|
||||
# Database files
|
||||
*.db
|
||||
*.db-shm
|
||||
|
|
|
|||
|
|
@ -76,10 +76,9 @@ func TestHostKeyStoreConcurrency(t *testing.T) {
|
|||
|
||||
func TestGetHostKeyStoreDefault(t *testing.T) {
|
||||
// Reset the once for testing
|
||||
origOnce := hostKeysOnce
|
||||
origStore := globalHostKeys
|
||||
defer func() {
|
||||
hostKeysOnce = origOnce
|
||||
hostKeysOnce = sync.Once{}
|
||||
globalHostKeys = origStore
|
||||
}()
|
||||
hostKeysOnce = sync.Once{}
|
||||
|
|
@ -93,10 +92,9 @@ func TestGetHostKeyStoreDefault(t *testing.T) {
|
|||
|
||||
func TestSSHHostKeyCallback(t *testing.T) {
|
||||
// Reset global state
|
||||
origOnce := hostKeysOnce
|
||||
origStore := globalHostKeys
|
||||
defer func() {
|
||||
hostKeysOnce = origOnce
|
||||
hostKeysOnce = sync.Once{}
|
||||
globalHostKeys = origStore
|
||||
}()
|
||||
hostKeysOnce = sync.Once{}
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"127.0.0.1:34241": "7b15d4949c86819c72610bb15661751a258ba039010e1544d8a6a2291411844c",
|
||||
"127.0.0.1:38017": "2aaf02f4a6e47ece1361d10df54c8af2ffd8f43f8d3ad0d3d1b8cf42107e0bea",
|
||||
"127.0.0.1:42691": "fd4c0283f9848d207364b309eb894f54516e0b2d6c0935399a514a0504e31f4d",
|
||||
"127.0.0.1:44377": "a0b1c55bc4c006fe871315e6a95d49afd1af3ac90e0309f1afae98acf003a5b9"
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue