add unit test case for types
@@ -10,26 +10,51 @@ import (
"fmt"
"testing"
+ "github.com/gogf/gf/g"
+
"github.com/gogf/gf/g/test/gtest"
)
func Test_Types(t *testing.T) {
+
+ gtest.Case(t, func() {
if _, err := db.Exec(fmt.Sprintf(`
- CREATE TABLE types (
+ CREATE TABLE IF NOT EXISTS types (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
- blob blob NOT NULL,
- binary binary(8) NOT NULL ,
- date varchar(45) NOT NULL ,
- decimal decimal(5,2) NOT NULL ',
- double double NOT NULL ',
- bit bit(2) NOT NULL ',
+ %s blob NOT NULL,
+ %s binary(8) NOT NULL,
+ %s date NOT NULL,
+ %s decimal(5,2) NOT NULL,
+ %s double NOT NULL,
+ %s bit(2) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- `)); err != nil {
+ `, "`blob`", "`binary`", "`date`", "`decimal`", "`double`", "`bit`")); err != nil {
gtest.Error(err)
}
+ defer dropTable("types")
+ data := g.Map{
+ "id": 1,
+ "blob": "i love gf",
+ "binary": []byte("abcdefgh"),
+ "date": "2018-10-24",
+ "decimal": 123.456,
+ "double": 123.456,
+ "bit": 2,
+ }
+ r, err := db.Table("types").Data(data).Insert()
+ gtest.Assert(err, nil)
+ n, _ := r.RowsAffected()
+ gtest.Assert(n, 1)
- gtest.Case(t, func() {
-
+ one, err := db.Table("types").One()
+ gtest.Assert(err, nil)
+ gtest.Assert(one["id"].Int(), 1)
+ gtest.Assert(one["blob"].String(), data["blob"])
+ gtest.Assert(one["binary"].String(), data["binary"])
+ gtest.Assert(one["date"].String(), data["date"])
+ gtest.Assert(one["decimal"].String(), 123.46)
+ gtest.Assert(one["double"].String(), data["double"])
+ gtest.Assert(one["bit"].Int(), data["bit"])
})
}
