Use testing.TempDir() where possible

Refactor tests to use go built-in temporary directory utility for tests.

Also avoid binding to default port (which may be in use)
This commit is contained in:
Marco Primi
2022-12-08 11:16:45 -08:00
parent dcd7ffdc4b
commit f8a030bc4a
49 changed files with 599 additions and 2237 deletions

View File

@@ -542,7 +542,6 @@ func TestClusterNameOption(t *testing.T) {
listen: 127.0.0.1:-1
}
`))
defer removeFile(t, conf)
s, opts := RunServerWithConfig(conf)
defer s.Shutdown()
@@ -563,7 +562,6 @@ func TestEphemeralClusterName(t *testing.T) {
listen: 127.0.0.1:-1
}
`))
defer removeFile(t, conf)
s, opts := RunServerWithConfig(conf)
defer s.Shutdown()
@@ -600,7 +598,6 @@ func TestClusterNameConflictsDropRoutes(t *testing.T) {
listen: 127.0.0.1:5244
}
`))
defer removeFile(t, conf)
s1, _ := RunServerWithConfig(conf)
defer s1.Shutdown()
@@ -614,7 +611,6 @@ func TestClusterNameConflictsDropRoutes(t *testing.T) {
routes = [nats-route://127.0.0.1:5244]
}
`))
defer removeFile(t, conf2)
s2, _ := RunServerWithConfig(conf2)
defer s2.Shutdown()
@@ -635,7 +631,6 @@ func TestClusterNameDynamicNegotiation(t *testing.T) {
listen: 127.0.0.1:-1
cluster {listen: 127.0.0.1:5244}
`))
defer removeFile(t, conf)
seed, _ := RunServerWithConfig(conf)
defer seed.Shutdown()
@@ -647,7 +642,6 @@ func TestClusterNameDynamicNegotiation(t *testing.T) {
routes = [nats-route://127.0.0.1:5244]
}
`))
defer removeFile(t, oconf)
// Create a random number of additional servers, up to 20.
numServers := rand.Intn(20) + 1