From ca6ad970c3f85433e50a0f8ea89375836195af7d Mon Sep 17 00:00:00 2001 From: Jeremie Fraeys Date: Thu, 12 Mar 2026 16:35:37 -0400 Subject: [PATCH] refactor: co-locate logging, manifest, network, privacy, prommetrics tests Move unit tests from tests/unit/ to internal/ following Go conventions: - tests/unit/logging/* -> internal/logging/* (logging tests) - tests/unit/manifest/* -> internal/manifest/* (run_manifest, schema tests) - tests/unit/network/* -> internal/network/* (retry, ssh_pool, ssh tests) - tests/unit/privacy/* -> internal/privacy/* (pii tests) - tests/unit/metrics/* -> internal/prommetrics/* (metrics tests) Update import paths in test files to reflect new locations. Note: metrics_test.go moved from tests/unit/metrics/ to internal/prommetrics/ to match the actual package name. --- {tests/unit => internal}/logging/logging_test.go | 2 +- .../manifest/run_manifest_test.go | 0 {tests/unit => internal}/manifest/schema_test.go | 14 +++++++------- {tests/unit => internal}/network/retry_test.go | 2 +- {tests/unit => internal}/network/ssh_pool_test.go | 2 +- {tests/unit => internal}/network/ssh_test.go | 2 +- {tests/unit => internal}/privacy/pii_test.go | 0 .../prommetrics}/metrics_test.go | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) rename {tests/unit => internal}/logging/logging_test.go (99%) rename {tests/unit => internal}/manifest/run_manifest_test.go (100%) rename {tests/unit => internal}/manifest/schema_test.go (94%) rename {tests/unit => internal}/network/retry_test.go (99%) rename {tests/unit => internal}/network/ssh_pool_test.go (99%) rename {tests/unit => internal}/network/ssh_test.go (99%) rename {tests/unit => internal}/privacy/pii_test.go (100%) rename {tests/unit/metrics => internal/prommetrics}/metrics_test.go (99%) diff --git a/tests/unit/logging/logging_test.go b/internal/logging/logging_test.go similarity index 99% rename from tests/unit/logging/logging_test.go rename to internal/logging/logging_test.go index 02a9d96..e0cf163 100644 --- a/tests/unit/logging/logging_test.go +++ b/internal/logging/logging_test.go @@ -1,4 +1,4 @@ -package tests +package logging_test import ( "context" diff --git a/tests/unit/manifest/run_manifest_test.go b/internal/manifest/run_manifest_test.go similarity index 100% rename from tests/unit/manifest/run_manifest_test.go rename to internal/manifest/run_manifest_test.go diff --git a/tests/unit/manifest/schema_test.go b/internal/manifest/schema_test.go similarity index 94% rename from tests/unit/manifest/schema_test.go rename to internal/manifest/schema_test.go index 1ee737c..3ff0cf6 100644 --- a/tests/unit/manifest/schema_test.go +++ b/internal/manifest/schema_test.go @@ -1,4 +1,4 @@ -package manifest +package manifest_test import ( "crypto/sha256" @@ -19,7 +19,7 @@ func TestSchemaUnchanged(t *testing.T) { // Get the project root (this test runs from internal/manifest/) _, testFile, _, _ := runtime.Caller(0) testDir := filepath.Dir(testFile) - schemaPath := filepath.Join(testDir, "..", "..", "..", "internal", "manifest", "schema.json") + schemaPath := filepath.Join(testDir, "schema.json") // Load the committed schema committedSchemaData, err := os.ReadFile(schemaPath) @@ -65,7 +65,7 @@ func TestSchemaUnchanged(t *testing.T) { func TestSchemaValidatesExampleManifest(t *testing.T) { _, testFile, _, _ := runtime.Caller(0) testDir := filepath.Dir(testFile) - schemaPath := filepath.Join(testDir, "..", "..", "..", "internal", "manifest", "schema.json") + schemaPath := filepath.Join(testDir, "schema.json") schemaLoader, err := loadSchemaFromFile(schemaPath) if err != nil { @@ -124,7 +124,7 @@ func TestSchemaValidatesExampleManifest(t *testing.T) { func TestSchemaRejectsInvalidManifest(t *testing.T) { _, testFile, _, _ := runtime.Caller(0) testDir := filepath.Dir(testFile) - schemaPath := filepath.Join(testDir, "..", "..", "..", "internal", "manifest", "schema.json") + schemaPath := filepath.Join(testDir, "schema.json") schemaLoader, err := loadSchemaFromFile(schemaPath) if err != nil { @@ -228,7 +228,7 @@ func TestSchemaVersionMatchesConst(t *testing.T) { _, testFile, _, _ := runtime.Caller(0) testDir := filepath.Dir(testFile) // Schema is in internal/manifest, not tests/unit/manifest - schemaPath := filepath.Join(testDir, "..", "..", "..", "internal", "manifest", "schema.json") + schemaPath := filepath.Join(testDir, "schema.json") schemaData, err := os.ReadFile(schemaPath) if err != nil { @@ -274,7 +274,7 @@ func GenerateSchemaFromStructs() map[string]any { // Since we have the schema committed, we just return it parsed _, testFile, _, _ := runtime.Caller(0) testDir := filepath.Dir(testFile) - schemaPath := filepath.Join(testDir, "..", "..", "..", "internal", "manifest", "schema.json") + schemaPath := filepath.Join(testDir, "schema.json") data, err := os.ReadFile(schemaPath) if err != nil { @@ -302,7 +302,7 @@ func GenerateSchemaFromStructs() map[string]any { func GenerateSchemaJSON() []byte { _, testFile, _, _ := runtime.Caller(0) testDir := filepath.Dir(testFile) - schemaPath := filepath.Join(testDir, "..", "..", "..", "internal", "manifest", "schema.json") + schemaPath := filepath.Join(testDir, "schema.json") data, err := os.ReadFile(schemaPath) if err != nil { diff --git a/tests/unit/network/retry_test.go b/internal/network/retry_test.go similarity index 99% rename from tests/unit/network/retry_test.go rename to internal/network/retry_test.go index 2a378e9..7c8d9f8 100644 --- a/tests/unit/network/retry_test.go +++ b/internal/network/retry_test.go @@ -1,4 +1,4 @@ -package tests +package network_test import ( "context" diff --git a/tests/unit/network/ssh_pool_test.go b/internal/network/ssh_pool_test.go similarity index 99% rename from tests/unit/network/ssh_pool_test.go rename to internal/network/ssh_pool_test.go index fda4b67..a85baa2 100644 --- a/tests/unit/network/ssh_pool_test.go +++ b/internal/network/ssh_pool_test.go @@ -1,4 +1,4 @@ -package tests +package network_test import ( "context" diff --git a/tests/unit/network/ssh_test.go b/internal/network/ssh_test.go similarity index 99% rename from tests/unit/network/ssh_test.go rename to internal/network/ssh_test.go index 6febe75..058877f 100644 --- a/tests/unit/network/ssh_test.go +++ b/internal/network/ssh_test.go @@ -1,4 +1,4 @@ -package tests +package network_test import ( "context" diff --git a/tests/unit/privacy/pii_test.go b/internal/privacy/pii_test.go similarity index 100% rename from tests/unit/privacy/pii_test.go rename to internal/privacy/pii_test.go diff --git a/tests/unit/metrics/metrics_test.go b/internal/prommetrics/metrics_test.go similarity index 99% rename from tests/unit/metrics/metrics_test.go rename to internal/prommetrics/metrics_test.go index efa3051..2c464b6 100644 --- a/tests/unit/metrics/metrics_test.go +++ b/internal/prommetrics/metrics_test.go @@ -1,4 +1,4 @@ -package tests +package prommetrics_test import ( "testing"