Skip to content

Commit f09eed1

Browse files
committed
test: Add CURD test cases for sqlite
1 parent 1a874b1 commit f09eed1

4 files changed

Lines changed: 7 additions & 3 deletions

File tree

tests/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ PgSQL_DB_PORT=5432
1111
PgSQL_DB_DATABASE=carbon
1212
PgSQL_DB_USERNAME=root
1313
PgSQL_DB_PASSWORD=123456
14+
15+
# SQLite config
16+
SQLite_DB_DATABASE=file::memory:

tests/connect.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"gorm.io/driver/postgres"
1010
"gorm.io/driver/sqlite"
1111
"gorm.io/gorm"
12-
"gorm.io/gorm/logger"
1312
)
1413

1514
const (
@@ -37,10 +36,10 @@ func connect(driver string) *gorm.DB {
3736
dsn = fmt.Sprintf("host=%s port=%s user=%s dbname=%s password=%s sslmode=disable TimeZone=Asia/Shanghai", os.Getenv("PgSQL_DB_HOST"), os.Getenv("PgSQL_DB_PORT"), os.Getenv("PgSQL_DB_USERNAME"), os.Getenv("PgSQL_DB_DATABASE"), os.Getenv("PgSQL_DB_PASSWORD"))
3837
dia = postgres.Open(dsn)
3938
case driverSQLite:
40-
dia = sqlite.Open("file::memory:")
39+
dia = sqlite.Open(os.Getenv("SQLite_DB_DATABASE"))
4140
}
4241
db, err := gorm.Open(dia, &gorm.Config{
43-
Logger: logger.Default.LogMode(logger.Info),
42+
//Logger: logger.Default.LogMode(logger.Info),
4443
})
4544
if err != nil {
4645
panic(fmt.Sprintf("failed to connect database, dsn: %q", dsn))

tests/pgsql_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func (s *PgSQLSuite) TestCurd1() {
208208
// read
209209
var model2 PgSQLModel1
210210
db.Last(&model2)
211+
211212
data1, err1 := json.Marshal(&model2)
212213
s.Nil(err1)
213214
s.Equal(`{"carbon1":"2020-08-05 21:14:15","carbon2":"2020-08-05 13:14:15","date1":"2020-08-05","time1":"13:14:15","time2":"13:19:58","date_time1":"2020-08-05 21:14:15","date_time2":"2020-08-05 13:14:15","rfc3339_layout1":"2020-08-05T21:14:15+08:00","rfc3339_layout2":"2020-08-05T13:14:15+08:00","iso8601_format1":"2020-08-05T21:14:15+08:00","iso8601_format2":"2020-08-05T13:14:15+08:00","timestamp1":1596604455}`, string(data1))

tests/sqlite_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ func (s *SQLiteSuite) TestCurd1() {
177177
// read
178178
var model2 SQLiteModel1
179179
db.Last(&model2)
180+
180181
data1, err1 := json.Marshal(&model2)
181182
s.Nil(err1)
182183
s.Equal(`{"carbon":"2020-08-05 13:14:15","date":"2020-08-05","time":"13:14:15","date_time":"2020-08-05 13:14:15","rfc3339_layout":"2020-08-05T13:14:15+08:00","iso8601_format":"2020-08-05T13:14:15+08:00","timestamp":1596604455}`, string(data1))

0 commit comments

Comments
 (0)