mirror of https://github.com/dirtbags/moth.git
Remove some debugging
This commit is contained in:
parent
bde4b2c86d
commit
243fdfd006
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue