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

@@ -357,7 +357,6 @@ func TestReloadDoesNotWipeAccountsWithOperatorMode(t *testing.T) {
`
contents := strings.Replace(fmt.Sprintf(cf, "", sysPub, sysPub, sysJWT, accPub, accJWT), "\n\t", "\n", -1)
conf := createConfFile(t, []byte(contents))
defer removeFile(t, conf)
s, opts := RunServerWithConfig(conf)
defer s.Shutdown()
@@ -367,7 +366,6 @@ func TestReloadDoesNotWipeAccountsWithOperatorMode(t *testing.T) {
contents2 := strings.Replace(fmt.Sprintf(cf, routeStr, sysPub, sysPub, sysJWT, accPub, accJWT), "\n\t", "\n", -1)
conf2 := createConfFile(t, []byte(contents2))
defer removeFile(t, conf2)
s2, opts2 := RunServerWithConfig(conf2)
defer s2.Shutdown()
@@ -481,7 +479,6 @@ func TestReloadDoesUpdateAccountsWithMemoryResolver(t *testing.T) {
`
contents := strings.Replace(fmt.Sprintf(cf, "", sysPub, sysPub, sysJWT, accPub, accJWT), "\n\t", "\n", -1)
conf := createConfFile(t, []byte(contents))
defer removeFile(t, conf)
s, opts := RunServerWithConfig(conf)
defer s.Shutdown()
@@ -573,7 +570,6 @@ func TestReloadFailsWithBadAccountsWithMemoryResolver(t *testing.T) {
`
contents := strings.Replace(fmt.Sprintf(cf, "", sysPub, sysPub, sysJWT, apub, ajwt), "\n\t", "\n", -1)
conf := createConfFile(t, []byte(contents))
defer removeFile(t, conf)
s, _ := RunServerWithConfig(conf)
defer s.Shutdown()
@@ -637,7 +633,6 @@ func TestConnsRequestDoesNotLoadAccountCheckingConnLimits(t *testing.T) {
`
contents := strings.Replace(fmt.Sprintf(cf, "", sysPub, sysPub, sysJWT, accPub, accJWT), "\n\t", "\n", -1)
conf := createConfFile(t, []byte(contents))
defer removeFile(t, conf)
s, opts := RunServerWithConfig(conf)
defer s.Shutdown()
@@ -647,7 +642,6 @@ func TestConnsRequestDoesNotLoadAccountCheckingConnLimits(t *testing.T) {
contents2 := strings.Replace(fmt.Sprintf(cf, routeStr, sysPub, sysPub, sysJWT, accPub, accJWT), "\n\t", "\n", -1)
conf2 := createConfFile(t, []byte(contents2))
defer removeFile(t, conf2)
s2, _ := RunServerWithConfig(conf2)
defer s2.Shutdown()