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

Code before:
		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())
		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))

Review comment (suggestion):
```suggestion
		require.ErrorContains(t, err, `invalid 'promote_resource_attributes'`)
```

Code after:
		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())
		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))