diff --git a/poller/internal/store/devices_integration_test.go b/poller/internal/store/devices_integration_test.go index 7947838..1340d4c 100644 --- a/poller/internal/store/devices_integration_test.go +++ b/poller/internal/store/devices_integration_test.go @@ -87,6 +87,15 @@ func TestDeviceStore_FetchDevices_Integration(t *testing.T) { assert.Equal(t, "7.16", *d.RouterOSVersion) require.NotNil(t, d.MajorVersion) assert.Equal(t, 7, *d.MajorVersion) + + // New fields: verify COALESCE defaults for existing RouterOS devices. + assert.Equal(t, "routeros", d.DeviceType, "COALESCE should default to routeros") + assert.Equal(t, 161, d.SNMPPort, "COALESCE should default to 161") + assert.Nil(t, d.SNMPVersion, "SNMPVersion should be nil for RouterOS devices") + assert.Nil(t, d.SNMPProfileID, "SNMPProfileID should be nil for RouterOS devices") + assert.Nil(t, d.CredentialProfileID, "CredentialProfileID should be nil when not linked") + assert.Nil(t, d.ProfileEncryptedCredentials, "ProfileEncryptedCredentials should be nil when no profile linked") + assert.Nil(t, d.ProfileEncryptedCredentialsTransit, "ProfileEncryptedCredentialsTransit should be nil when no profile linked") } } } diff --git a/poller/internal/testutil/containers.go b/poller/internal/testutil/containers.go index 6d835d2..4e1b3fb 100644 --- a/poller/internal/testutil/containers.go +++ b/poller/internal/testutil/containers.go @@ -44,6 +44,18 @@ CREATE TABLE IF NOT EXISTS certificate_authorities ( created_at TIMESTAMPTZ DEFAULT now() ); +-- credential_profiles is LEFT JOINed by FetchDevices/GetDevice to resolve +-- profile-level credentials for devices using credential_profile_id. +CREATE TABLE IF NOT EXISTS credential_profiles ( + id UUID DEFAULT gen_random_uuid() PRIMARY KEY, + tenant_id UUID NOT NULL, + name VARCHAR(255) NOT NULL, + encrypted_credentials BYTEA, + encrypted_credentials_transit TEXT, + created_at TIMESTAMPTZ DEFAULT now(), + updated_at TIMESTAMPTZ DEFAULT now() +); + CREATE TABLE IF NOT EXISTS devices ( id UUID DEFAULT gen_random_uuid() PRIMARY KEY, tenant_id UUID NOT NULL, @@ -65,6 +77,11 @@ CREATE TABLE IF NOT EXISTS devices ( ssh_host_key_fingerprint TEXT, ssh_host_key_first_seen TIMESTAMPTZ, ssh_host_key_last_verified TIMESTAMPTZ, + device_type VARCHAR(20) DEFAULT 'routeros', + snmp_port INTEGER DEFAULT 161, + snmp_version VARCHAR(10), + snmp_profile_id UUID, + credential_profile_id UUID REFERENCES credential_profiles(id), status VARCHAR(20) NOT NULL DEFAULT 'unknown', created_at TIMESTAMPTZ DEFAULT now(), updated_at TIMESTAMPTZ DEFAULT now()