Example #1
0
//-----------------------------------------------------------------------------
// Check
//-----------------------------------------------------------------------------
func TestCallerDebug(t *testing.T) {
	tu.SkipLog(t)

	callerDebug(0)
	callerDebug(1)
	callerDebug(2)
}
Example #2
0
//JSON Type without placeholder
func TestSelectInsScanOneJSON(t *testing.T) {
	tu.SkipLog(t)

	db := getMySQL().Db

	//1.Json Data as string
	var memo string
	sql := "SELECT memo2 FROM t_invoices"
	b := db.SelectIns(sql).ScanOne(&memo)
	if db.Err != nil {
		t.Fatalf("[1]db.SelectIns(): %s", db.Err)
	}
	lg.Debugf("memo2 is %s, result is %v", memo, b)

	//convert string to slice
	var converted []int
	json.Unmarshal([]byte(memo), &converted)
	lg.Debugf("converted memo2 is %v", converted)

	//2.Json Data as Array (This is not correct)
	var memo2 []int
	sql = "SELECT memo2 FROM t_invoices"
	b = db.SelectIns(sql).ScanOne(&memo2)
	if db.Err != nil {
		t.Fatalf("[2]db.SelectIns(): %s", db.Err)
	}
	lg.Debugf("memo2 is %s, result is %v", memo2, b)

}
Example #3
0
func TestCurl(t *testing.T) {
	//TODO:work in progress
	tu.SkipLog(t)

	//option := `'http://www.google.co.jp' -H 'Cookie: xxxx=uuuu'`
	option := `'http://www.yahoo.co.jp/'`
	result, err := GetExec("curl", option)
	if err != nil {
		t.Errorf("TestCurl: error: %s", err)
	}
	lg.Debugf("TestCurl xxxx: %v", result)
}
Example #4
0
func TestGetValueAsString(t *testing.T) {
	tu.SkipLog(t)

	lg.Debug(GetValueAsString(dInt))
	lg.Debug(GetValueAsString(dInt64))
	lg.Debug(GetValueAsString(dStr))
	lg.Debug(GetValueAsString(dBool))
	lg.Debug(GetValueAsString(dSlice))
	lg.Debug(GetValueAsString(dTime))
	lg.Debug(GetValueAsString(dMap))
	lg.Debug(GetValueAsString([]time.Duration{dTime}))
	lg.Debug(GetValueAsString(siteInfo))
}
Example #5
0
func TestCheckReflect(t *testing.T) {
	tu.SkipLog(t)

	checkReflect(dInt)     //int/int
	checkReflect(dInt64)   //int64/int64
	checkReflect(dStr)     //v.Kind(): string  Type: string
	checkReflect(dSlice)   //v.Kind(): slice   Type: []int
	checkReflect(dMap)     //v.Kind(): map     Type: map[string]int
	checkReflect(siteInfo) //v.Kind(): struct  Type: reflects_test.SiteInfo
	checkReflect(tInfo)    //v.Kind(): struct  Type: reflects_test.SiteInfo

	var techerInfo []TeacherInfo
	checkReflect(&techerInfo) //v.Kind(): ptr  Type: *[]reflects_test.TeacherInfo
}
Example #6
0
//without placeholder
//TODO:this pattern doesn't work yet
//TODO:SelectInsにパラメータがないと動かん・・・
//panic: reflect.Set: value of type string is not assignable to type int [recovered]
func TestSelectInsScan1(t *testing.T) {
	tu.SkipLog(t)

	db := getMySQL().Db

	var userIDs []int

	sql := "SELECT user_id FROM t_users"
	db.SelectIns(sql).Scan(&userIDs)
	if db.Err != nil {
		t.Errorf("[1]db.SelectIns(sql, 0).Scan(): %s", db.Err)
	}
	lg.Debugf("userIDs is %v", userIDs)
}
Example #7
0
// TestCheckValidationEg is just check of struct type
func TestCheckValidationEg(t *testing.T) {
	tu.SkipLog(t)

	//1:Normal
	data := &LoginRequest{Email: "abc", Pass: "******", Code: "aa", Alpha: "abcde"}
	checkStruct(data)

	//2:Normal and blank field
	data = &LoginRequest{Email: "abc", Pass: "******", Code: "aa", Alpha: ""}
	checkStruct(data)

	//3: there is lack of field
	data = &LoginRequest{Email: "abc", Pass: "******", Code: "aa"}
	checkStruct(data)

}
Example #8
0
//Insert JSON Type
func TestInsertJSON(t *testing.T) {
	tu.SkipLog(t)

	db := getMySQL().Db

	JsonBase := []int{10, 20, 30, 40, 50}
	retByte, _ := json.Marshal(JsonBase)

	// Insert
	sql := "INSERT INTO t_invoices (user_id, memo2) VALUES (1, ?)"
	newID, err := db.Insert(sql, string(retByte))
	if err != nil {
		t.Fatalf("[1]db.Insert(): %s", db.Err)
	}
	lg.Debugf("newID is %d", newID)
}
Example #9
0
//-----------------------------------------------------------------------------
// Check
//-----------------------------------------------------------------------------
func TestInitFlag(t *testing.T) {
	tu.SkipLog(t)

	//SetUsage(usage)
	//flag.Usage = func() {
	//	fmt.Fprint(os.Stderr, fmt.Sprintf(usage, os.Args[0]))
	//}

	//command-line
	//flag.Parse()

	lg.Debugf("flag.NArg():%v", flag.NArg())
	lg.Debugf("flag.Args():%v", flag.Args())

	//show error
	ShowUsageAndExit("something error")
}
Example #10
0
//-----------------------------------------------------------------------------
// Test
//-----------------------------------------------------------------------------
func TestSignal(t *testing.T) {
	tu.SkipLog(t)
	wg := &sync.WaitGroup{}

	go StartSignal()
	fmt.Println("Input Ctrl + c")

	wg.Add(1)
	go func() {
		count := 0
		for {
			fmt.Println(count)
			count++
		}
	}()

	wg.Wait()
}
Example #11
0
//pass struct and without placeholder
//TODO:this pattern doesn't work yet
//TODO:SelectInsにパラメータがないと動かん・・・
//panic: reflect.Set: value of type string is not assignable to type int [recovered]
//panic: reflect.Set: value of type string is not assignable to type int
func TestSelectInsScanOne3(t *testing.T) {
	tu.SkipLog(t)

	type Person struct {
		UserId    int    `db:"id"`
		FirstName string `db:"first_name"`
		LastName  string `db:"last_name"`
		//DateTime  time.Time `db:"create_datetime"`
		DateTime string `db:"create_datetime"`
	}

	db := getMySQL().Db

	//1.Single data
	var person Person
	sql := "SELECT user_id, first_name, last_name, create_datetime FROM t_users"
	db.SelectIns(sql)
	if db.Err != nil {
		t.Fatalf("[1]db.SelectIns(): %s", db.Err)
	}

	for db.ScanOne(&person) {
		//lg.Debugf(person)
		//lg.Debugf("person.UserId: %d", person.UserId)
		//lg.Debugf("person.FirstName: %s", person.FirstName)
		//lg.Debugf("person.LastName: %s", person.LastName)
		//lg.Debugf("person.DateTime: %s", person.DateTime)
	}
	if db.Err != nil {
		t.Fatalf("[1]db.ScanOne(): %s", db.Err)
	}

	//When result is nothing -> nodata
	var person2 Person
	b := db.SelectIns(sql, "1").ScanOne(&person2)
	if db.Err != nil {
		t.Fatalf("[2]db.SelectIns(): %s", db.Err)
	}
	if b {
		t.Error("[2]db.ScanOne(): return bool may be wrong.")
	}
}
Example #12
0
func TestPostRequest(t *testing.T) {
	tu.SkipLog(t)

	url := "https://www.google.co.jp/"

	message := MessagesJson{
		ContentType: 1,
		Text:        "something code",
	}

	byteBody, _ := json.Marshal(message)

	status, _, err := PostRequest(url, byteBody)
	if err != nil {
		t.Fatalf("TestPostRequest1: %s", err)
	}
	if status != 200 {
		t.Errorf("TestPostRequest2: %d", status)
	}
	lg.Debugf("byteBody: %v", byteBody)
}
Example #13
0
func TestDisplay(t *testing.T) {
	tu.SkipLog(t)

	Display("int", dInt)
	//Display int (int):
	//int = 10

	Display("int64", dInt64)
	//Display int64 (int64):
	//int64 = 99999

	Display("string", dStr)
	//Display string (string):
	//string = "testdata"

	Display("bool", dBool)
	//Display bool (bool):
	//bool = false

	Display("slice", dSlice)
	//Display slice ([]int):
	//slice[0] = 1
	//slice[1] = 2
	//slice[2] = 3
	//slice[3] = 4
	//slice[4] = 5

	Display("time", dTime)
	//Display time (time.Duration):
	//time = 1

	Display("map", dMap)
	//Display map (map[string]int):
	//map["apple"] = 150
	//map["banana"] = 300
	//map["lemon"] = 300

	Display("struct", siteInfo)
	//Display struct (reflects_test.SiteInfo):
	//struct.Url = "http://google.com"
	//struct.Teachers[0].Id = 123
	//struct.Teachers[0].Name = "Harry"
	//struct.Teachers[0].Country = "Japan"
	//struct.Teachers[1].Id = 456
	//struct.Teachers[1].Name = "Taro"
	//struct.Teachers[1].Country = "America"

	Display("struct", tInfo)
	//Display struct ([]reflects_test.TeacherInfo):
	//struct[0].Id = 123
	//struct[0].Name = "Harry"
	//struct[0].Country = "Japan"
	//struct[1].Id = 456
	//struct[1].Name = "Taro"
	//struct[1].Country = "America"

	Display("struct", &tInfo)
	//Display struct (*[]reflects_test.TeacherInfo):
	//(*struct)[0].Id = 123
	//(*struct)[0].Name = "Harry"
	//(*struct)[0].Country = "Japan"
	//(*struct)[1].Id = 456
	//(*struct)[1].Name = "Taro"
	//(*struct)[1].Country = "America"
}
Example #14
0
func TestArchEnv(t *testing.T) {
	tu.SkipLog(t)

	lg.Debugf("GOOS: %s", runtime.GOOS)     //[mac]darwin
	lg.Debugf("GOARCH: %s", runtime.GOARCH) //[mac]amd64
}