tests: move the test-only constructors into export_test.go (closes #111)
check / check (push) Successful in 1m37s
check / check (push) Successful in 1m37s
state.NewForTest, state.NewForTestWithDataDir and watcher.NewForTest were compiled into and exported by the production packages internal/state and internal/watcher. NewForTestWithDataDir and watcher.NewForTest now live in their package's export_test.go. Tests in other packages cannot see those files, so the watcher and middleware tests build their State with state.New and a temporary data directory; the watcher tests no longer try to save to /state.json. state.NewForTest, whose State saved to /, is deleted: the state tests that used it pass t.TempDir() to NewForTestWithDataDir, and the test of the helper itself is gone. Model: opus-5-5
This commit was merged in pull request #169.
This commit is contained in:
@@ -739,7 +739,7 @@ func TestPortStateUnmarshalJSON_BothFormats(t *testing.T) {
|
||||
func TestGetSnapshot_ReturnsCopy(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := state.NewForTest()
|
||||
s := state.NewForTestWithDataDir(t.TempDir())
|
||||
|
||||
populateState(t, s)
|
||||
|
||||
@@ -761,7 +761,7 @@ func TestGetSnapshot_ReturnsCopy(t *testing.T) {
|
||||
func TestDomainState_GetSet(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := state.NewForTest()
|
||||
s := state.NewForTestWithDataDir(t.TempDir())
|
||||
|
||||
// Get on missing key returns false.
|
||||
_, ok := s.GetDomainState("nonexistent.com")
|
||||
@@ -812,7 +812,7 @@ func TestDomainState_GetSet(t *testing.T) {
|
||||
func TestHostnameState_GetSet(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := state.NewForTest()
|
||||
s := state.NewForTestWithDataDir(t.TempDir())
|
||||
|
||||
_, ok := s.GetHostnameState("missing.example.com")
|
||||
if ok {
|
||||
@@ -857,7 +857,7 @@ func TestHostnameState_GetSet(t *testing.T) {
|
||||
func TestPortState_GetSetDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := state.NewForTest()
|
||||
s := state.NewForTestWithDataDir(t.TempDir())
|
||||
|
||||
_, ok := s.GetPortState("1.2.3.4:80")
|
||||
if ok {
|
||||
@@ -895,7 +895,7 @@ func TestPortState_GetSetDelete(t *testing.T) {
|
||||
func TestGetAllPortKeys(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := state.NewForTest()
|
||||
s := state.NewForTestWithDataDir(t.TempDir())
|
||||
|
||||
keys := s.GetAllPortKeys()
|
||||
if len(keys) != 0 {
|
||||
@@ -937,7 +937,7 @@ func TestGetAllPortKeys(t *testing.T) {
|
||||
func TestCertificateState_GetSet(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := state.NewForTest()
|
||||
s := state.NewForTestWithDataDir(t.TempDir())
|
||||
|
||||
_, ok := s.GetCertificateState("1.2.3.4:443:www.example.com")
|
||||
if ok {
|
||||
@@ -1158,7 +1158,7 @@ func TestLoadPreservesExistingStateOnMissingFile(t *testing.T) {
|
||||
func TestConcurrentGetSet(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := state.NewForTest()
|
||||
s := state.NewForTestWithDataDir(t.TempDir())
|
||||
|
||||
const goroutines = 20
|
||||
|
||||
@@ -1368,35 +1368,6 @@ func TestMultipleSavesOverwrite(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestNewForTest verifies the test helper creates a valid empty state.
|
||||
func TestNewForTest(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := state.NewForTest()
|
||||
|
||||
snap := s.GetSnapshot()
|
||||
|
||||
if snap.Version != 1 {
|
||||
t.Errorf("version: got %d, want 1", snap.Version)
|
||||
}
|
||||
|
||||
if snap.Domains == nil {
|
||||
t.Error("Domains map should be initialized")
|
||||
}
|
||||
|
||||
if snap.Hostnames == nil {
|
||||
t.Error("Hostnames map should be initialized")
|
||||
}
|
||||
|
||||
if snap.Ports == nil {
|
||||
t.Error("Ports map should be initialized")
|
||||
}
|
||||
|
||||
if snap.Certificates == nil {
|
||||
t.Error("Certificates map should be initialized")
|
||||
}
|
||||
}
|
||||
|
||||
// TestSaveFilePermissions verifies the saved file has restricted permissions.
|
||||
func TestSaveFilePermissions(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
Reference in New Issue
Block a user