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

Function TestGaussDBTableWithIdentifierLength

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

Source from the content-addressed store, hash-verified

253}
254
255func TestGaussDBTableWithIdentifierLength(t *testing.T) {
256 if DB.Dialector.Name() != "gaussdb" {
257 return
258 }
259
260 type LongString struct {
261 ThisIsAVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString string `gorm:"unique"`
262 }
263
264 t.Run("default", func(t *testing.T) {
265 db, _ := gorm.Open(gaussdb.Open(gaussdbDSN), &gorm.Config{})
266 user, err := schema.Parse(&LongString{}, &sync.Map{}, db.Config.NamingStrategy)
267 if err != nil {
268 t.Fatalf("failed to parse user unique, got error %v", err)
269 }
270
271 constraints := user.ParseUniqueConstraints()
272 if len(constraints) != 1 {
273 t.Fatalf("failed to find unique constraint, got %v", constraints)
274 }
275
276 for key := range constraints {
277 if len(key) != 63 {
278 t.Errorf("failed to find unique constraint, got %v", constraints)
279 }
280 }
281 })
282
283 t.Run("naming strategy", func(t *testing.T) {
284 db, _ := gorm.Open(gaussdb.Open(gaussdbDSN), &gorm.Config{
285 NamingStrategy: schema.NamingStrategy{},
286 })
287
288 user, err := schema.Parse(&LongString{}, &sync.Map{}, db.Config.NamingStrategy)
289 if err != nil {
290 t.Fatalf("failed to parse user unique, got error %v", err)
291 }
292
293 constraints := user.ParseUniqueConstraints()
294 if len(constraints) != 1 {
295 t.Fatalf("failed to find unique constraint, got %v", constraints)
296 }
297
298 for key := range constraints {
299 if len(key) != 63 {
300 t.Errorf("failed to find unique constraint, got %v", constraints)
301 }
302 }
303 })
304
305 t.Run("namer", func(t *testing.T) {
306 uname := "custom_unique_name"
307 db, _ := gorm.Open(gaussdb.Open(gaussdbDSN), &gorm.Config{
308 NamingStrategy: mockUniqueNamingStrategy{
309 UName: uname,
310 },
311 })
312

Callers

nothing calls this directly

Calls 4

OpenFunction · 0.92
ParseFunction · 0.92
NameMethod · 0.65

Tested by

no test coverage detected