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

Function TestGaussDBOnConstraint

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

Source from the content-addressed store, hash-verified

184}
185
186func TestGaussDBOnConstraint(t *testing.T) {
187 t.Skipf("This test case skipped, because of gaussdb not support 'ON CONSTRAINT' statement")
188 if DB.Dialector.Name() != "gaussdb" {
189 t.Skip()
190 }
191
192 type Thing struct {
193 gorm.Model
194 SomeID string
195 OtherID string
196 Data string
197 }
198
199 DB.Migrator().DropTable(&Thing{})
200 DB.Migrator().CreateTable(&Thing{})
201 if err := DB.Exec("ALTER TABLE things ADD CONSTRAINT some_id_other_id_unique UNIQUE (some_id, other_id)").Error; err != nil {
202 t.Error(err)
203 }
204
205 thing := Thing{
206 SomeID: "1234",
207 OtherID: "1234",
208 Data: "something",
209 }
210
211 DB.Create(&thing)
212
213 thing2 := Thing{
214 SomeID: "1234",
215 OtherID: "1234",
216 Data: "something else",
217 }
218
219 result := DB.Clauses(clause.OnConflict{
220 OnConstraint: "some_id_other_id_unique",
221 UpdateAll: true,
222 }).Create(&thing2)
223 if result.Error != nil {
224 t.Errorf("creating second thing: %v", result.Error)
225 }
226
227 var things []Thing
228 if err := DB.Find(&things).Error; err != nil {
229 t.Errorf("Failed, got error: %v", err)
230 }
231
232 if len(things) > 1 {
233 t.Errorf("expected 1 thing got more")
234 }
235}
236
237func TestGaussDBAlterColumnDataType(t *testing.T) {
238 if DB.Dialector.Name() != "gaussdb" {

Callers

nothing calls this directly

Calls 9

ClausesMethod · 0.80
NameMethod · 0.65
DropTableMethod · 0.65
MigratorMethod · 0.65
CreateTableMethod · 0.65
ExecMethod · 0.65
ErrorMethod · 0.65
CreateMethod · 0.65
FindMethod · 0.65

Tested by

no test coverage detected