Clean up tests a little

This commit is contained in:
Justin Li 2013-12-13 11:48:47 -05:00
parent 140a738162
commit e8e692cbf6
3 changed files with 46 additions and 57 deletions

View file

@ -35,10 +35,7 @@ func mapArrayEqual(boxed map[string][]string, unboxed map[string]string) bool {
}
for mapKey, mapVal := range boxed {
// Always expect box to hold only one element
if len(mapVal) != 1 {
return false
}
if ub_mapVal, eleExists := unboxed[mapKey]; !eleExists || mapVal[0] != ub_mapVal {
if len(mapVal) != 1 || mapVal[0] != unboxed[mapKey] {
return false
}
}
@ -61,10 +58,10 @@ func TestInvalidQueries(t *testing.T) {
for parseIndex, parseStr := range InvalidQueries {
parsedQueryObj, err := parseQuery(parseStr)
if err == nil {
t.Error("Should have produced error ", parseIndex)
t.Error("Should have produced error", parseIndex)
}
if parsedQueryObj != nil {
t.Error("Should be nil after error ", parsedQueryObj, parseIndex)
t.Error("Should be nil after error", parsedQueryObj, parseIndex)
}
}
}

View file

@ -13,8 +13,7 @@ type PeerClientPair struct {
clientId string
}
var (
TestClients = []PeerClientPair{
var TestClients = []PeerClientPair{
{"-AZ3034-6wfG2wk6wWLc", "AZ3034"},
{"-AZ3042-6ozMq5q6Q3NX", "AZ3042"},
{"-BS5820-oy4La2MWGEFj", "BS5820"},
@ -56,8 +55,7 @@ var (
{"-12345", ""},
{"123456", "123456"},
{"-123456", "123456"},
}
)
}
func TestParseClientID(t *testing.T) {
for _, pair := range TestClients {

View file

@ -5,7 +5,6 @@
package server
import (
"errors"
"net/http"
"net/http/httptest"
"testing"
@ -16,12 +15,7 @@ import (
)
func newTestServer() (*Server, error) {
s, err := New(&config.MockConfig)
if err != nil {
return nil, err
}
return s, nil
return New(&config.MockConfig)
}
func TestStats(t *testing.T) {
@ -39,10 +33,10 @@ func TestStats(t *testing.T) {
s.serveStats(w, r)
if w.Code != 200 {
t.Error(errors.New("/stats did not return HTTP 200"))
t.Error("/stats did not return 200 OK")
}
if w.Header()["Content-Type"][0] != "application/json" {
t.Error(errors.New("/stats did not return the proper Content-Type header"))
t.Error("/stats did not return JSON")
}
}