toutiao/article/article_test.go

47 lines
948 B
Go
Raw Normal View History

2018-12-23 14:31:50 +00:00
package main
import (
"io/ioutil"
"testing"
"github.com/tidwall/gjson"
)
func TestTaskEx_Execute(t *testing.T) {
2018-12-27 19:29:34 +00:00
data, err := ioutil.ReadFile("../ssss.json")
2018-12-23 14:31:50 +00:00
if err != nil {
panic(err)
}
2018-12-27 19:29:34 +00:00
var adDataList []string
if gjson.Valid(string(data)) {
P := gjson.Parse(string(data))
data := P.Get(`data`)
if data.Exists() {
adData := data.Get(`ordered_info.#.ad_data`)
if adData.Exists() {
for _, result := range adData.Array() {
adDataList = append(adDataList, result.String())
}
} else {
t.Error(`ordered_info.#.ad_data not exists`)
}
2018-12-23 14:31:50 +00:00
2018-12-27 19:29:34 +00:00
relatedVideo := data.Get(`related_video_toutiao.#[show_tag = "广告"]#`)
if adData.Exists() {
for _, result := range relatedVideo.Array() {
adDataList = append(adDataList, result.String())
}
} else {
t.Error(`related_video_toutiao.#[show_tag = "广告"]# not exists`)
}
}
2018-12-23 14:31:50 +00:00
}
2018-12-27 19:29:34 +00:00
if len(adDataList) != 2 {
t.Error("adDataList != 2")
2018-12-23 14:31:50 +00:00
}
2018-12-27 19:29:34 +00:00
2018-12-23 14:31:50 +00:00
}