Skip to content

Commit

Permalink
save test code
Browse files Browse the repository at this point in the history
  • Loading branch information
lazychanger committed Jan 16, 2025
1 parent fabf3ff commit 48484bb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ gorm
go.sum
.*
*.db
vendor
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ require (
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/tools v0.27.0 // indirect
gorm.io/datatypes v1.2.4 // indirect
Expand Down
28 changes: 21 additions & 7 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
package main

import (
"log"
"testing"
)

// GORM_REPO: https://github.com/go-gorm/gorm.git
// GORM_BRANCH: master
// TEST_DRIVERS: sqlite, mysql, postgres, sqlserver
// TEST_DRIVERS: sqlite

func TestGORM(t *testing.T) {
user := User{Name: "jinzhu"}
type Order struct {
tableName string
Id uint64 `gorm:"column:id;type:bigint unsigned;primaryKey;autoIncrement:true" json:"id"`
UserId uint64 `gorm:"column:user_id;type:bigint unsigned;not null;uniqueIndex:unique_user,priority:1" json:"user_id"`
}

DB.Create(&user)
func (o *Order) TableName() string {
return o.tableName
}

var result User
if err := DB.First(&result, user.ID).Error; err != nil {
t.Errorf("Failed, got error: %v", err)
func TestGORM(t *testing.T) {
if err := DB.Table("order-1").AutoMigrate(&Order{}); err != nil {
t.Error(err)
}

if err := DB.Table("order-2").AutoMigrate(&Order{}); err != nil {
t.Error(err)
}
values := []map[string]any{}
DB.Table("sqlite_master").Where("type = ?", "index").Select("type, name, tbl_name").Find(&values)

log.Println(values)
}

0 comments on commit 48484bb

Please # to comment.