Skip to content

Commit a84d16e

Browse files
Extract test port and data constants in agent service tests
- Add constants for test server ports (testInventoryPort, testAttestPort) - Add constant for test PID file content (testPIDContent) - Replace hardcoded localhost URLs with constructed constants - Replace hardcoded PID file data with named constant - Improve test maintainability and consistency - Address goconst linting issues in agent test suite Test constants added: - testInventoryPort (:8081) for inventory service testing - testAttestPort (:8443) for attestation service testing - testPIDContent (12345\n) for PID file testing Co-authored-by: Amp <[email protected]> Amp-Thread-ID: https://ampcode.com/threads/T-5be4213f-26eb-400c-bb7b-d4c79b7ee6fe
1 parent 3e1fbb2 commit a84d16e

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

agent/internal/service/service_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ import (
1717
)
1818

1919
const (
20-
testDeviceID = "test-device"
21-
initialCapacity = 0
22-
pidFileMode = 0o600
20+
testDeviceID = "test-device"
21+
initialCapacity = 0
22+
pidFileMode = 0o600
23+
testInventoryPort = ":8081"
24+
testAttestPort = ":8443"
25+
testPIDContent = "12345\n"
2326
)
2427

2528
// mockPostureCollector implements the posture.Collector interface for testing
@@ -48,8 +51,8 @@ func TestService_New(t *testing.T) {
4851
t.Run("creates service with valid config", func(t *testing.T) {
4952
config := &Config{
5053
DeviceID: testDeviceID,
51-
InventoryURL: "http://localhost:8081",
52-
AttestURL: "http://localhost:8443",
54+
InventoryURL: "http://localhost" + testInventoryPort,
55+
AttestURL: "http://localhost" + testAttestPort,
5356
KeyPath: "/tmp/test.key",
5457
CertPath: "/tmp/test.crt",
5558
CAPath: "/tmp/ca.pem",
@@ -445,7 +448,7 @@ func TestService_removePIDFile(t *testing.T) {
445448
pidFile := filepath.Join(tmpDir, "test.pid")
446449

447450
// Create PID file
448-
err := os.WriteFile(pidFile, []byte("12345\n"), pidFileMode)
451+
err := os.WriteFile(pidFile, []byte(testPIDContent), pidFileMode)
449452
if err != nil {
450453
t.Fatalf("Failed to create test PID file: %v", err)
451454
}

0 commit comments

Comments
 (0)