<commit_before>package db

import (
	"github.com/leptonyu/goeast/wechat"
	"labix.org/v2/mgo"
	"labix.org/v2/mgo/bson"
	"testing"
	"time"
)

type dd struct {
	Name  string
	Value string
}

// Test Basic Query of MongoDB
func TestA(t *testing.T) {
	abc := NewDBConfig("test")
	d, err := abc.Query(func(dbm *mgo.Database) (data interface{}, err error) {
		c := dbm.C("userinfo")
		err = c.Insert(&dd{Name: "Maria", Value: "Hello"})
		if err != nil {
			return
		}
		m := bson.M{"name": "Maria"}
		data = &dd{}
		err = c.Find(m).One(data)
		if err != nil {
			return
		}
		c.RemoveAll(m)
		return
	})
	if err != nil {
		t.Error(err)
	} else {
		t.Log(d)
	}
}

func TestB(t *testing.T) {
	abc := NewDBConfig("test")
	x := &wechat.AccessToken{
		Token:      "this is token",
		ExpireTime: time.Now(),
	}
	err := abc.Write(x)
	if err != nil {
		t.Error(err)
	}
	y, err := abc.Read()
	if err != nil {
		t.Error(err)
	}
	if x.Token != y.Token {
		t.Error("Token is not same!")
	}
}<commit_msg>WeChat Code<commit_after>package db

import (
	"github.com/leptonyu/goeast/wechat"
	"labix.org/v2/mgo"
	"labix.org/v2/mgo/bson"
	"testing"
	"time"
)

type dd struct {
	Name  string
	Value string
}

// Test Basic Query of MongoDB
func TestA(t *testing.T) {
	abc := NewDBConfig("test")
	d, err := abc.Query(func(dbm *mgo.Database) (data interface{}, err error) {
		c := dbm.C("userinfo")
		err = c.Insert(&dd{Name: "Maria", Value: "Hello"})
		if err != nil {
			return
		}
		m := bson.M{"name": "Maria"}
		data = &dd{}
		err = c.Find(m).One(data)
		if err != nil {
			return
		}
		c.RemoveAll(m)
		return
	})
	if err != nil {
		t.Error(err)
	} else {
		t.Log(d)
	}
}

func TestB(t *testing.T) {
	abc := NewDBConfig("test")
	x := &wechat.AccessToken{
		Token:      "<PASSWORD>",
		ExpireTime: time.Now(),
	}
	err := abc.Write(x)
	if err != nil {
		t.Error(err)
	}
	y, err := abc.Read()
	if err != nil {
		t.Error(err)
	}
	if x.Token != y.Token {
		t.Error("Token is not same!")
	}
	t.Log(x)
	t.Log(y)
}
{'fraction_non_alphanumeric': 0.19364599092284418, 'fraction_numerical': 0.002017145738779627, 'mean_word_length': 2.952191235059761, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2311848', 'n_tokens_mistral': 938, 'n_tokens_neox': 889, 'n_words': 193}