Socket
Socket
Sign inDemoInstall

github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden


Version published
Created
Source

golden

Status
Stabilityalpha: traces, metrics, logs
IssuesOpen issues Closed issues
Code Owners@djaglowski, @atoulme

The package golden provides utilities for reading and writing files with metrics, traces and logs in YAML format. The package is expected to be used with pkg/pdatatest module.

Generating an expected result file

The easiest way to capture the expected result in a file is golden.WriteMetrics, golden.WriteTraces or golden.WriteLogs.

When writing a new test:

  1. Write the test as if the expected file exists.
  2. Follow the steps below for updating an existing test.

When updating an existing test:

  1. Add a call to golden.WriteMetrics, golden.WriteTraces or golden.WriteLogs or in the appropriate place.
  2. Run the test once.
  3. Remove the call to golden.WriteMetrics, golden.WriteTraces or golden.WriteLogs.

NOTE: golden.WriteMetrics will always mark the test as failed. This behavior is necessary to ensure the function is removed after the golden file is written.

func TestScraper(t *testing.T) {
	cfg := createDefaultConfig().(*Config)
	require.NoError(t, component.ValidateConfig(cfg))

	scraper := newScraper(componenttest.NewNopReceiverCreateSettings(), cfg)

	err := scraper.start(context.Background(), componenttest.NewNopHost())
	require.NoError(t, err)

	actualMetrics, err := scraper.scrape(context.Background())
	require.NoError(t, err)

	expectedFile := filepath.Join("testdata", "scraper", "expected.yaml")

	golden.WriteMetrics(t, expectedFile, actualMetrics) // This line is temporary! TODO remove this!!

	expectedMetrics, err := golden.ReadMetrics(expectedFile)
	require.NoError(t, err)

	require.NoError(t, pmetrictest.CompareMetrics(expectedMetrics, actualMetrics))
}

FAQs

Package last updated on 04 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc