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

[v15] fix: Avoid large unix socket paths on lib/service tests #49781

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
37 changes: 22 additions & 15 deletions lib/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,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 @@ -130,7 +130,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 @@ -190,7 +190,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 @@ -272,7 +272,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 @@ -782,7 +782,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 @@ -907,7 +907,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 Down Expand Up @@ -941,7 +941,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 @@ -1009,7 +1009,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 @@ -1031,7 +1031,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 @@ -1611,11 +1611,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 @@ -1738,7 +1734,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 All @@ -1758,3 +1754,14 @@ func TestInstanceMetadata(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