Skip to content

Commit

Permalink
Address conflict with open-telemetry#31031
Browse files Browse the repository at this point in the history
  • Loading branch information
mx-psi committed Mar 6, 2024
1 parent cf95953 commit 0b08aaf
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions extension/sumologicextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/open-telemetry/opentelemetry-collector-contrib/extension/sumologicextension/api"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/sumologicextension/credentials"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/sumologicextension/internal/metadata"
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -74,7 +75,7 @@ func TestBasicExtensionConstruction(t *testing.T) {

for _, tc := range testcases {
t.Run(tc.Name, func(t *testing.T) {
se, err := newSumologicExtension(tc.Config, zap.NewNop(), component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(tc.Config, zap.NewNop(), component.NewID(metadata.Type), "1.0.0")
if tc.WantErr {
assert.Error(t, err)
} else {
Expand Down Expand Up @@ -137,7 +138,7 @@ func TestBasicStart(t *testing.T) {
cfg.Credentials.InstallationToken = "dummy_install_token"
cfg.CollectorCredentialsDirectory = dir

se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
require.NoError(t, se.Start(context.Background(), componenttest.NewNopHost()))
assert.NotEmpty(t, se.registrationInfo.CollectorCredentialID)
Expand Down Expand Up @@ -213,7 +214,7 @@ func TestStoreCredentials(t *testing.T) {
// Ensure the directory doesn't exist before running the extension
require.NoError(t, os.RemoveAll(dir))

se, err := newSumologicExtension(cfg, logger, component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, logger, component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
key := createHashKey(cfg)
fileName, err := credentials.HashKeyToFilename(key)
Expand All @@ -239,7 +240,7 @@ func TestStoreCredentials(t *testing.T) {
// Ensure the directory has 600 permissions
require.NoError(t, os.Chmod(dir, 0600))

se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
key := createHashKey(cfg)
fileName, err := credentials.HashKeyToFilename(key)
Expand All @@ -264,7 +265,7 @@ func TestStoreCredentials(t *testing.T) {
// Ensure the directory has 700 permissions
require.NoError(t, os.Chmod(dir, 0700))

se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
key := createHashKey(cfg)
fileName, err := credentials.HashKeyToFilename(key)
Expand All @@ -287,7 +288,7 @@ func TestStoreCredentials(t *testing.T) {
cfg := getConfig(srv.URL)
cfg.CollectorCredentialsDirectory = dir

se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
key := createHashKey(cfg)
fileName, err := credentials.HashKeyToFilename(key)
Expand Down Expand Up @@ -372,7 +373,7 @@ func TestStoreCredentials_PreexistingCredentialsAreUsed(t *testing.T) {
}),
)

se, err := newSumologicExtension(cfg, logger, component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, logger, component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)

fileName, err := credentials.HashKeyToFilename(hashKey)
Expand Down Expand Up @@ -467,7 +468,7 @@ func TestLocalFSCredentialsStore_WorkCorrectlyForMultipleExtensions(t *testing.T
logger2, err := zap.NewDevelopment(zap.Fields(zap.Int("#", 2)))
require.NoError(t, err)

se1, err := newSumologicExtension(cfg1, logger1, component.NewID("sumologic"), "1.0.0")
se1, err := newSumologicExtension(cfg1, logger1, component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, se1.Shutdown(context.Background())) })
fileName1, err := credentials.HashKeyToFilename(createHashKey(cfg1))
Expand All @@ -477,7 +478,7 @@ func TestLocalFSCredentialsStore_WorkCorrectlyForMultipleExtensions(t *testing.T
require.NoError(t, se1.Start(context.Background(), componenttest.NewNopHost()))
require.FileExists(t, credsPath1)

se2, err := newSumologicExtension(cfg2, logger2, component.NewID("sumologic"), "1.0.0")
se2, err := newSumologicExtension(cfg2, logger2, component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, se2.Shutdown(context.Background())) })
fileName2, err := credentials.HashKeyToFilename(createHashKey(cfg2))
Expand Down Expand Up @@ -553,7 +554,7 @@ func TestRegisterEmptyCollectorName(t *testing.T) {
cfg.Credentials.InstallationToken = "dummy_install_token"
cfg.CollectorCredentialsDirectory = dir

se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
require.NoError(t, se.Start(context.Background(), componenttest.NewNopHost()))
require.NoError(t, err)
Expand Down Expand Up @@ -641,7 +642,7 @@ func TestRegisterEmptyCollectorNameForceRegistration(t *testing.T) {
cfg.CollectorCredentialsDirectory = dir
cfg.ForceRegistration = true

se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
require.NoError(t, se.Start(context.Background(), componenttest.NewNopHost()))
require.NoError(t, se.Shutdown(context.Background()))
Expand All @@ -650,7 +651,7 @@ func TestRegisterEmptyCollectorNameForceRegistration(t *testing.T) {
colCreds, err := se.credentialsStore.Get(se.hashKey)
require.NoError(t, err)
colName := colCreds.CollectorName
se, err = newSumologicExtension(cfg, zap.NewNop(), component.NewID("sumologic"), "1.0.0")
se, err = newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
require.NoError(t, se.Start(context.Background(), componenttest.NewNopHost()))
assert.Equal(t, se.collectorName, colName)
Expand Down Expand Up @@ -714,7 +715,7 @@ func TestCollectorSendsBasicAuthHeadersOnRegistration(t *testing.T) {
cfg.Credentials.InstallationToken = "dummy_install_token"
cfg.CollectorCredentialsDirectory = dir

se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
require.NoError(t, se.Start(context.Background(), componenttest.NewNopHost()))
require.NoError(t, se.Shutdown(context.Background()))
Expand Down Expand Up @@ -1008,7 +1009,7 @@ func TestCollectorCheckingCredentialsFoundInLocalStorage(t *testing.T) {
logger, err := zap.NewDevelopment()
require.NoError(t, err)

se, err := newSumologicExtension(cfg, logger, component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, logger, component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
require.NoError(t, se.Start(context.Background(), componenttest.NewNopHost()))

Expand Down Expand Up @@ -1097,7 +1098,7 @@ func TestRegisterEmptyCollectorNameWithBackoff(t *testing.T) {
cfg.BackOff.InitialInterval = time.Millisecond
cfg.BackOff.MaxInterval = time.Millisecond

se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
require.NoError(t, se.Start(context.Background(), componenttest.NewNopHost()))
require.Equal(t, hostname, se.collectorName)
Expand Down Expand Up @@ -1147,7 +1148,7 @@ func TestRegisterEmptyCollectorNameUnrecoverableError(t *testing.T) {
cfg.BackOff.InitialInterval = time.Millisecond
cfg.BackOff.MaxInterval = time.Millisecond

se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
require.EqualError(t, se.Start(context.Background(), componenttest.NewNopHost()),
"collector registration failed: failed to register the collector, got HTTP status code: 404")
Expand Down Expand Up @@ -1252,7 +1253,7 @@ func TestRegistrationRedirect(t *testing.T) {
require.NoError(t, err)

t.Run("works correctly", func(t *testing.T) {
se, err := newSumologicExtension(configFn(), logger, component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(configFn(), logger, component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
require.NoError(t, se.Start(context.Background(), componenttest.NewNopHost()))
assert.Eventually(t, func() bool { return atomic.LoadInt32(&origReqCount) == 1 },
Expand All @@ -1267,7 +1268,7 @@ func TestRegistrationRedirect(t *testing.T) {
})

t.Run("credentials store retrieves credentials with redirected api url", func(t *testing.T) {
se, err := newSumologicExtension(configFn(), logger, component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(configFn(), logger, component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
require.NoError(t, se.Start(context.Background(), componenttest.NewNopHost()))

Expand Down Expand Up @@ -1364,7 +1365,7 @@ func TestCollectorReregistersAfterHTTPUnathorizedFromHeartbeat(t *testing.T) {
logger, err := zap.NewDevelopment()
require.NoError(t, err)

se, err := newSumologicExtension(cfg, logger, component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, logger, component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
require.NoError(t, se.Start(context.Background(), componenttest.NewNopHost()))

Expand Down Expand Up @@ -1456,7 +1457,7 @@ func TestRegistrationRequestPayload(t *testing.T) {
}
cfg.TimeZone = "PST"

se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)
require.NoError(t, se.Start(context.Background(), componenttest.NewNopHost()))
require.Equal(t, hostname, se.collectorName)
Expand All @@ -1467,7 +1468,7 @@ func TestRegistrationRequestPayload(t *testing.T) {
func TestWatchCredentialKey(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.Credentials.InstallationToken = "dummy_install_token"
se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)

ctx := context.Background()
Expand All @@ -1494,7 +1495,7 @@ func TestWatchCredentialKey(t *testing.T) {
func TestCreateCredentialsHeader(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.Credentials.InstallationToken = "dummy_install_token"
se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)

_, err = se.CreateCredentialsHeader()
Expand Down Expand Up @@ -1562,7 +1563,7 @@ func TestUpdateMetadataRequestPayload(t *testing.T) {
cfg.DiscoverCollectorTags = true
cfg.TimeZone = "PST"

se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID("sumologic"), "1.0.0")
se, err := newSumologicExtension(cfg, zap.NewNop(), component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)

httpClient, err := se.getHTTPClient(se.conf.ClientConfig, api.OpenRegisterResponsePayload{})
Expand Down

0 comments on commit 0b08aaf

Please sign in to comment.