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

Rename define.NewFixture to define.NewFixtureFromLocalBuild #4562

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions pkg/testing/define/define.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ func Version() string {
return ver
}

// NewFixture returns a new Elastic Agent testing fixture with a LocalFetcher and
// NewFixtureFromLocalBuild returns a new Elastic Agent testing fixture with a LocalFetcher and
// the agent logging to the test logger.
func NewFixture(t *testing.T, version string, opts ...atesting.FixtureOpt) (*atesting.Fixture, error) {
func NewFixtureFromLocalBuild(t *testing.T, version string, opts ...atesting.FixtureOpt) (*atesting.Fixture, error) {
buildsDir := os.Getenv("AGENT_BUILD_DIR")
if buildsDir == "" {
projectDir, err := findProjectRoot()
Expand All @@ -82,7 +82,7 @@ func NewFixture(t *testing.T, version string, opts ...atesting.FixtureOpt) (*ate

}

// NewFixture returns a new Elastic Agent testing fixture with a LocalFetcher and
// NewFixtureWithBinary returns a new Elastic Agent testing fixture with a LocalFetcher and
// the agent logging to the test logger.
func NewFixtureWithBinary(t *testing.T, version string, binary string, buildsDir string, opts ...atesting.FixtureOpt) (*atesting.Fixture, error) {
ver, err := semver.ParseVersion(version)
Expand Down
6 changes: 3 additions & 3 deletions testing/integration/agent_long_running_leak_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (runner *ExtendedRunner) SetupSuite() {
Privileged: true,
}

fixture, err := define.NewFixture(runner.T(), define.Version())
fixture, err := define.NewFixtureFromLocalBuild(runner.T(), define.Version())
require.NoError(runner.T(), err)
runner.agentFixture = fixture

Expand Down Expand Up @@ -173,7 +173,7 @@ func (runner *ExtendedRunner) TestHandleLeak() {
// if the slope is increasing above a certain rate, fail the test
// A number of factors can change the slope during a test; shortened runtime (lots of handles allocated in the first few seconds, producing an upward slope),
// filebeat trying to open a large number of log files, etc
//handleSlopeFailure := 0.1
// handleSlopeFailure := 0.1
for _, mon := range runner.resourceWatchers {
handleSlopeFailure := 0.1

Expand Down Expand Up @@ -320,7 +320,7 @@ func (gm *goroutinesMonitor) Update(t *testing.T, fixture *atesting.Fixture) {
}

func (gm *goroutinesMonitor) GetSlopeHandlers() []tools.Slope {
//handleSlopeFailure := 0.1
// handleSlopeFailure := 0.1
slopes := []tools.Slope{}
for _, handle := range gm.handles {
slopes = append(slopes, handle.regGoroutines)
Expand Down
8 changes: 4 additions & 4 deletions testing/integration/apm_propagation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestAPMConfig(t *testing.T) {
Group: Default,
Stack: &define.Stack{},
})
f, err := define.NewFixture(t, define.Version())
f, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

deadline := time.Now().Add(10 * time.Minute)
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestAPMConfig(t *testing.T) {
return count > 0
}, 1*time.Minute, time.Second)

//change the configuration with a new environment and check that the update has been processed
// change the configuration with a new environment and check that the update has been processed
environment = environment + "-changed"
modifiedAgentConfig := generateAgentConfigForAPM(t, agentConfigTemplateString, info, environment)
t.Logf("Rendered agent modified config:\n%s", modifiedAgentConfig)
Expand Down Expand Up @@ -178,8 +178,8 @@ func countAPMTraces(ctx context.Context, t *testing.T, esClient *elasticsearch.C
Count int
}

//decoder := json.NewDecoder(response.Body)
//err = decoder.Decode(&body)
// decoder := json.NewDecoder(response.Body)
// err = decoder.Decode(&body)
bodyBytes, _ := io.ReadAll(response.Body)

t.Logf("received ES response: %s", bodyBytes)
Expand Down
2 changes: 1 addition & 1 deletion testing/integration/container_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestContainerCMD(t *testing.T) {
})
ctx := context.Background()

agentFixture, err := define.NewFixture(t, define.Version())
agentFixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

createPolicyReq := kibana.AgentPolicy{
Expand Down
2 changes: 1 addition & 1 deletion testing/integration/delay_enroll_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestDelayEnroll(t *testing.T) {
ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
defer cancel()

agentFixture, err := define.NewFixture(t, define.Version())
agentFixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

// 1. Create a policy in Fleet with monitoring enabled.
Expand Down
4 changes: 2 additions & 2 deletions testing/integration/diagnostics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestDiagnosticsOptionalValues(t *testing.T) {
Local: false,
})

fixture, err := define.NewFixture(t, define.Version())
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
Expand All @@ -119,7 +119,7 @@ func TestDiagnosticsCommand(t *testing.T) {
Local: false,
})

f, err := define.NewFixture(t, define.Version())
f, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
Expand Down
12 changes: 6 additions & 6 deletions testing/integration/endpoint_security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func testInstallAndCLIUninstallWithEndpointSecurity(t *testing.T, info *define.I
defer cancel()

// Get path to agent executable.
fixture, err := define.NewFixture(t, define.Version())
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err, "could not create agent fixture")

t.Log("Enrolling the agent in Fleet")
Expand Down Expand Up @@ -226,7 +226,7 @@ func testInstallAndCLIUninstallWithEndpointSecurity(t *testing.T, info *define.I

func testInstallAndUnenrollWithEndpointSecurity(t *testing.T, info *define.Info, protected bool) {
// Get path to agent executable.
fixture, err := define.NewFixture(t, define.Version())
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

t.Log("Enrolling the agent in Fleet")
Expand Down Expand Up @@ -339,7 +339,7 @@ func testInstallAndUnenrollWithEndpointSecurity(t *testing.T, info *define.Info,

func testInstallWithEndpointSecurityAndRemoveEndpointIntegration(t *testing.T, info *define.Info, protected bool) {
// Get path to agent executable.
fixture, err := define.NewFixture(t, define.Version())
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

t.Log("Enrolling the agent in Fleet")
Expand Down Expand Up @@ -511,7 +511,7 @@ func TestEndpointSecurityNonDefaultBasePath(t *testing.T) {
defer cn()

// Get path to agent executable.
fixture, err := define.NewFixture(t, define.Version())
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

t.Log("Enrolling the agent in Fleet")
Expand Down Expand Up @@ -589,7 +589,7 @@ func TestEndpointSecurityUnprivileged(t *testing.T) {
defer cn()

// Get path to agent executable.
fixture, err := define.NewFixture(t, define.Version())
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

t.Log("Enrolling the agent in Fleet")
Expand Down Expand Up @@ -665,7 +665,7 @@ func TestEndpointLogsAreCollectedInDiagnostics(t *testing.T) {
defer cn()

// Get path to agent executable.
fixture, err := define.NewFixture(t, define.Version())
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

t.Log("Enrolling the agent in Fleet")
Expand Down
2 changes: 1 addition & 1 deletion testing/integration/fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestFakeComponent(t *testing.T) {
Local: true,
})

f, err := define.NewFixture(t, define.Version())
f, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
Expand Down
2 changes: 1 addition & 1 deletion testing/integration/fqdn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestFQDN(t *testing.T) {
Sudo: true,
})

agentFixture, err := define.NewFixture(t, define.Version())
agentFixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

externalIP, err := getExternalIP()
Expand Down
4 changes: 2 additions & 2 deletions testing/integration/install_privileged_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestInstallPrivilegedWithoutBasePath(t *testing.T) {
})

// Get path to Elastic Agent executable
fixture, err := define.NewFixture(t, define.Version())
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestInstallPrivilegedWithBasePath(t *testing.T) {
})

// Get path to Elastic Agent executable
fixture, err := define.NewFixture(t, define.Version())
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
Expand Down
6 changes: 3 additions & 3 deletions testing/integration/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestInstallWithoutBasePath(t *testing.T) {
})

// Get path to Elastic Agent executable
fixture, err := define.NewFixture(t, define.Version())
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestInstallWithBasePath(t *testing.T) {
})

// Get path to Elastic Agent executable
fixture, err := define.NewFixture(t, define.Version())
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestRepeatedInstallUninstall(t *testing.T) {

topPath := filepath.Join(defaultBasePath, "Elastic", "Agent")
// Get path to Elastic Agent executable
fixture, err := define.NewFixture(t, define.Version())
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(maxRunTime))
Expand Down
8 changes: 4 additions & 4 deletions testing/integration/logs_ingestion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestLogIngestionFleetManaged(t *testing.T) {
ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
defer cancel()

agentFixture, err := define.NewFixture(t, define.Version())
agentFixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

// 1. Create a policy in Fleet with monitoring enabled.
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestDebLogIngestFleetManaged(t *testing.T) {
ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
defer cancel()

agentFixture, err := define.NewFixture(t, define.Version(), atesting.WithPackageFormat("deb"))
agentFixture, err := define.NewFixtureFromLocalBuild(t, define.Version(), atesting.WithPackageFormat("deb"))
require.NoError(t, err)

// 1. Create a policy in Fleet with monitoring enabled.
Expand Down Expand Up @@ -185,7 +185,7 @@ func TestRpmLogIngestFleetManaged(t *testing.T) {
ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
defer cancel()

agentFixture, err := define.NewFixture(t, define.Version(), atesting.WithPackageFormat("rpm"))
agentFixture, err := define.NewFixtureFromLocalBuild(t, define.Version(), atesting.WithPackageFormat("rpm"))
require.NoError(t, err)

// 1. Create a policy in Fleet with monitoring enabled.
Expand Down Expand Up @@ -280,7 +280,7 @@ func testMonitoringLogsAreShipped(
"add_cloud_metadata: received error failed requesting openstack metadata: Get \\\"https://169.254.169.254/2009-04-04/meta-data/instance-type\\\": dial tcp 169.254.169.254:443: connect: connection refused", // okay for the cloud metadata to not work
"add_cloud_metadata: received error failed with http status code 404", // okay for the cloud metadata to not work
"add_cloud_metadata: received error failed fetching EC2 Identity Document: operation error ec2imds: GetInstanceIdentityDocument, http response error StatusCode: 404, request to EC2 IMDS failed", // okay for the cloud metadata to not work
"failed to invoke rollback watcher: failed to start Upgrade Watcher: fork/exec /var/lib/elastic-agent/elastic-agent: no such file or directory", //on debian this happens probably need to fix.
"failed to invoke rollback watcher: failed to start Upgrade Watcher: fork/exec /var/lib/elastic-agent/elastic-agent: no such file or directory", // on debian this happens probably need to fix.
})
})
t.Logf("error logs: Got %d documents", len(docs.Hits.Hits))
Expand Down
2 changes: 1 addition & 1 deletion testing/integration/metrics_monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestMetricsMonitoringCorrectBinaries(t *testing.T) {
}

func (runner *MetricsRunner) SetupSuite() {
fixture, err := define.NewFixture(runner.T(), define.Version())
fixture, err := define.NewFixtureFromLocalBuild(runner.T(), define.Version())
require.NoError(runner.T(), err)
runner.agentFixture = fixture

Expand Down
4 changes: 2 additions & 2 deletions testing/integration/otel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestOtelFileProcessing(t *testing.T) {
cfgFilePath := filepath.Join(tempDir, "otel.yml")
require.NoError(t, os.WriteFile(cfgFilePath, []byte(fileProcessingConfig), 0600))

fixture, err := define.NewFixture(t, define.Version(), aTesting.WithAdditionalArgs([]string{"--config", cfgFilePath}))
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version(), aTesting.WithAdditionalArgs([]string{"--config", cfgFilePath}))
require.NoError(t, err)

ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestOtelAPMIngestion(t *testing.T) {
require.NoError(t, os.WriteFile(cfgFilePath, []byte(apmConfig), 0600))
require.NoError(t, os.WriteFile(filepath.Join(tempDir, fileName), []byte{}, 0600))

fixture, err := define.NewFixture(t, define.Version(), aTesting.WithAdditionalArgs([]string{"--config", cfgFilePath}))
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version(), aTesting.WithAdditionalArgs([]string{"--config", cfgFilePath}))
require.NoError(t, err)

ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
Expand Down
4 changes: 2 additions & 2 deletions testing/integration/package_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestPackageVersion(t *testing.T) {
Local: true,
})

f, err := define.NewFixture(t, define.Version())
f, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestComponentBuildHashInDiagnostics(t *testing.T) {
})
ctx := context.Background()

f, err := define.NewFixture(t, define.Version())
f, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err, "could not create new fixture")

err = f.Prepare(ctx)
Expand Down
4 changes: 2 additions & 2 deletions testing/integration/proxy_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ func SetupTest(t *testing.T) *ProxyURL {
proxytest.WithRequestLog("proxy-2", t.Logf),
proxytest.WithVerboseLog())

f, err := define.NewFixture(t,
f, err := define.NewFixtureFromLocalBuild(t,
p.agentVersion,
integrationtest.WithAllowErrors(),
integrationtest.WithLogOutput())
require.NoError(t, err, "SetupTest: NewFixture failed")
require.NoError(t, err, "SetupTest: NewFixtureFromLocalBuild failed")

ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
defer cancel()
Expand Down
2 changes: 1 addition & 1 deletion testing/integration/upgrade_broken_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestUpgradeBrokenPackageVersion(t *testing.T) {

// Start at the build version as we want to test the retry
// logic that is in the build.
startFixture, err := define.NewFixture(t, define.Version())
startFixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

// Upgrade to an old build.
Expand Down
2 changes: 1 addition & 1 deletion testing/integration/upgrade_downgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestStandaloneDowngradeToSpecificSnapshotBuild(t *testing.T) {

// start at the build version as we want to test the retry
// logic that is in the build.
startFixture, err := define.NewFixture(t, define.Version())
startFixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)
startVersion, err := startFixture.ExecVersion(ctx)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions testing/integration/upgrade_fleet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func testFleetManagedUpgrade(t *testing.T, info *define.Info, unprivileged bool)

// Start at the build version as we want to test the retry
// logic that is in the build.
startFixture, err := define.NewFixture(t, define.Version())
startFixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)
err = startFixture.Prepare(ctx)
require.NoError(t, err)
Expand Down Expand Up @@ -171,7 +171,7 @@ func testFleetAirGappedUpgrade(t *testing.T, stack *define.Info, unprivileged bo
"It should not affect the connection to the stack. Host: %s, response body: %s",
stack.KibanaClient.URL, host, body)

fixture, err := define.NewFixture(t, define.Version())
fixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)
err = fixture.Prepare(ctx)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions testing/integration/upgrade_gpg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestStandaloneUpgradeWithGPGFallback(t *testing.T) {

// Start at the build version as we want to test the retry
// logic that is in the build.
startFixture, err := define.NewFixture(t, define.Version())
startFixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)
startVersionInfo, err := startFixture.ExecVersion(ctx)
require.NoError(t, err)
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestStandaloneUpgradeWithGPGFallbackOneRemoteFailing(t *testing.T) {

// Start at the build version as we want to test the retry
// logic that is in the build.
startFixture, err := define.NewFixture(t, define.Version())
startFixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

// Upgrade to an old build.
Expand Down
4 changes: 2 additions & 2 deletions testing/integration/upgrade_rollback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestStandaloneUpgradeRollback(t *testing.T) {
require.NoError(t, err, "failed to get start agent build version info")

// Upgrade to the build under test.
endFixture, err := define.NewFixture(t, define.Version())
endFixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

t.Logf("Testing Elastic Agent upgrade from %s to %s...", upgradeFromVersion, define.Version())
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestStandaloneUpgradeRollbackOnRestarts(t *testing.T) {
require.NoError(t, err, "failed to get start agent build version info")

// Upgrade to the build under test.
endFixture, err := define.NewFixture(t, define.Version())
endFixture, err := define.NewFixtureFromLocalBuild(t, define.Version())
require.NoError(t, err)

t.Logf("Testing Elastic Agent upgrade from %s to %s...", upgradeFromVersion, define.Version())
Expand Down
Loading
Loading