Skip to content

Commit

Permalink
Fix DataDog exporter unit test which was failing when run on EC2 inst…
Browse files Browse the repository at this point in the history
…ance development environment. (#3528)

The test assumed that the EC2 Instance Metadata Service would not be accessible.  Now disable it via environment
variable to enforce that assumption.
  • Loading branch information
straussb authored Jun 1, 2021
1 parent 984264b commit 0bedbca
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions exporter/datadogexporter/metadata/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ func TestHost(t *testing.T) {
})
assert.Equal(t, host, "test-host-2")

// Disable EC2 Metadata service to prevent fetching hostname from there,
// in case the test is running on an EC2 instance
const awsEc2MetadataDisabled = "AWS_EC2_METADATA_DISABLED"
curr := os.Getenv(awsEc2MetadataDisabled)
err := os.Setenv(awsEc2MetadataDisabled, "true")
require.NoError(t, err)
defer os.Setenv(awsEc2MetadataDisabled, curr)

host = GetHost(logger, &config.Config{})
osHostname, err := os.Hostname()
require.NoError(t, err)
Expand Down

0 comments on commit 0bedbca

Please sign in to comment.