Esempio n. 1
0
func TestDaoDeleteById(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	r, e := dao.DeleteById(TABLE_NAME, 1)

	fmt.Println(r, e)
}
Esempio n. 2
0
func TestSQBUpdate(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	sqb.Update(TABLE_NAME)

	printQueryAndArgs()
}
Esempio n. 3
0
func TestSQBInsert(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	sqb.Insert(TABLE_NAME, "id", "add_time", "edit_time", "name")

	printQueryAndArgs()
}
Esempio n. 4
0
func TestSQBHaving(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	sqb.HavingConditionAnd(
		NewColQueryItem("id", COND_GREATER, 3),
	)
	printQueryAndArgs()
}
Esempio n. 5
0
func TestSQBSelect(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	sqb.Select("*", TABLE_NAME)
	printQueryAndArgs()

	sqb.Select("name, count(*)", TABLE_NAME)
	printQueryAndArgs()
}
Esempio n. 6
0
func TestMd5(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	md5 := Md5([]byte("abc"))
	if len(md5) != 32 {
		t.Error(string(md5))
	}

	t.Log(string(md5))
}
Esempio n. 7
0
func TestSQBValues(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	sqb.Values(
		[]interface{}{1, "2016-06-23 09:00:00", "2016-06-23 09:00:00", "a"},
		[]interface{}{2, "2016-06-23 09:10:00", "2016-06-23 09:10:00", "b"},
	)

	printQueryAndArgs()
}
Esempio n. 8
0
func TestSQBSet(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	sqb.Set(
		NewColQueryItem("name", "", "d"),
		NewColQueryItem("edit_time", "", "2016-06-24 09:00:00"),
	)

	printQueryAndArgs()
}
Esempio n. 9
0
func TestDaoSelectById(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	r := dao.SelectById(
		"*",
		TABLE_NAME,
		7,
	)

	fmt.Println(r)
}
Esempio n. 10
0
func TestDaoUpdateById(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	r, e := dao.UpdateById(
		TABLE_NAME,
		7,
		NewColQueryItem("name", "", "e"),
	)

	fmt.Println(r, e)
}
Esempio n. 11
0
func TestSQBWhere(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	sqb.WhereConditionAnd(
		NewColQueryItem("id", COND_IN, 1, 2),
		NewColQueryItem("add_time", COND_BETWEEN, "2016-06-23 00:00:00", "2016-06-25 00:00:00"),
		NewColQueryItem("edit_time", COND_EQUAL, "2016-06-24 09:00:00"),
		NewColQueryItem("name", COND_LIKE, "%a%"),
	)
	printQueryAndArgs()
}
Esempio n. 12
0
func TestDaoInsert(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	r, e := dao.Insert(
		TABLE_NAME,
		[]string{"name"},
		[]interface{}{"a"},
		[]interface{}{"b"},
		[]interface{}{"c"},
	)

	fmt.Println(r, e)
}
Esempio n. 13
0
func TestSetGet(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	for i := 0; i < 10000; i++ {
		key := misc.Md5([]byte(strconv.Itoa(i)))
		smap.Set(key, i)

		v, ok := smap.Get(key)
		if !ok || v != i {
			t.Error(v, ok)
		}
	}
}
Esempio n. 14
0
func TestSetGet(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	for i := 0; i < 10000; i++ {
		key := getIntMd5(i)
		smap.Set(key, i)

		v, ok := smap.Get(key)
		if !ok || v != i {
			t.Error(v, ok)
		}
	}
}
Esempio n. 15
0
func TestWalkDel(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	smap.Walk(func(k string, v interface{}) {
		//t.Log(k, v)

		smap.Del(k)

		_, ok := smap.Get(k)
		if ok {
			t.Error(v, ok)
		}
	})
}
Esempio n. 16
0
func TestBase64EncodeDecode(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	od := []byte("abc")

	cd := Base64Encode(od)
	t.Log(string(cd))

	dd := Base64Decode(cd)
	t.Log(string(dd))

	if string(dd) != string(od) {
		t.Error("coding error")
	}
}
Esempio n. 17
0
func TestDaoQueryRow(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	row := dao.QueryRow("SELECT * FROM test_mysql WHERE id = ?", 5)
	item := new(tableTestMysqlRowItem)
	err := row.Scan(&item.Id, &item.AddTime, &item.EditTime, &item.Name)
	if err != nil {
		if err == sql.ErrNoRows {
			fmt.Println("no rows: " + err.Error())
		} else {
			fmt.Println("row scan error: " + err.Error())
		}
	} else {
		fmt.Println(item)
	}
}
Esempio n. 18
0
func TestPKCS5Padding(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	padding := &PKCS5Padding{
		BlockSize: 16,
	}

	data := []byte("abcd")
	pd := padding.Padding(data)
	t.Log(data, pd)

	upd := padding.UnPadding(pd)
	t.Log(upd)

	if string(data) != string(upd) {
		t.Error(upd)
	}
}
Esempio n. 19
0
func TestDaoQuery(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	rows, err := dao.Query("SELECT * FROM test_mysql WHERE id IN (?,?)", 1, 5)
	if err != nil {
		fmt.Println("query error: " + err.Error())
	} else {
		for rows.Next() {
			item := new(tableTestMysqlRowItem)
			err = rows.Scan(&item.Id, &item.AddTime, &item.EditTime, &item.Name)
			if err != nil {
				fmt.Println("rows scan error: " + err.Error())
			} else {
				fmt.Println(item)
			}
		}
	}
}
Esempio n. 20
0
func TestDaoTrans(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	dao.Begin()

	row := dao.QueryRow("SELECT * FROM test_mysql WHERE id = ?", 1)
	item := new(tableTestMysqlRowItem)
	err := row.Scan(&item.Id, &item.AddTime, &item.EditTime, &item.Name)
	if err != nil {
		fmt.Println("row scan error: " + err.Error())
	} else {
		fmt.Println(item)
	}

	dao.Commit()

	err = dao.Rollback()
	fmt.Println(err)
}
Esempio n. 21
0
func TestParse(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	qv, _ := url.ParseQuery("a=1&b=hello")
	qs := NewQuerySet()

	var a int
	var b string

	qs.IntVar(&a, "a", 101, "invalid a", nil)
	qs.StringVar(&b, "b", 102, "invalid b", nil)

	e := qs.Parse(&qv)
	if e != nil {
		fmt.Println(e.Error())
	} else {
		fmt.Println(a, b)
	}
}
Esempio n. 22
0
func TestDaoSelectByIds(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	rows, err := dao.SelectByIds(
		"*",
		TABLE_NAME,
		[]interface{}{5, 7},
	)

	fmt.Println(err)
	for rows.Next() {
		item := new(tableTestMysqlRowItem)
		err = rows.Scan(&item.Id, &item.AddTime, &item.EditTime, &item.Name)
		if err != nil {
			fmt.Println("rows scan error: " + err.Error())
		} else {
			fmt.Println(item)
		}
	}
}
Esempio n. 23
0
func TestAesCBCCrypter(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	key := Md5([]byte("gobox"))
	iv := Md5([]byte("andals"))[:AES_BLOCK_SIZE]
	data := []byte("abc")

	acc, err := NewAesCBCCrypter(key, iv)
	t.Log(err)
	t.Log(acc.BlockSize())

	crypted := acc.Encrypt(data)
	t.Log(crypted)

	d := acc.Decrypt(crypted)
	t.Log(d)

	if string(d) != string(data) {
		t.Error(d, data)
	}
}
Esempio n. 24
0
func TestDaoExec(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	result, err := dao.Exec("INSERT INTO test_mysql (name) VALUES (?)", "a")
	if err != nil {
		fmt.Println("exec error: " + err.Error())
	} else {
		li, err := result.LastInsertId()
		if err != nil {
			fmt.Println("lastInsertId error: " + err.Error())
		} else {
			fmt.Println("lastInsertId: " + strconv.FormatInt(li, 10))
		}

		rf, err := result.RowsAffected()
		if err != nil {
			fmt.Println("rowsAffected error: " + err.Error())
		} else {
			fmt.Println("rowsAffected: " + strconv.FormatInt(rf, 10))
		}
	}
}
Esempio n. 25
0
func TestSetGet(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	for i := 0; i < 10000; i++ {
		key := misc.Md5([]byte(strconv.Itoa(i)))
		sc.Set(key, i, 10*time.Second)

		v, ok := sc.Get(key)
		if !ok || v != i {
			t.Error(v, ok)
		}
	}

	time.Sleep(16 * time.Second)

	for i := 0; i < 10000; i++ {
		key := misc.Md5([]byte(strconv.Itoa(i)))

		v, ok := sc.Get(key)
		if ok || v == i {
			t.Error(v, ok)
		}
	}
}
Esempio n. 26
0
func TestSQBLimit(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	sqb.Limit(0, 10)
	printQueryAndArgs()
}
Esempio n. 27
0
func TestSQBGroupBy(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	sqb.GroupBy("name ASC")
	printQueryAndArgs()
}
Esempio n. 28
0
func TestSQBOrderBy(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

	sqb.OrderBy("id DESC")
	printQueryAndArgs()
}