MCPcopy
hub / github.com/go-gorm/gorm / TestPostgresTableWithIdentifierLength

Function TestPostgresTableWithIdentifierLength

tests/table_test.go:179–253  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

177}
178
179func TestPostgresTableWithIdentifierLength(t *testing.T) {
180 if DB.Dialector.Name() != "postgres" {
181 return
182 }
183
184 type LongString struct {
185 ThisIsAVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString string `gorm:"unique"`
186 }
187
188 t.Run("default", func(t *testing.T) {
189 db, _ := gorm.Open(postgres.Open(postgresDSN), &gorm.Config{})
190 user, err := schema.Parse(&LongString{}, &sync.Map{}, db.Config.NamingStrategy)
191 if err != nil {
192 t.Fatalf("failed to parse user unique, got error %v", err)
193 }
194
195 constraints := user.ParseUniqueConstraints()
196 if len(constraints) != 1 {
197 t.Fatalf("failed to find unique constraint, got %v", constraints)
198 }
199
200 for key := range constraints {
201 if len(key) != 63 {
202 t.Errorf("failed to find unique constraint, got %v", constraints)
203 }
204 }
205 })
206
207 t.Run("naming strategy", func(t *testing.T) {
208 db, _ := gorm.Open(postgres.Open(postgresDSN), &gorm.Config{
209 NamingStrategy: schema.NamingStrategy{},
210 })
211
212 user, err := schema.Parse(&LongString{}, &sync.Map{}, db.Config.NamingStrategy)
213 if err != nil {
214 t.Fatalf("failed to parse user unique, got error %v", err)
215 }
216
217 constraints := user.ParseUniqueConstraints()
218 if len(constraints) != 1 {
219 t.Fatalf("failed to find unique constraint, got %v", constraints)
220 }
221
222 for key := range constraints {
223 if len(key) != 63 {
224 t.Errorf("failed to find unique constraint, got %v", constraints)
225 }
226 }
227 })
228
229 t.Run("namer", func(t *testing.T) {
230 uname := "custom_unique_name"
231 db, _ := gorm.Open(postgres.Open(postgresDSN), &gorm.Config{
232 NamingStrategy: mockUniqueNamingStrategy{
233 UName: uname,
234 },
235 })
236

Callers

nothing calls this directly

Calls 4

OpenFunction · 0.92
ParseFunction · 0.92
NameMethod · 0.65

Tested by

no test coverage detected