Repository: prometheus/prometheus
File: config/config_test.go (Go)

Code before:
	want, err := LoadFile("testdata/remote_write_retry_on_rate_limit.good.yml", false, promslog.NewNopLogger())
	require.NoError(t, err)

	out, err := yaml.Marshal(want)
	require.NoError(t, err)

	got, err := Load(string(out), promslog.NewNopLogger())
	require.NoError(t, err)

	require.True(t, got.RemoteWriteConfigs[0].QueueConfig.RetryOnRateLimit)
	require.False(t, got.RemoteWriteConfigs[1].QueueConfig.RetryOnRateLimit)
}

func TestOTLPSanitizeResourceAttributes(t *testing.T) {
	t.Run("good config - default resource attributes", func(t *testing.T) {
		want, err := LoadFile(filepath.Join("testdata", "otlp_sanitize_default_resource_attributes.good.yml"), false, promslog.NewNopLogger())
		require.NoError(t, err)

		out, err := yaml.Marshal(want)
		require.NoError(t, err)
		var got Config
		require.NoError(t, yaml.UnmarshalStrict(out, &got))

		require.False(t, got.OTLPConfig.PromoteAllResourceAttributes)
		require.Len(t, got.OTLPConfig.IgnoreResourceAttributes, 0)
		require.Len(t, got.OTLPConfig.PromoteResourceAttributes, 0)
	})

	t.Run("good config - promote resource attributes", func(t *testing.T) {
		want, err := LoadFile(filepath.Join("testdata", "otlp_sanitize_promote_resource_attributes.good.yml"), false, promslog.NewNopLogger())
		require.NoError(t, err)

		out, err := yaml.Marshal(want)
		require.NoError(t, err)
		var got Config
		require.NoError(t, yaml.UnmarshalStrict(out, &got))

		require.False(t, got.OTLPConfig.PromoteAllResourceAttributes)
		require.Len(t, got.OTLPConfig.IgnoreResourceAttributes, 0)
		require.Equal(t, []string{"k8s.cluster.name", "k8s.job.name", "k8s.namespace.name"}, got.OTLPConfig.PromoteResourceAttributes)
	})

	t.Run("bad config - promote resource attributes", func(t *testing.T) {
		_, err := LoadFile(filepath.Join("testdata", "otlp_sanitize_promote_resource_attributes.bad.yml"), false, promslog.NewNopLogger())
		require.Contains(t, err.Error(), `invalid 'promote_resource_attributes'`)
		require.ErrorContains(t, err, `duplicated promoted OTel resource attribute "k8s.job.name"`)
		require.ErrorContains(t, err, `empty promoted OTel resource attribute`)
	})

	t.Run("good config - promote all resource attributes", func(t *testing.T) {
		want, err := LoadFile(filepath.Join("testdata", "otlp_sanitize_resource_attributes_promote_all.good.yml"), false, promslog.NewNopLogger())

Review comment (bug):
`require.Len` with zero length will fail the linter, once you sync with main.
```suggestion
		require.Empty(t, got.OTLPConfig.IgnoreResourceAttributes)
		require.Empty(t, got.OTLPConfig.PromoteResourceAttributes)
```

Code after:
	want, err := LoadFile("testdata/remote_write_retry_on_rate_limit.good.yml", false, promslog.NewNopLogger())
	require.NoError(t, err)

	out, err := yaml.Marshal(want)
	require.NoError(t, err)

	got, err := Load(string(out), promslog.NewNopLogger())
	require.NoError(t, err)

	require.True(t, got.RemoteWriteConfigs[0].QueueConfig.RetryOnRateLimit)
	require.False(t, got.RemoteWriteConfigs[1].QueueConfig.RetryOnRateLimit)
}

func TestOTLPSanitizeResourceAttributes(t *testing.T) {
	t.Run("good config - default resource attributes", func(t *testing.T) {
		want, err := LoadFile(filepath.Join("testdata", "otlp_sanitize_default_resource_attributes.good.yml"), false, promslog.NewNopLogger())
		require.NoError(t, err)

		out, err := yaml.Marshal(want)
		require.NoError(t, err)
		var got Config
		require.NoError(t, yaml.UnmarshalStrict(out, &got))

		require.False(t, got.OTLPConfig.PromoteAllResourceAttributes)
		require.Empty(t, got.OTLPConfig.IgnoreResourceAttributes)
		require.Empty(t, got.OTLPConfig.PromoteResourceAttributes)
	})

	t.Run("good config - promote resource attributes", func(t *testing.T) {
		want, err := LoadFile(filepath.Join("testdata", "otlp_sanitize_promote_resource_attributes.good.yml"), false, promslog.NewNopLogger())
		require.NoError(t, err)

		out, err := yaml.Marshal(want)
		require.NoError(t, err)
		var got Config
		require.NoError(t, yaml.UnmarshalStrict(out, &got))

		require.False(t, got.OTLPConfig.PromoteAllResourceAttributes)
		require.Empty(t, got.OTLPConfig.IgnoreResourceAttributes)
		require.Equal(t, []string{"k8s.cluster.name", "k8s.job.name", "k8s.namespace.name"}, got.OTLPConfig.PromoteResourceAttributes)
	})

	t.Run("bad config - promote resource attributes", func(t *testing.T) {
		_, err := LoadFile(filepath.Join("testdata", "otlp_sanitize_promote_resource_attributes.bad.yml"), false, promslog.NewNopLogger())
		require.ErrorContains(t, err, `invalid 'promote_resource_attributes'`)
		require.ErrorContains(t, err, `duplicated promoted OTel resource attribute "k8s.job.name"`)
		require.ErrorContains(t, err, `empty promoted OTel resource attribute`)
	})

	t.Run("good config - promote all resource attributes", func(t *testing.T) {
		want, err := LoadFile(filepath.Join("testdata", "otlp_sanitize_resource_attributes_promote_all.good.yml"), false, promslog.NewNopLogger())