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

Code before:
		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())
		require.NoError(t, err)

		out, err := yaml.Marshal(want)
		require.NoError(t, err)
		var got Config
		require.NoError(t, yaml.UnmarshalStrict(out, &got))
		require.True(t, got.OTLPConfig.PromoteAllResourceAttributes)
		require.Len(t, got.OTLPConfig.PromoteResourceAttributes, 0)
		require.Len(t, got.OTLPConfig.IgnoreResourceAttributes, 0)
	})

	t.Run("good config - ignore resource attributes", func(t *testing.T) {
		want, err := LoadFile(filepath.Join("testdata", "otlp_sanitize_ignore_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.True(t, got.OTLPConfig.PromoteAllResourceAttributes)
		require.Len(t, got.OTLPConfig.PromoteResourceAttributes, 0)
		require.Equal(t, []string{"k8s.cluster.name", "k8s.job.name", "k8s.namespace.name"}, got.OTLPConfig.IgnoreResourceAttributes)
	})

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

	t.Run("bad config - conflict promote all and promote specific resource attributes", func(t *testing.T) {
		_, err := LoadFile(filepath.Join("testdata", "otlp_promote_all_resource_attributes.bad.yml"), false, promslog.NewNopLogger())
		require.ErrorContains(t, err, `'promote_all_resource_attributes' and 'promote_resource_attributes' cannot be configured simultaneously`)

Review comment (suggestion):
```suggestion
		require.Empty(t, got.OTLPConfig.PromoteResourceAttributes)
		require.Empty(t, got.OTLPConfig.IgnoreResourceAttributes)
```

Code after:
		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())
		require.NoError(t, err)

		out, err := yaml.Marshal(want)
		require.NoError(t, err)
		var got Config
		require.NoError(t, yaml.UnmarshalStrict(out, &got))
		require.True(t, got.OTLPConfig.PromoteAllResourceAttributes)
		require.Empty(t, got.OTLPConfig.PromoteResourceAttributes)
		require.Empty(t, got.OTLPConfig.IgnoreResourceAttributes)
	})

	t.Run("good config - ignore resource attributes", func(t *testing.T) {
		want, err := LoadFile(filepath.Join("testdata", "otlp_sanitize_ignore_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.True(t, got.OTLPConfig.PromoteAllResourceAttributes)
		require.Empty(t, got.OTLPConfig.PromoteResourceAttributes)
		require.Equal(t, []string{"k8s.cluster.name", "k8s.job.name", "k8s.namespace.name"}, got.OTLPConfig.IgnoreResourceAttributes)
	})

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

	t.Run("bad config - conflict between promote all and promote specific resource attributes", func(t *testing.T) {
		_, err := LoadFile(filepath.Join("testdata", "otlp_promote_all_resource_attributes.bad.yml"), false, promslog.NewNopLogger())
		require.ErrorContains(t, err, `'promote_all_resource_attributes' and 'promote_resource_attributes' cannot be configured simultaneously`)