<commit_before>// Copyright 2013 gandalf authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package db

import (
	"github.com/globocom/config"
	"labix.org/v2/mgo"
	. "launchpad.net/gocheck"
	"testing"
)

func Test(t *testing.T) { TestingT(t) }

type S struct{}

var _ = Suite(&S{})

func (s *S) SetUpSuite(c *C) {
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "gandalf_tests")
	Connect()
}

func (s *S) TearDownSuite(c *C) {
	Session.DB.DropDatabase()
}

func (s *S) TestSessionRepositoryShouldReturnAMongoCollection(c *C) {
	var rep *mgo.Collection
	rep = Session.Repository()
	cRep := Session.DB.C("repository")
	c.Assert(rep, DeepEquals, cRep)
}

func (s *S) TestSessionUserShouldReturnAMongoCollection(c *C) {
	var usr *mgo.Collection
	usr = Session.User()
	cUsr := Session.DB.C("user")
	c.Assert(usr, DeepEquals, cUsr)
}

func (s *S) TestSessionKeyShouldReturnKeyCollection(c *C) {
	key := Session.Key()
	cKey := Session.DB.C("key")
	c.Assert(key, DeepEquals, cKey)
}

func (s *S) TestSessionKeyBodyIsUnique(c *C) {
	key := Session.Key()
	indexes, err := key.Indexes()
	c.Assert(err, IsNil)
	c.Assert(indexes, HasLen, 2)
	c.Assert(indexes[1].Key, DeepEquals, []string{"body"})
	c.Assert(indexes[1].Unique, DeepEquals, true)
}

func (s *S) TestConnect(c *C) {
	Connect()
	c.Assert(Session.DB.Name, Equals, "gandalf_tests")
	err := Session.DB.Session.Ping()
	c.Assert(err, IsNil)
}<commit_msg>db: don't use unqualified imports for gocheck<commit_after>// Copyright 2013 gandalf authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package db

import (
	"github.com/globocom/config"
	"labix.org/v2/mgo"
	"launchpad.net/gocheck"
	"testing"
)

func Test(t *testing.T) { gocheck.TestingT(t) }

type S struct{}

var _ = gocheck.Suite(&S{})

func (s *S) SetUpSuite(c *gocheck.C) {
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "gandalf_tests")
	Connect()
}

func (s *S) TearDownSuite(c *gocheck.C) {
	Session.DB.DropDatabase()
}

func (s *S) TestSessionRepositoryShouldReturnAMongoCollection(c *gocheck.C) {
	var rep *mgo.Collection
	rep = Session.Repository()
	cRep := Session.DB.C("repository")
	c.Assert(rep, gocheck.DeepEquals, cRep)
}

func (s *S) TestSessionUserShouldReturnAMongoCollection(c *gocheck.C) {
	var usr *mgo.Collection
	usr = Session.User()
	cUsr := Session.DB.C("user")
	c.Assert(usr, gocheck.DeepEquals, cUsr)
}

func (s *S) TestSessionKeyShouldReturnKeyCollection(c *gocheck.C) {
	key := Session.Key()
	cKey := Session.DB.C("key")
	c.Assert(key, gocheck.DeepEquals, cKey)
}

func (s *S) TestSessionKeyBodyIsUnique(c *gocheck.C) {
	key := Session.Key()
	indexes, err := key.Indexes()
	c.Assert(err, gocheck.IsNil)
	c.Assert(indexes, gocheck.HasLen, 2)
	c.Assert(indexes[1].Key, gocheck.DeepEquals, []string{"body"})
	c.Assert(indexes[1].Unique, gocheck.DeepEquals, true)
}

func (s *S) TestConnect(c *gocheck.C) {
	Connect()
	c.Assert(Session.DB.Name, gocheck.Equals, "gandalf_tests")
	err := Session.DB.Session.Ping()
	c.Assert(err, gocheck.IsNil)
}
{'fraction_non_alphanumeric': 0.16374452097683156, 'fraction_numerical': 0.011897307451471509, 'mean_word_length': 4.819672131147541, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4176859', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1268, 'n_words': 276}