diff --git a/cmd/mothd/httpd_test.go b/cmd/mothd/httpd_test.go index 385e188..e5a51a7 100644 --- a/cmd/mothd/httpd_test.go +++ b/cmd/mothd/httpd_test.go @@ -4,11 +4,9 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "log" "net/http/httptest" "net/url" - "strings" "testing" "github.com/spf13/afero" @@ -111,21 +109,6 @@ func TestHttpd(t *testing.T) { if r := hs.TestRequest("/answer", map[string]string{"cat": "pategory", "points": "1", "answer": "answer123"}); r.Result().StatusCode != 200 { t.Error(r.Result()) - } else if strings.Contains(r.Body.String(), "incorrect answer") { - // Pernicious intermittent bug - t.Error("Incorrect answer that was actually correct") - for _, provider := range server.PuzzleProviders { - if mb, ok := provider.(*Mothballs); !ok { - t.Error("Provider is not a mothball") - } else { - cat, _ := mb.getCat("pategory") - f, _ := cat.Open("answers.txt") - defer f.Close() - answersBytes, _ := ioutil.ReadAll(f) - t.Errorf("Correct answers: %v", string(answersBytes)) - } - } - t.Error("Wrong answer") } else if r.Body.String() != `{"status":"success","data":{"short":"accepted","description":"1 points awarded in pategory"}}` { t.Error("Unexpected body", r.Body.String()) } @@ -154,25 +137,6 @@ func TestHttpd(t *testing.T) { if r := hs.TestRequest("/answer", map[string]string{"cat": "pategory", "points": "1", "answer": "answer123"}); r.Result().StatusCode != 200 { t.Error(r.Result()) - } else if strings.Contains(r.Body.String(), "incorrect answer") { - // Pernicious intermittent bug - t.Error("Incorrect answer that was actually correct") - for _, provider := range server.PuzzleProviders { - if mb, ok := provider.(*Mothballs); !ok { - t.Error("Provider is not a mothball") - } else { - if cat, ok := mb.getCat("pategory"); !ok { - t.Error("opening pategory failed") - } else if f, err := cat.Open("answers.txt"); err != nil { - t.Error("opening answers.txt", err) - } else { - defer f.Close() - answersBytes, _ := ioutil.ReadAll(f) - t.Errorf("Correct answers: %#v len %d", string(answersBytes), len(answersBytes)) - } - } - } - t.Error("Wrong answer") } else if r.Body.String() != `{"status":"fail","data":{"short":"not accepted","description":"error awarding points: points already awarded to this team in this category"}}` { t.Error("Unexpected body", r.Body.String()) } diff --git a/cmd/mothd/mothballs.go b/cmd/mothd/mothballs.go index bc1ff72..f204975 100644 --- a/cmd/mothd/mothballs.go +++ b/cmd/mothd/mothballs.go @@ -92,30 +92,23 @@ func (m *Mothballs) Inventory() []Category { func (m *Mothballs) CheckAnswer(cat string, points int, answer string) (bool, error) { zfs, ok := m.getCat(cat) if !ok { - log.Println("There's no such category") return false, fmt.Errorf("no such category: %s", cat) } - log.Println("Opening answers.txt") af, err := zfs.Open("answers.txt") if err != nil { - log.Println("I did not find an answer") return false, fmt.Errorf("no answers.txt file") } defer af.Close() - log.Println("I'm going to start looking for an answer") needle := fmt.Sprintf("%d %s", points, answer) scanner := bufio.NewScanner(af) for scanner.Scan() { - log.Println("testing equality between", scanner.Text(), needle) if scanner.Text() == needle { return true, nil } } - log.Println("I did not find the answer", answer) - return false, nil } diff --git a/cmd/mothd/server_test.go b/cmd/mothd/server_test.go index 4be46c6..caaf61a 100644 --- a/cmd/mothd/server_test.go +++ b/cmd/mothd/server_test.go @@ -36,6 +36,7 @@ func (ts TestServer) refresh() { for _, pp := range ts.PuzzleProviders { pp.(*Mothballs).refresh() } + ts.Theme.(*Theme).refresh() } func TestDevelServer(t *testing.T) {