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

Function TestGaussDB

tests/gaussdb_test.go:66–158  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

64}
65
66func TestGaussDB(t *testing.T) {
67 t.Skipf("This test case skipped, because of gaussdb not support pgcrypto extension and gen_random_uuid() function")
68 if DB.Dialector.Name() != "gaussdb" {
69 t.Skip()
70 }
71
72 type Harumph struct {
73 gorm.Model
74 Name string `gorm:"check:name_checker,name <> ''"`
75 // TODO: function gen_random_uuid() does not exist
76 Test uuid.UUID `gorm:"type:uuid;not null;default:gen_random_uuid()"`
77 CreatedAt time.Time `gorm:"type:TIMESTAMP WITHOUT TIME ZONE"`
78 UpdatedAt time.Time `gorm:"type:TIMESTAMP WITHOUT TIME ZONE;default:current_timestamp"`
79 Things pq.StringArray `gorm:"type:text[]"`
80 }
81
82 if err := DB.Exec("CREATE EXTENSION IF NOT EXISTS pgcrypto;").Error; err != nil {
83 t.Errorf("Failed to create extension pgcrypto, got error %v", err)
84 }
85
86 DB.Migrator().DropTable(&Harumph{})
87
88 if err := DB.AutoMigrate(&Harumph{}); err != nil {
89 t.Fatalf("Failed to migrate for uuid default value, got error: %v", err)
90 }
91
92 harumph := Harumph{}
93 if err := DB.Create(&harumph).Error; err == nil {
94 t.Fatalf("should failed to create data, name can't be blank")
95 }
96
97 harumph = Harumph{Name: "jinzhu"}
98 if err := DB.Create(&harumph).Error; err != nil {
99 t.Fatalf("should be able to create data, but got %v", err)
100 }
101
102 var result Harumph
103 if err := DB.First(&result, "id = ?", harumph.ID).Error; err != nil || harumph.Name != "jinzhu" {
104 t.Errorf("No error should happen, but got %v", err)
105 }
106
107 if err := DB.Where("id = $1", harumph.ID).First(&Harumph{}).Error; err != nil || harumph.Name != "jinzhu" {
108 t.Errorf("No error should happen, but got %v", err)
109 }
110
111 harumph.Name = "jinzhu1"
112 if err := DB.Save(&harumph).Error; err != nil {
113 t.Errorf("Failed to update date, got error %v", err)
114 }
115
116 if err := DB.First(&result, "id = ?", harumph.ID).Error; err != nil || harumph.Name != "jinzhu1" {
117 t.Errorf("No error should happen, but got %v", err)
118 }
119
120 DB.Migrator().DropTable("log_usage")
121
122 if err := DB.Exec(`
123CREATE TABLE public.log_usage (

Callers

nothing calls this directly

Calls 11

SaveMethod · 0.80
NameMethod · 0.65
ExecMethod · 0.65
DropTableMethod · 0.65
MigratorMethod · 0.65
AutoMigrateMethod · 0.65
CreateMethod · 0.65
FirstMethod · 0.65
WhereMethod · 0.65
ColumnTypesMethod · 0.65
AutoIncrementMethod · 0.65

Tested by

no test coverage detected