dockerfiles/anylink/server/dbdata/db_test.go

36 lines
539 B
Go
Raw Normal View History

2021-06-08 20:45:26 +08:00
package dbdata
import (
"os"
"path"
"testing"
"github.com/bjdgyc/anylink/base"
"github.com/stretchr/testify/assert"
)
func preIpData() {
tmpDb := path.Join(os.TempDir(), "anylink_test.db")
2021-08-02 20:41:35 +08:00
base.Cfg.DbType = "sqlite3"
base.Cfg.DbSource = tmpDb
2021-06-08 20:45:26 +08:00
initDb()
}
func closeIpdata() {
2021-08-02 20:41:35 +08:00
xdb.Close()
2021-06-08 20:45:26 +08:00
tmpDb := path.Join(os.TempDir(), "anylink_test.db")
os.Remove(tmpDb)
}
func TestDb(t *testing.T) {
ast := assert.New(t)
preIpData()
defer closeIpdata()
u := User{Username: "a"}
2021-08-02 20:41:35 +08:00
err := Add(&u)
2021-06-08 20:45:26 +08:00
ast.Nil(err)
ast.Equal(u.Id, 1)
}