Files
zeekayandHanzo Dev c16ed9fe26 Go 1.27.1, and the code it can say more simply
Modules declare go 1.27.1 and the build images follow. go fix applied the
modernizers; omitzero is not applied, since it changes what the JSON says.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-17 02:34:35 -07:00

49 lines
1.0 KiB
Go

package inmemoryreceiver
import (
"testing"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/xconfmap"
)
func TestValidate(t *testing.T) {
tests := []struct {
name string
rawConf *confmap.Conf
errorExpected bool
}{
{
name: "with id",
rawConf: confmap.NewFromStringMap(map[string]any{
"id": "test_receiver",
}),
errorExpected: false,
},
{
name: "empty id",
rawConf: confmap.NewFromStringMap(map[string]any{
"id": "",
}),
errorExpected: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
err := tt.rawConf.Unmarshal(&cfg)
require.NoError(t, err, "could not UnmarshalConfig")
err = xconfmap.Validate(cfg)
if tt.errorExpected {
require.NotNilf(t, err, "Invalid config did not return validation error: %v", cfg)
} else {
require.NoErrorf(t, err, "Valid config returned validation error: %v", cfg)
}
})
}
}