From 321c701fd7406f7ae5530563df09b5f54bdee7b2 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Wed, 4 Mar 2026 13:32:53 -0600 Subject: [PATCH] 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. --- .gitignore | 3 +++ hostkeys_test.go | 6 ++---- known_hosts.json | 6 ------ 3 files changed, 5 insertions(+), 10 deletions(-) delete mode 100644 known_hosts.json diff --git a/.gitignore b/.gitignore index 33899cf..61dcdf4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ towerops-agent cover.out cover.html +# Runtime data +known_hosts.json + # Database files *.db *.db-shm diff --git a/hostkeys_test.go b/hostkeys_test.go index 7b75675..b36586c 100644 --- a/hostkeys_test.go +++ b/hostkeys_test.go @@ -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{} diff --git a/known_hosts.json b/known_hosts.json deleted file mode 100644 index 4982bec..0000000 --- a/known_hosts.json +++ /dev/null @@ -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" -} \ No newline at end of file