diff --git a/pkg/config/autodiscovery/autodiscovery_test.go b/pkg/config/autodiscovery/autodiscovery_test.go index 09a7f28ae1a04..ee096f8d9ed01 100644 --- a/pkg/config/autodiscovery/autodiscovery_test.go +++ b/pkg/config/autodiscovery/autodiscovery_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/assert" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" + snmplistener "github.com/DataDog/datadog-agent/pkg/snmp" ) func TestDiscoverComponentsFromConfigForSnmp(t *testing.T) { @@ -46,3 +47,26 @@ snmp_listener: _, configListeners = DiscoverComponentsFromConfig() assert.Empty(t, len(configListeners)) } + +func TestUnmarshalFromConfigForSnmp(t *testing.T) { + pkgconfigsetup.Datadog().SetConfigType("yaml") + + err := pkgconfigsetup.Datadog().ReadConfig(strings.NewReader(` +network_devices: + autodiscovery: + configs: + - network_address: 127.0.0.1/30 + ignored_ip_addresses: + - 127.0.0.2 +`)) + assert.NoError(t, err) + + configs := []snmplistener.Config{} + err = pkgconfigsetup.Datadog().UnmarshalKey("network_devices.autodiscovery.configs", &configs) + assert.NoError(t, err) + + assert.Len(t, configs, 1) + assert.Equal(t, "127.0.0.1/30", configs[0].Network) + assert.Equal(t, 1, len(configs[0].IgnoredIPAddresses)) + assert.Contains(t, configs[0].IgnoredIPAddresses, "127.0.0.2") +}