Commit 628ecbf
Changed files (1)
question_test.go
@@ -0,0 +1,46 @@
+// question_test tests the functions in
+// question.go
+package main
+
+import (
+ "os"
+ "testing"
+)
+
+// Test_parseLine ensures that lines are parsed into
+// records correctly
+func Test_parseLine(t *testing.T) {
+ testQ := "question here"
+ testA := "answer here"
+ testCat := "cat here"
+ record, err := parseLine(testQ + "," + testA + "," + testCat)
+ if err != nil {
+ t.Errorf("Error while testing line parser: %+v", err)
+ t.FailNow()
+ }
+ if record.Answer == "" {
+ t.Errorf("Record returned nil for line parsing.")
+ t.FailNow()
+ }
+ if record.Question != testQ {
+ t.Errorf("Question for record incorrect. Is: %+v\tshould be: %s", record.Question, testQ)
+ }
+ if record.Answer != testA {
+ t.Errorf("Answer for record incorrect. Is: %+v\tshould be: %s", record.Answer, testA)
+ }
+}
+
+// TestBuildCategoryPath ensures that the correct category is returned
+func TestBuildCategoryPath(t *testing.T) {
+ testFile, err := os.Open("/Users/RLuby/dev/golang/src/richluby/questioner/corpus/linux/networking/test.csv")
+ serverConfig.QUESTIONS = "/Users/RLuby/dev/golang/src/richluby/questioner/corpus"
+ if err != nil {
+ t.Errorf("Error opening test file: %+v", err)
+ t.FailNow()
+ }
+ const expected = "linux:networking:test"
+ catPath := assignCategory(testFile)
+ if catPath != expected {
+ t.Errorf("Unexpected category path: %s\tshould be: %s", catPath, expected)
+ }
+}