imitater/task_test.go

50 lines
1.4 KiB
Go
Raw Normal View History

2018-12-07 10:21:23 +00:00
package imitater
2018-11-27 09:46:29 +00:00
import (
"log"
"testing"
"474420502.top/eson/curl2info"
)
func TestExecute(t *testing.T) {
curl := `curl 'https://appgrowing.cn/' -H 'authority: appgrowing.cn' -H 'cache-control: max-age=0' -H 'upgrade-insecure-requests: 1' -H 'user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1' -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: zh' -H 'cookie: _ga=GA1.2.1371058419.1533104518; _gid=GA1.2.896241740.1543307916; _gat_gtag_UA_4002880_19=1' -H 'if-none-match: W/"5bf7a0a9-ca6"' -H 'if-modified-since: Fri, 23 Nov 2018 06:39:37 GMT' --compressed`
u, err := curl2info.ParseRawCURL(curl)
if err != nil {
panic(err)
}
2018-12-18 07:33:57 +00:00
_, err = u.CreateWorkflow(nil).Execute()
2018-11-27 09:46:29 +00:00
if err != nil {
t.Error("TestExecute")
}
}
type Toutiao struct {
Task
}
2018-12-07 10:21:23 +00:00
func (tt *Toutiao) Execute(data interface{}) ITask {
2018-12-06 20:47:22 +00:00
resp, err := tt.Request()
2018-12-18 07:33:57 +00:00
if err != nil {
panic(err)
} else {
log.Println(resp.Content()[0:20], err)
}
2018-12-07 10:21:23 +00:00
return nil
}
2018-11-27 09:46:29 +00:00
func TestExecutePlan(t *testing.T) {
2018-12-07 10:21:23 +00:00
Register("toutiao", &Toutiao{})
2018-12-07 11:09:38 +00:00
2018-12-06 20:47:22 +00:00
person := NewPerson()
2018-12-07 11:09:38 +00:00
person.Config("test.yaml")
2018-12-06 20:47:22 +00:00
person.Execute()
2018-11-27 09:46:29 +00:00
2018-12-06 06:44:10 +00:00
// for _, task := range person.Tasks.GetLoopValues() {
// task.GetValue().(*Task).ExecuteOnPlan()
// }
2018-11-27 09:46:29 +00:00
}