Skip to content

Commit e46a25b

Browse files
author
kaanyalti
committed
enhancement(6394): use addressFromPath and SetClient
1 parent 5699226 commit e46a25b

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

pkg/testing/fixture_install.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/elastic/elastic-agent-libs/mapstr"
2727
agentsystemprocess "github.com/elastic/elastic-agent-system-metrics/metric/system/process"
2828
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
29+
"github.com/elastic/elastic-agent/pkg/control"
2930
"github.com/elastic/elastic-agent/pkg/control/v2/client"
3031
"github.com/elastic/elastic-agent/pkg/core/process"
3132
)
@@ -445,10 +446,16 @@ func getProcesses(t *gotesting.T, regex string) []runningProcess {
445446
return processes
446447
}
447448

448-
func (f *Fixture) SetClient() {
449-
socketPath := "unix:///var/lib/elastic-agent/elastic-agent.sock"
449+
func (f *Fixture) SetClient() error {
450+
socketPath, err := control.AddressFromPath(f.operatingSystem, f.workDir)
451+
if err != nil {
452+
return fmt.Errorf("failed to get control protcol address: %w", err)
453+
}
454+
450455
c := client.New(client.WithAddress(socketPath))
451456
f.setClient(c)
457+
458+
return nil
452459
}
453460

454461
// installDeb installs the prepared Elastic Agent binary from the deb
@@ -508,9 +515,10 @@ func (f *Fixture) installDeb(ctx context.Context, installOpts *InstallOpts, shou
508515
return out, fmt.Errorf("systemctl start elastic-agent failed: %w", err)
509516
}
510517

511-
socketPath := "unix:///var/lib/elastic-agent/elastic-agent.sock"
512-
c := client.New(client.WithAddress(socketPath))
513-
f.setClient(c)
518+
err = f.SetClient()
519+
if err != nil {
520+
return nil, err
521+
}
514522

515523
if !shouldEnroll {
516524
return nil, nil
@@ -603,9 +611,10 @@ func (f *Fixture) installRpm(ctx context.Context, installOpts *InstallOpts, shou
603611
return out, fmt.Errorf("systemctl start elastic-agent failed: %w", err)
604612
}
605613

606-
socketPath := "unix:///var/lib/elastic-agent/elastic-agent.sock"
607-
c := client.New(client.WithAddress(socketPath))
608-
f.setClient(c)
614+
err = f.SetClient()
615+
if err != nil {
616+
return nil, err
617+
}
609618

610619
if !shouldEnroll {
611620
return nil, nil

0 commit comments

Comments
 (0)