intimate/extractor/openrec/openrec_test.go

38 lines
706 B
Go
Raw Normal View History

2020-07-10 04:05:33 +00:00
package main
import (
"intimate"
"os"
"testing"
"github.com/tidwall/gjson"
)
func TestExtractor(t *testing.T) {
store := intimate.NewSourceStore("source_openrec")
source, err := store.Pop("openrec_user", 100)
if source != nil {
defer store.Restore(source)
}
if err != nil {
t.Error(err)
}
sdata := source.GetExt().([]byte)
if gjson.ValidBytes(sdata) {
result := gjson.ParseBytes(sdata)
m := result.Map()
for key := range m {
t.Error(key)
f, err := os.OpenFile("./openrec_"+key+".html", os.O_CREATE|os.O_RDWR|os.O_TRUNC, os.ModePerm)
if err != nil {
panic(err)
}
f.WriteString(m[key].String())
}
} else {
t.Error("data is not json:\n", string(sdata))
}
}