Example #1
0
func TestGoDoc(t *testing.T) {
	Convey("Given a search query text", t, func() {
		url := ""
		setURL := func(u string) {
			url = u
		}

		Convey("When the result is empty", func() {
			s, err := searchGodoc("non existant package", web.GetJSONFromString(emptyResults, setURL))

			So(err, ShouldBeNil)
			So(s, ShouldEqual, noPackagesFound)
			So(url, ShouldEqual, fmt.Sprintf(godocSearchURL, "non existant package"))
		})

		Convey("When the result is ok", func() {
			s, err := searchGodoc("go-bot", web.GetJSONFromString(results, setURL))

			So(err, ShouldBeNil)
			So(s, ShouldEqual, "github.com/fabioxgn/go-bot IRC bot written in go")
			So(url, ShouldEqual, fmt.Sprintf(godocSearchURL, "go-bot"))
		})

		Convey("When the query is empty", func() {
			url = ""
			s, err := searchGodoc("", web.GetJSONFromString(results, setURL))

			So(err, ShouldBeNil)
			So(s, ShouldEqual, "")
			So(url, ShouldEqual, "")
		})
	})

}
func TestCatFacts(t *testing.T) {
	url := ""
	setURL := func(u string) {
		url = u
	}
	Convey("Given a text", t, func() {
		Convey("When the text does not have cat", func() {

			s, err := getFacts("My name is Catarina.", nil)

			So(err, ShouldBeNil)
			So(s, ShouldEqual, "")
		})

		Convey("When the api returns 0 results", func() {
			s, err := getFacts("I love Catz!", web.GetJSONFromString(emptyResult, setURL))

			So(err, ShouldBeNil)
			So(s, ShouldEqual, "")
		})

		Convey("When the text has cat in the end of the sentence", func() {

			s, err := getFacts("I love Catz!", web.GetJSONFromString(result, setURL))

			So(err, ShouldBeNil)
			So(s, ShouldEqual, fmt.Sprintf(msgPrefix, "Catz FTW!"))
			So(url, ShouldEqual, catFactsURL)
		})

		Convey("When the text does not end with the world or puntuation", func() {

			s, err := getFacts("My name is Catzarina", web.GetJSONFromString(result, setURL))

			So(err, ShouldBeNil)
			So(s, ShouldEqual, "")
		})

		Convey("When the text has cat in the middle of a word", func() {

			s, err := getFacts("My name is aCats", web.GetJSONFromString(result, setURL))

			So(err, ShouldBeNil)
			So(s, ShouldEqual, "")
		})

		Convey("when the text have gato in the middle of the sentence", func() {

			s, err := getFacts("Eu tenho 2 gatos gordos.", web.GetJSONFromString(result, setURL))

			So(err, ShouldBeNil)
			So(s, ShouldEqual, fmt.Sprintf(msgPrefix, "Catz FTW!"))
			So(url, ShouldEqual, catFactsURL)
		})

	})
}