Example #1
0
func before() {
	expectedProbe = models.NewProbe("Is this test ok ?", []string{})
	var err error
	session, err = mgo.Dial("localhost")
	if err != nil {
		panic(err)
	}
	collection = session.DB("test").C("probe")
	collection.RemoveAll(bson.M{})
}
Example #2
0
func TestGetPollsTemplate(testing *testing.T) {
	templatePath = "../static/polls.html"
	probe := models.NewProbe("Is this test ok ?", []string{"Oui", "Non"})
	probe.Save()
	writer := httptest.NewRecorder()

	PollTemplateHandler(writer, nil)

	assert.Contains(testing, writer.Body.String(), "Is this test ok ?")
	assert.Contains(testing, writer.Body.String(), "Oui")
	assert.Contains(testing, writer.Body.String(), "Non")
}
Example #3
0
func TestRespondProbe(testing *testing.T) {
	collection.RemoveAll(bson.M{})
	probe := models.NewProbe("Aimez-vous golang ?", []string{})
	probe.Id = bson.NewObjectId()
	collection.Insert(probe)
	request := createRequest(models.ProbeResponse{probe.Id, "Oui"})

	RespondProbe(nil, request)

	actualProbe := findOneProbeAndRemoveIt()
	assert.Equal(testing, 1, len(actualProbe.Responses))
	assert.Equal(testing, "Oui", actualProbe.Responses[0])
}