Example #1
0
func TestDaoDeleteById(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

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

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

	sqb.Update(TABLE_NAME)

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

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

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

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

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

	sqb.Select("name, count(*)", TABLE_NAME)
	printQueryAndArgs()
}
Example #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))
}
Example #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()
}
Example #8
0
func TestSQBSet(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

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

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

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

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

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

	fmt.Println(r, e)
}
Example #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()
}
Example #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)
}
Example #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)
		}
	}
}
Example #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)
		}
	}
}
Example #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)
		}
	})
}
Example #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")
	}
}
Example #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)
	}
}
Example #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)
	}
}
Example #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)
			}
		}
	}
}
Example #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)
}
Example #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)
	}
}
Example #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)
		}
	}
}
Example #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)
	}
}
Example #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))
		}
	}
}
Example #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)
		}
	}
}
Example #26
0
func TestSQBLimit(t *testing.T) {
	misc.PrintCallerFuncNameForTest()

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

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

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