Skip to content

Commit 22be18c

Browse files
committed
refactor: move fakeDeployer and bytesFromString to testhelpers_test.go for better organization
1 parent 4a45655 commit 22be18c

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

internal/deploy/audit_test.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package deploy_test
66

77
import (
8-
"bytes"
98
"testing"
109

1110
"github.com/toeirei/keymaster/internal/core"
@@ -14,16 +13,6 @@ import (
1413
"github.com/toeirei/keymaster/internal/model"
1514
)
1615

17-
// fakeDeployer implements core.RemoteDeployer for tests.
18-
type fakeDeployer struct {
19-
content []byte
20-
seen string
21-
}
22-
23-
func (f *fakeDeployer) DeployAuthorizedKeys(content string) error { f.seen = content; return nil }
24-
func (f *fakeDeployer) GetAuthorizedKeys() ([]byte, error) { return f.content, nil }
25-
func (f *fakeDeployer) Close() {}
26-
2716
func TestAuditAccountSerial_Errors(t *testing.T) {
2817
if err := db.InitDB("sqlite", ":memory:"); err != nil {
2918
t.Fatalf("db.InitDB failed: %v", err)
@@ -91,7 +80,4 @@ func TestAuditAccountStrict_DriftDetected(t *testing.T) {
9180
}
9281
}
9382

94-
// small helpers to avoid importing bytes package directly in test bodies
95-
// small helpers to avoid importing bytes package directly in test bodies
96-
// small helpers to avoid importing bytes package directly in test bodies
97-
func bytesFromString(s string) *bytes.Buffer { return bytes.NewBufferString(s) }
83+
// bytesFromString is provided by testhelpers_test.go
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) 2025 ToeiRei
2+
// Keymaster - SSH key management system
3+
// This source code is licensed under the MIT license found in the LICENSE file.
4+
5+
package deploy_test
6+
7+
import "bytes"
8+
9+
// fakeDeployer implements core.RemoteDeployer for tests and is shared
10+
// so multiple test files can override `core.NewDeployerFactory` without
11+
// redeclaring the type.
12+
type fakeDeployer struct {
13+
content []byte
14+
seen string
15+
}
16+
17+
func (f *fakeDeployer) DeployAuthorizedKeys(content string) error { f.seen = content; return nil }
18+
func (f *fakeDeployer) GetAuthorizedKeys() ([]byte, error) { return f.content, nil }
19+
func (f *fakeDeployer) Close() {}
20+
21+
// bytesFromString is a small helper used by tests to create buffers.
22+
func bytesFromString(s string) *bytes.Buffer { return bytes.NewBufferString(s) }

0 commit comments

Comments
 (0)