38 lines
706 B
Go
38 lines
706 B
Go
|
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))
|
||
|
}
|
||
|
|
||
|
}
|