feat: test for goner/gorm
Some checks are pending
Test and coverage / build (1.21.x) (push) Waiting to run
Test and coverage / build (1.22.x) (push) Waiting to run
Test and coverage / build (1.23.x) (push) Waiting to run

This commit is contained in:
dapeng 2024-11-23 23:08:30 +08:00
parent d31b84c6d4
commit a8b7acc9ce
11 changed files with 138 additions and 11 deletions

View File

@ -19,6 +19,8 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Install SQLite
run: sudo apt-get update && sudo apt-get install -y sqlite3 libsqlite3-dev
- name: Gather dependencies
run: go mod download
- name: Run coverage

View File

@ -12,15 +12,15 @@ type dial struct {
driverName string `gone:"config,gorm.clickhouse.driver-name"`
dsn string `gone:"config,gorm.clickhouse.dsn"`
disableDatetimePrecision bool `gone:"gorm.clickhouse.disable-datetime-precision,default=false"`
dontSupportRenameColumn bool `gone:"gorm.clickhouse.dont-support-rename-column,default=false"`
dontSupportColumnPrecision bool `gone:"gorm.clickhouse.dont-support-column-precision,default=false"`
dontSupportEmptyDefaultValue bool `gone:"gorm.clickhouse.dont-support-empty-default-value,default=false"`
skipInitializeWithVersion bool `gone:"gorm.clickhouse.skip-initialize-with-version,default=false"`
defaultGranularity int `gone:"gorm.clickhouse.default-granularity,default="`
defaultCompression string `gone:"gorm.clickhouse.default-compression,default="`
defaultIndexType string `gone:"gorm.clickhouse.default-indexType,default="`
defaultTableEngineOpts string `gone:"gorm.clickhouse.default-table-engine-opts,default="`
disableDatetimePrecision bool `gone:"config,gorm.clickhouse.disable-datetime-precision,default=false"`
dontSupportRenameColumn bool `gone:"config,gorm.clickhouse.dont-support-rename-column,default=false"`
dontSupportColumnPrecision bool `gone:"config,gorm.clickhouse.dont-support-column-precision,default=false"`
dontSupportEmptyDefaultValue bool `gone:"config,gorm.clickhouse.dont-support-empty-default-value,default=false"`
skipInitializeWithVersion bool `gone:"config,gorm.clickhouse.skip-initialize-with-version,default=false"`
defaultGranularity int `gone:"config,gorm.clickhouse.default-granularity,default="`
defaultCompression string `gone:"config,gorm.clickhouse.default-compression,default="`
defaultIndexType string `gone:"config,gorm.clickhouse.default-indexType,default="`
defaultTableEngineOpts string `gone:"config,gorm.clickhouse.default-table-engine-opts,default="`
}
func (d *dial) Apply(*gorm.Config) error {

View File

@ -0,0 +1,24 @@
package postgres
import (
"github.com/gone-io/gone"
"github.com/gone-io/gone/goner/config"
goneGorm "github.com/gone-io/gone/goner/gorm"
"github.com/stretchr/testify/assert"
"gorm.io/gorm"
"testing"
)
func TestPriest(t *testing.T) {
gone.RunTest(func(in struct {
dial gorm.Dialector `gone:"*"`
}) {
assert.NotNil(t, in.dial)
err := in.dial.(goneGorm.Applier).Apply(nil)
assert.Nil(t, err)
}, func(cemetery gone.Cemetery) error {
_ = config.Priest(cemetery)
return Priest(cemetery)
})
}

View File

@ -0,0 +1,24 @@
package mysql
import (
"github.com/gone-io/gone"
"github.com/gone-io/gone/goner/config"
goneGorm "github.com/gone-io/gone/goner/gorm"
"github.com/stretchr/testify/assert"
"gorm.io/gorm"
"testing"
)
func TestPriest(t *testing.T) {
gone.RunTest(func(in struct {
dial gorm.Dialector `gone:"*"`
}) {
assert.NotNil(t, in.dial)
err := in.dial.(goneGorm.Applier).Apply(nil)
assert.Nil(t, err)
}, func(cemetery gone.Cemetery) error {
_ = config.Priest(cemetery)
return Priest(cemetery)
})
}

View File

@ -0,0 +1,24 @@
package postgres
import (
"github.com/gone-io/gone"
"github.com/gone-io/gone/goner/config"
goneGorm "github.com/gone-io/gone/goner/gorm"
"github.com/stretchr/testify/assert"
"gorm.io/gorm"
"testing"
)
func TestPriest(t *testing.T) {
gone.RunTest(func(in struct {
dial gorm.Dialector `gone:"*"`
}) {
assert.NotNil(t, in.dial)
err := in.dial.(goneGorm.Applier).Apply(nil)
assert.Nil(t, err)
}, func(cemetery gone.Cemetery) error {
_ = config.Priest(cemetery)
return Priest(cemetery)
})
}

View File

@ -7,6 +7,10 @@ import (
"time"
)
type Applier interface {
Apply(*gorm.Config) error
}
func ProviderPriest(cemetery gone.Cemetery) error {
var gInstance *gorm.DB

View File

@ -1,4 +1,4 @@
package mysql
package sqlite
import (
"github.com/gone-io/gone"

View File

@ -0,0 +1,24 @@
package sqlite
import (
"github.com/gone-io/gone"
"github.com/gone-io/gone/goner/config"
goneGorm "github.com/gone-io/gone/goner/gorm"
"github.com/stretchr/testify/assert"
"gorm.io/gorm"
"testing"
)
func TestPriest(t *testing.T) {
gone.RunTest(func(in struct {
dial gorm.Dialector `gone:"*"`
}) {
assert.NotNil(t, in.dial)
err := in.dial.(goneGorm.Applier).Apply(nil)
assert.Nil(t, err)
}, func(cemetery gone.Cemetery) error {
_ = config.Priest(cemetery)
return Priest(cemetery)
})
}

View File

@ -0,0 +1 @@
gorm.sqlite.dsn=./testdata/test.db

View File

@ -1,4 +1,4 @@
package mysql
package sqlserver
import (
"github.com/gone-io/gone"

View File

@ -0,0 +1,24 @@
package sqlserver
import (
"github.com/gone-io/gone"
"github.com/gone-io/gone/goner/config"
goneGorm "github.com/gone-io/gone/goner/gorm"
"github.com/stretchr/testify/assert"
"gorm.io/gorm"
"testing"
)
func TestPriest(t *testing.T) {
gone.RunTest(func(in struct {
dial gorm.Dialector `gone:"*"`
}) {
assert.NotNil(t, in.dial)
err := in.dial.(goneGorm.Applier).Apply(nil)
assert.Nil(t, err)
}, func(cemetery gone.Cemetery) error {
_ = config.Priest(cemetery)
return Priest(cemetery)
})
}