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) <noreply@anthropic.com>
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user