<commit_before>package server

import (
	"labix.org/v2/mgo"
	. "launchpad.net/gocheck"
	//	"labix.org/v2/mgo/bson"
	//	"image"
	"io"
	"os"
)

// Checker: IsNil, ErrorMatches, Equals, HasLen, FitsTypeof, DeepEquals, NotNil, Not(Checker)
// Bootstrap unit test suite.
type DatabaseTestSuite struct{}

var _ = Suite(&DatabaseTestSuite{})

// SetUpTest creates test datasets to the local mongodb server.
func (s *DatabaseTestSuite) SetUpTest(c *C) {
	Connection, _ = mgo.Dial("localhost")
	gridfs := Connection.DB("unittest").GridFS("fs")

	// create a new file
	gridfsfile, _ := gridfs.Create("image.jpg")

	// set a jpeg image to gridfs
	testJpeg, _ = os.Open("/../testdata/image.jpg")
	defer testJpeg.Close()
	io.Copy(gridfsfile, testJpeg)

	gridfsfile.Close()
}

// TearDownTest removes the created test file.
func (s *DatabaseTestSuite) TearDownTest(c *C) {
	Connection, _ = mgo.Dial("localhost")
	Connection.DB("unittest").DropDatabase()
}

// TestFindImageByParentFilename tests the FindImageByParentFile func
func (s *DatabaseTestSuite) TestFindImageByParentFilename(c *C) {
	Connection, _ = mgo.Dial("localhost")
	gridfs := Connection.DB("unittest").GridFS("fs")

	file, err := FindImageByParentFilename("image.jpg", nil, gridfs)

	c.Assert(file, NotNil)
	c.Assert(err, IsNil)
}<commit_msg>Add negative case for TestFindImageByParentFilename<commit_after>package server

import (
	"labix.org/v2/mgo"
	. "launchpad.net/gocheck"
	//	"labix.org/v2/mgo/bson"
	//	"image"
	"io"
	"os"
)

// Checker: IsNil, ErrorMatches, Equals, HasLen, FitsTypeof, DeepEquals, NotNil, Not(Checker)
// Bootstrap unit test suite.
type DatabaseTestSuite struct{}

var _ = Suite(&DatabaseTestSuite{})

// SetUpTest creates test datasets to the local mongodb server.
func (s *DatabaseTestSuite) SetUpTest(c *C) {
	Connection, _ = mgo.Dial("localhost")
	gridfs := Connection.DB("unittest").GridFS("fs")

	// create a new file
	gridfsfile, _ := gridfs.Create("image.jpg")

	// set a jpeg image to gridfs
	testJpeg, _ = os.Open("/../testdata/image.jpg")
	defer testJpeg.Close()
	io.Copy(gridfsfile, testJpeg)

	gridfsfile.Close()
}

// TearDownTest removes the created test file.
func (s *DatabaseTestSuite) TearDownTest(c *C) {
	Connection, _ = mgo.Dial("localhost")
	Connection.DB("unittest").DropDatabase()
}

// TestFindImageByParentFilename tests the FindImageByParentFile func
func (s *DatabaseTestSuite) TestFindImageByParentFilename(c *C) {
	Connection, _ = mgo.Dial("localhost")
	gridfs := Connection.DB("unittest").GridFS("fs")

	file, err := FindImageByParentFilename("image.jpg", nil, gridfs)

	c.Assert(file, NotNil)
	c.Assert(err, IsNil)

	file, err = FindImageByParentFilename("imagenotexisting.jpg", nil, gridfs)

	c.Assert(file, IsNil)
	c.Assert(err, NotNil)
	c.Assert(err, ErrorMatches, "no image found for imagenotexisting.jpg")
}
{'fraction_non_alphanumeric': 0.14553824362606232, 'fraction_numerical': 0.00141643059490085, 'mean_word_length': 4.947368421052632, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4884629', 'n_tokens_mistral': 1030, 'n_tokens_neox': 1008, 'n_words': 222}