Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v17] fix: Avoid large unix socket paths on lib/service tests #49779

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions lib/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestAdditionalExpectedRoles(t *testing.T) {
name: "everything enabled",
cfg: func() *servicecfg.Config {
cfg := servicecfg.MakeDefaultConfig()
cfg.DataDir = t.TempDir()
cfg.DataDir = makeTempDir(t)
cfg.SetAuthServerAddress(utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"})
cfg.Auth.StorageConfig.Params["path"] = t.TempDir()
cfg.DiagnosticAddr = utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"}
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestAdditionalExpectedRoles(t *testing.T) {
name: "everything enabled with additional roles",
cfg: func() *servicecfg.Config {
cfg := servicecfg.MakeDefaultConfig()
cfg.DataDir = t.TempDir()
cfg.DataDir = makeTempDir(t)
cfg.SetAuthServerAddress(utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"})
cfg.Auth.StorageConfig.Params["path"] = t.TempDir()
cfg.DiagnosticAddr = utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"}
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestDynamicClientReuse(t *testing.T) {

cfg := servicecfg.MakeDefaultConfig()
cfg.Clock = fakeClock
cfg.DataDir = t.TempDir()
cfg.DataDir = makeTempDir(t)
cfg.SetAuthServerAddress(utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"})
cfg.Auth.Enabled = true
cfg.Auth.ListenAddr = utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"}
Expand Down Expand Up @@ -274,7 +274,7 @@ func TestMonitor(t *testing.T) {
cfg := servicecfg.MakeDefaultConfig()
cfg.Clock = fakeClock
var err error
cfg.DataDir = t.TempDir()
cfg.DataDir = makeTempDir(t)
cfg.DiagnosticAddr = utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"}
cfg.SetAuthServerAddress(utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"})
cfg.Auth.Enabled = true
Expand Down Expand Up @@ -785,7 +785,7 @@ func TestDesktopAccessFIPS(t *testing.T) {
cfg := servicecfg.MakeDefaultConfig()
cfg.SetAuthServerAddress(utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"})
cfg.Clock = clockwork.NewFakeClock()
cfg.DataDir = t.TempDir()
cfg.DataDir = makeTempDir(t)
cfg.Auth.Enabled = false
cfg.Proxy.Enabled = false
cfg.SSH.Enabled = false
Expand Down Expand Up @@ -910,7 +910,7 @@ func TestSetupProxyTLSConfig(t *testing.T) {
cfg := servicecfg.MakeDefaultConfig()
cfg.CircuitBreakerConfig = breaker.NoopBreakerConfig()
cfg.Proxy.ACME.Enabled = tc.acmeEnabled
cfg.DataDir = t.TempDir()
cfg.DataDir = makeTempDir(t)
cfg.Proxy.PublicAddrs = utils.MustParseAddrList("localhost")
process := TeleportProcess{
Config: cfg,
Expand All @@ -935,7 +935,7 @@ func TestTeleportProcess_reconnectToAuth(t *testing.T) {
cfg := servicecfg.MakeDefaultConfig()
cfg.SetAuthServerAddress(utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"})
cfg.Clock = clockwork.NewRealClock()
cfg.DataDir = t.TempDir()
cfg.DataDir = makeTempDir(t)
cfg.Auth.Enabled = false
cfg.Proxy.Enabled = false
cfg.SSH.Enabled = true
Expand Down Expand Up @@ -1003,7 +1003,7 @@ func TestTeleportProcessAuthVersionCheck(t *testing.T) {

authCfg := servicecfg.MakeDefaultConfig()
authCfg.SetAuthServerAddress(listenAddr)
authCfg.DataDir = t.TempDir()
authCfg.DataDir = makeTempDir(t)
authCfg.Auth.Enabled = true
authCfg.Auth.StaticTokens = staticTokens
authCfg.Auth.StorageConfig.Type = lite.GetName()
Expand All @@ -1025,7 +1025,7 @@ func TestTeleportProcessAuthVersionCheck(t *testing.T) {
authListenAddr := authProc.Config.AuthServerAddresses()[0]
nodeCfg := servicecfg.MakeDefaultConfig()
nodeCfg.SetAuthServerAddress(authListenAddr)
nodeCfg.DataDir = t.TempDir()
nodeCfg.DataDir = makeTempDir(t)
nodeCfg.SetToken(token)
nodeCfg.Auth.Enabled = false
nodeCfg.Proxy.Enabled = false
Expand Down Expand Up @@ -1612,11 +1612,7 @@ func TestDebugServiceStartSocket(t *testing.T) {
t.Parallel()
fakeClock := clockwork.NewFakeClock()

var err error
dataDir, err := os.MkdirTemp("", "*")
require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(dataDir) })

dataDir := makeTempDir(t)
cfg := servicecfg.MakeDefaultConfig()
cfg.DebugService.Enabled = true
cfg.Clock = fakeClock
Expand Down Expand Up @@ -1739,7 +1735,7 @@ func TestInstanceMetadata(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
cfg := newCfg()
cfg.DataDir = t.TempDir()
cfg.DataDir = makeTempDir(t)
cfg.Auth.StorageConfig.Params["path"] = t.TempDir()
cfg.InstanceMetadataClient = tc.imClient

Expand Down Expand Up @@ -1800,7 +1796,7 @@ func TestInitDatabaseService(t *testing.T) {
t.Parallel()

cfg := servicecfg.MakeDefaultConfig()
cfg.DataDir = t.TempDir()
cfg.DataDir = makeTempDir(t)
cfg.DebugService = servicecfg.DebugConfig{
Enabled: false,
}
Expand Down Expand Up @@ -1845,3 +1841,14 @@ func TestInitDatabaseService(t *testing.T) {
})
}
}

// makeTempDir makes a temp dir with a shorter name than t.TempDir() in order to
// avoid https://github.com/golang/go/issues/62614.
func makeTempDir(t *testing.T) string {
t.Helper()

tempDir, err := os.MkdirTemp("", "teleport-test-")
require.NoError(t, err, "os.MkdirTemp() failed")
t.Cleanup(func() { os.RemoveAll(tempDir) })
return tempDir
}
Loading