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

fix: Avoid large unix socket paths on lib/service tests #49673

Merged
merged 1 commit into from
Dec 4, 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
41 changes: 24 additions & 17 deletions lib/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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 @@ -134,7 +134,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 @@ -194,7 +194,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 @@ -276,7 +276,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 @@ -787,7 +787,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 @@ -912,7 +912,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 @@ -937,7 +937,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 @@ -1005,7 +1005,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 @@ -1027,7 +1027,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 @@ -1614,11 +1614,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 @@ -1741,7 +1737,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 @@ -1802,7 +1798,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 @@ -1858,7 +1854,7 @@ func TestAgentRolloutController(t *testing.T) {
// Test setup: create a Teleport Auth config
fakeClock := clockwork.NewFakeClock()

dataDir := t.TempDir()
dataDir := makeTempDir(t)

cfg := servicecfg.MakeDefaultConfig()
cfg.Clock = fakeClock
Expand Down Expand Up @@ -1920,3 +1916,14 @@ func TestAgentRolloutController(t *testing.T) {
return rollout.Spec.GetTargetVersion() == version.Spec.GetAgents().GetTargetVersion()
}, time.Second, 10*time.Millisecond)
}

// 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