22package database
33
44import (
5+ "sync"
56 "testing"
67 "time"
78
89 "github.com/stretchr/testify/assert"
910 "github.com/stretchr/testify/require"
11+ "gorm.io/driver/postgres"
12+ "gorm.io/gorm/schema"
1013)
1114
1215func TestConnect_SQLite (t * testing.T ) {
@@ -37,7 +40,7 @@ func TestConnect_SQLite(t *testing.T) {
3740 t .Run ("InvalidDSN" , func (t * testing.T ) {
3841 invalidConfig := config
3942 invalidConfig .DSN = "/invalid/path/to/db.sqlite"
40-
43+
4144 _ , err := Connect (invalidConfig )
4245 assert .Error (t , err )
4346 })
@@ -54,7 +57,27 @@ func TestConnect_UnsupportedDatabase(t *testing.T) {
5457 assert .Contains (t , err .Error (), "unsupported database type" )
5558}
5659
57- // TestMigrate removed - GORM handles migrations automatically
60+ func TestControlPayload_PostgresPayloadColumnType (t * testing.T ) {
61+ modelSchema , err := schema .Parse (& ControlPayload {}, & sync.Map {}, schema.NamingStrategy {})
62+ require .NoError (t , err )
63+
64+ payloadField := modelSchema .LookUpField ("Payload" )
65+ require .NotNil (t , payloadField )
66+
67+ columnType := postgres.Dialector {}.DataTypeOf (payloadField )
68+ assert .Equal (t , "bytea" , columnType )
69+ }
70+
71+ func TestAnalyticsEvent_PostgresInteractionTypeColumnType (t * testing.T ) {
72+ modelSchema , err := schema .Parse (& AnalyticsEvent {}, & sync.Map {}, schema.NamingStrategy {})
73+ require .NoError (t , err )
74+
75+ interactionTypeField := modelSchema .LookUpField ("InteractionType" )
76+ require .NotNil (t , interactionTypeField )
77+
78+ columnType := postgres.Dialector {}.DataTypeOf (interactionTypeField )
79+ assert .Equal (t , "text" , columnType )
80+ }
5881
5982func TestDatabaseConfig_Validation (t * testing.T ) {
6083 tests := []struct {
@@ -90,7 +113,7 @@ func TestDatabaseConfig_Validation(t *testing.T) {
90113 t .Run (tt .name , func (t * testing.T ) {
91114 // Test connection (may fail due to actual DB not available, but config should be valid)
92115 _ , err := Connect (tt .config )
93-
116+
94117 if tt .hasError {
95118 assert .Error (t , err )
96119 } else {
@@ -124,4 +147,4 @@ func TestGormLogger(t *testing.T) {
124147 // but we can verify the function doesn't panic
125148 })
126149 }
127- }
150+ }
0 commit comments