From d3084abbb9f82b0529b67bfb39d26a2b80535e07 Mon Sep 17 00:00:00 2001 From: Jason Staack Date: Sat, 21 Mar 2026 18:26:53 -0500 Subject: [PATCH] test(16-02): verify new Device fields in integration test - Assert DeviceType defaults to "routeros" via COALESCE - Assert SNMPPort defaults to 161 via COALESCE - Assert SNMPVersion, SNMPProfileID, CredentialProfileID are nil for existing RouterOS devices without profile links - Assert ProfileEncryptedCredentials and ProfileEncryptedCredentialsTransit are nil when no credential profile is linked - Update test schema with device_type, snmp_port, snmp_version, snmp_profile_id, credential_profile_id columns - Add credential_profiles table to test schema for LEFT JOIN Co-Authored-By: Claude Opus 4.6 (1M context) --- .../internal/store/devices_integration_test.go | 9 +++++++++ poller/internal/testutil/containers.go | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) 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()