github.com/dolanor/pop@v4.13.0+incompatible/dialect_cockroach_test.go (about) 1 package pop 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func Test_Cockroach_URL_Raw(t *testing.T) { 11 r := require.New(t) 12 cd := &ConnectionDetails{ 13 Dialect: "cockroach", 14 URL: "scheme://user:pass@host:1337/database?option1=value1", 15 } 16 err := cd.Finalize() 17 r.NoError(err) 18 m := &cockroach{commonDialect: commonDialect{ConnectionDetails: cd}} 19 r.Equal("scheme://user:pass@host:1337/database?option1=value1", m.URL()) 20 r.Equal("postgres://user:pass@host:1337/?option1=value1", m.urlWithoutDb()) 21 } 22 23 func Test_Cockroach_URL_Build(t *testing.T) { 24 r := require.New(t) 25 26 cd := &ConnectionDetails{ 27 Dialect: "cockroach", 28 Database: "database", 29 Host: "host", 30 Port: "port", 31 User: "user", 32 Password: "pass", 33 Options: map[string]string{ 34 "option1": "value1", 35 }, 36 } 37 err := cd.Finalize() 38 r.NoError(err) 39 m := &cockroach{commonDialect: commonDialect{ConnectionDetails: cd}} 40 r.True(strings.HasPrefix(m.URL(), "postgres://user:pass@host:port/database?"), "URL() returns %v", m.URL()) 41 r.Contains(m.URL(), "option1=value1") 42 r.Contains(m.URL(), "application_name=pop.test") 43 r.True(strings.HasPrefix(m.urlWithoutDb(), "postgres://user:pass@host:port/?"), "urlWithoutDb() returns %v", m.urlWithoutDb()) 44 r.Contains(m.urlWithoutDb(), "option1=value1") 45 r.Contains(m.urlWithoutDb(), "application_name=pop.test") 46 r.True(strings.HasPrefix(m.MigrationURL(), "postgres://user:pass@host:port/database?"), "MigrationURL() returns %v", m.MigrationURL()) 47 } 48 49 func Test_Cockroach_URL_UserDefinedAppName(t *testing.T) { 50 r := require.New(t) 51 52 cd := &ConnectionDetails{ 53 Dialect: "cockroach", 54 Database: "database", 55 Options: map[string]string{ 56 "application_name": "myapp", 57 }, 58 } 59 err := cd.Finalize() 60 r.NoError(err) 61 m := &cockroach{commonDialect: commonDialect{ConnectionDetails: cd}} 62 r.Contains(m.URL(), "database?application_name=myapp") 63 r.Contains(m.urlWithoutDb(), "/?application_name=myapp") 64 } 65 66 func Test_Cockroach_tableQuery(t *testing.T) { 67 r := require.New(t) 68 cr := cockroach{} 69 70 cr.info.version = "v1.0.7" 71 r.Equal(selectTablesQueryCockroachV1, cr.tablesQuery()) 72 73 cr.info.version = "v1.1.9" 74 r.Equal(selectTablesQueryCockroachV1, cr.tablesQuery()) 75 76 cr.info.version = "v2.0.7" 77 r.Equal(selectTablesQueryCockroach, cr.tablesQuery()) 78 79 cr.info.version = "v2.1.7" 80 r.Equal(selectTablesQueryCockroach, cr.tablesQuery()) 81 82 cr.info.version = "v19.1.1" 83 r.Equal(selectTablesQueryCockroach, cr.tablesQuery()) 84 85 cr.info.version = "v20.1.1" 86 r.Equal(selectTablesQueryCockroach, cr.tablesQuery()) 87 }