OpenTelemetry Bot d680729c09 [chore] Prepare release 0.90.0 (#29543) | 1 年之前 | |
---|---|---|
.. | ||
testdata | 1 年之前 | |
Makefile | 1 年之前 | |
README.md | 1 年之前 | |
doc.go | 1 年之前 | |
go.mod | 1 年之前 | |
go.sum | 1 年之前 | |
golden.go | 1 年之前 | |
golden_test.go | 1 年之前 | |
metadata.yaml | 1 年之前 | |
normalize_timestamps.go | 1 年之前 | |
normalize_timestamps_test.go | 1 年之前 | |
sort_metrics.go | 1 年之前 | |
sort_metrics_test.go | 1 年之前 |
Status | |
---|---|
Stability | alpha: traces, metrics, logs |
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.
The easiest way to capture the expected result in a file is golden.WriteMetrics
or golden.WriteLogs
.
When writing a new test:
When updating an existing test:
golden.WriteMetrics
or golden.WriteLogs
or in the appropriate place.golden.WriteMetrics
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))
}