factory_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package googlecloudexporter
  4. import (
  5. "context"
  6. "os"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. "go.opentelemetry.io/collector/component/componenttest"
  10. "go.opentelemetry.io/collector/exporter/exportertest"
  11. )
  12. func TestCreateDefaultConfig(t *testing.T) {
  13. factory := NewFactory()
  14. cfg := factory.CreateDefaultConfig()
  15. assert.NotNil(t, cfg, "failed to create default config")
  16. assert.NoError(t, componenttest.CheckConfigStruct(cfg))
  17. }
  18. func TestCreateExporter(t *testing.T) {
  19. if os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" {
  20. t.Skip("Default credentials not set, skip creating Google Cloud exporter")
  21. }
  22. ctx := context.Background()
  23. factory := NewFactory()
  24. cfg := factory.CreateDefaultConfig()
  25. eCfg := cfg.(*Config)
  26. eCfg.ProjectID = "test"
  27. te, err := factory.CreateTracesExporter(ctx, exportertest.NewNopCreateSettings(), eCfg)
  28. assert.NoError(t, err)
  29. assert.NotNil(t, te, "failed to create trace exporter")
  30. me, err := factory.CreateMetricsExporter(ctx, exportertest.NewNopCreateSettings(), eCfg)
  31. assert.NoError(t, err)
  32. assert.NotNil(t, me, "failed to create metrics exporter")
  33. }
  34. func TestCreateLegacyExporter(t *testing.T) {
  35. if os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" {
  36. t.Skip("Default credentials not set, skip creating Google Cloud exporter")
  37. }
  38. ctx := context.Background()
  39. factory := NewFactory()
  40. cfg := factory.CreateDefaultConfig()
  41. eCfg := cfg.(*Config)
  42. eCfg.ProjectID = "test"
  43. te, err := factory.CreateTracesExporter(ctx, exportertest.NewNopCreateSettings(), eCfg)
  44. assert.NoError(t, err)
  45. assert.NotNil(t, te, "failed to create trace exporter")
  46. me, err := factory.CreateMetricsExporter(ctx, exportertest.NewNopCreateSettings(), eCfg)
  47. assert.NoError(t, err)
  48. assert.NotNil(t, me, "failed to create metrics exporter")
  49. }