master
Raw Download raw file
 1// question_test tests the functions in
 2// question.go
 3package main
 4
 5import (
 6	"os"
 7	"testing"
 8)
 9
10// Test_parseLine ensures that lines are parsed into
11// records correctly
12func TestParseLine(t *testing.T) {
13	testQ := "question here"
14	testA := "answer here"
15	testCat := "cat here"
16	record, err := parseLine(testQ + "," + testA + "," + testCat)
17	if err != nil {
18		t.Errorf("Error while testing line parser: %+v", err)
19		t.FailNow()
20	}
21	if record.Answer == "" {
22		t.Errorf("Record returned nil for line parsing.")
23		t.FailNow()
24	}
25	if record.Question != testQ {
26		t.Errorf("Question for record incorrect. Is: %+v\tshould be: %s", record.Question, testQ)
27	}
28	if record.Answer != testA {
29		t.Errorf("Answer for record incorrect. Is: %+v\tshould be: %s", record.Answer, testA)
30	}
31}
32
33// TestBuildCategoryPath ensures that the correct category is returned
34func TestBuildCategoryPath(t *testing.T) {
35	testFile, err := os.Open("/Users/RLuby/dev/golang/src/richluby/questioner/corpus/linux/networking/test.csv")
36	serverConfig.QUESTIONS = "/Users/RLuby/dev/golang/src/richluby/questioner/corpus"
37	if err != nil {
38		t.Errorf("Error opening test file: %+v", err)
39		t.FailNow()
40	}
41	const expected = "linux:networking:test"
42	catPath := assignCategory(testFile)
43	if catPath != expected {
44		t.Errorf("Unexpected category path: %s\tshould be: %s", catPath, expected)
45	}
46}