forked from go-gorm/playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
38 lines (28 loc) · 798 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"testing"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/driver/sqlite"
)
type TestFile struct {
ProjName string
File string
}
type TestFileList struct {
ProjName string `gorm:"primaryKey"`
Files []TestFile `gorm:"ForeignKey:ProjName"`
}
// GORM_REPO: https://github.com/go-gorm/gorm.git
// GORM_BRANCH: master
// TEST_DRIVERS: sqlite, mysql, postgres, sqlserver
func TestGORM(t *testing.T) {
var files []TestFile
files = append(files,TestFile{"test","test"})
zart := TestFileList {"test",files}
_db,_ := gorm.Open(sqlite.Open("db.sql"), &gorm.Config{PrepareStmt: true})
_db.AutoMigrate(&TestFile{},&TestFileList{})
if err := _db.Clauses(clause.OnConflict{DoNothing: true}).Create(zart).Error ; err != nil {
t.Errorf("Failed, got error: %v", err)
}
}