Exemple #1
0
func TestLooperCallback(t *testing.T) {
	testData := []int{1, 2, 3, 4, 5}
	err := callback_looper.LooperCallback(testData, 0, nil)
	if err == nil {
		t.Error(fmt.Println("case failed: invalid step"))
	}

	err = callback_looper.LooperCallback(nil, 1, nil)
	if err == nil {
		t.Error(fmt.Println("case failed: data isnt slice"))
	}

	callBackFunc := func(data interface{}) error {
		return fmt.Errorf("callback return error")
	}
	err = callback_looper.LooperCallback(testData, 2, callBackFunc)
	if err == nil {
		t.Error(fmt.Println("case failed: callback return error"))
	}

	callBackFunc = func(data interface{}) error {
		fmt.Println("TestLooperCallback", data)
		return nil
	}
	if err = callback_looper.LooperCallback(testData, 2, callBackFunc); err != nil {
		t.Error(fmt.Println("case failed: looper func"))
	}
	return
}
Exemple #2
0
func LooperCallback(data interface{}, step int, actionFunc callback_looper.Callback) error {
	return callback_looper.LooperCallback(data, step, actionFunc)
}