hunter/pre_url_com_test.go

37 lines
668 B
Go
Raw Normal View History

2020-04-10 08:39:48 +00:00
package hunter
import (
"encoding/json"
"testing"
)
type WebPreUrl struct {
PreGetUrl
}
func (web *WebPreUrl) Execute(cxt *TaskContext) {
resp, err := cxt.Hunt()
if err != nil {
panic(err)
}
cxt.SetShare("test", string(resp.Content()))
2020-04-10 08:39:48 +00:00
}
func TestCasePreUrl(t *testing.T) {
hunter := NewHunter()
hunter.AddTask(&WebPreUrl{PreGetUrl: "http://httpbin.org/get"})
hunter.Execute()
data := make(map[string]interface{})
content := hunter.GetShare("test").(string)
err := json.Unmarshal([]byte(content), &data)
if err != nil {
t.Error(err)
}
if iurl, ok := data["url"]; ok {
if iurl.(string) != "http://httpbin.org/get" {
t.Error(iurl)
}
}
}