Skip to content

Commit 8192f93

Browse files
committed
Refactoring: extract common logic into helper function
1 parent 2dfd9ca commit 8192f93

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

pkg/testing/define/define.go

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,13 @@ func Version() string {
8383
// NewFixtureFromLocalBuild returns a new Elastic Agent testing fixture with a LocalFetcher and
8484
// the agent logging to the test logger.
8585
func NewFixtureFromLocalBuild(t *testing.T, version string, opts ...atesting.FixtureOpt) (*atesting.Fixture, error) {
86-
buildsDir := os.Getenv("AGENT_BUILD_DIR")
87-
if buildsDir == "" {
88-
projectDir, err := findProjectRoot()
89-
if err != nil {
90-
return nil, err
91-
}
92-
buildsDir = filepath.Join(projectDir, "build", "distributions")
93-
}
94-
95-
return NewFixtureWithBinary(t, version, "elastic-agent", buildsDir, false, opts...)
86+
return NewFixtureWithBinary(t, version, "elastic-agent", buildsDir(), false, opts...)
9687
}
9788

9889
// NewFixtureFromLocalFIPSBuild returns a new FIPS-capable Elastic Agent testing fixture with a LocalFetcher
9990
// and the agent logging to the test logger.
10091
func NewFixtureFromLocalFIPSBuild(t *testing.T, version string, opts ...atesting.FixtureOpt) (*atesting.Fixture, error) {
101-
buildsDir := os.Getenv("AGENT_BUILD_DIR")
102-
if buildsDir == "" {
103-
projectDir, err := findProjectRoot()
104-
if err != nil {
105-
return nil, err
106-
}
107-
buildsDir = filepath.Join(projectDir, "build", "distributions")
108-
}
109-
110-
return NewFixtureWithBinary(t, version, "elastic-agent", buildsDir, true, opts...)
92+
return NewFixtureWithBinary(t, version, "elastic-agent", buildsDir(), true, opts...)
11193
}
11294

11395
// NewFixtureWithBinary returns a new Elastic Agent testing fixture with a LocalFetcher and
@@ -317,3 +299,16 @@ func getKibanaClient() (*kibana.Client, error) {
317299
}
318300
return c, nil
319301
}
302+
303+
func buildsDir() string {
304+
buildsDir := os.Getenv("AGENT_BUILD_DIR")
305+
if buildsDir == "" {
306+
projectDir, err := findProjectRoot()
307+
if err != nil {
308+
return nil, err
309+
}
310+
buildsDir = filepath.Join(projectDir, "build", "distributions")
311+
}
312+
313+
return buildsDir
314+
}

0 commit comments

Comments
 (0)