master
1package main
2
3import (
4 "strings"
5 "testing"
6)
7
8// TestBuildingBlueprint tests the blueprint building
9// function
10func TestBuildingBlueprint(t *testing.T) {
11 categories = nil
12 categories = []string{"thing", "thing1", "thing2", "thing3", "thing4"}
13 cats, err := parseBluePrint("2-0-3")
14 if err != nil {
15 t.Errorf("Error for building blueprint: %+v", err)
16 t.FailNow()
17 }
18 if len(cats) != 3 {
19 t.Error("cats is wrong length: %+v", cats)
20 }
21 for _, cat := range []string{"thing2", "thing", "thing3"} {
22 elementFound := false
23 for _, origCat := range cats {
24 if origCat == cat {
25 elementFound = true
26 }
27 }
28 if !elementFound {
29 t.Errorf("category not found: %+v", cat)
30 }
31 }
32}
33
34// TestBuildRecordArray builds the array for giving
35// a test to a client
36func TestBuildRecordArray(t *testing.T) {
37 numQuestions := 23
38 testArray := []string{"linux"}
39 serverConfig.DB_ADDRESS = "localhost"
40 serverConfig.DB_PORT = 27017
41 records, err := buildRecordArray(numQuestions, testArray)
42 if err != nil {
43 t.Errorf("Error building array: %+v", err)
44 t.FailNow()
45 }
46 if len(records) != numQuestions {
47 t.Errorf("Incorrect number of records returned (%d): %+v", len(records), records)
48 t.Fail()
49 }
50 for _, record := range records {
51 if !strings.HasPrefix(record.Path, testArray[0]) {
52 t.Errorf("Improper record selected: %+v", record)
53 }
54 }
55}