Skip to content

Commit

Permalink
Fix newline in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Feb 25, 2017
1 parent 75a126e commit 0b77efa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestMigrateDatabase(t *testing.T) {
resp := httptest.NewRecorder()
router.ServeHTTP(resp, req)

assert.Equal(t, resp.Body.String(), "{\"message\":\"Successfully migrated testdb to newdb\",\"success\":true}")
assert.Equal(t, strings.TrimSpace(resp.Body.String()), "{\"message\":\"Successfully migrated testdb to newdb\",\"success\":true}")
os.Remove("data/newdb.db")
}

Expand All @@ -54,7 +54,7 @@ func TestDeleteDatabase(t *testing.T) {
resp := httptest.NewRecorder()
router.ServeHTTP(resp, req)

assert.Equal(t, resp.Body.String(), "{\"message\":\"Successfully deleted deleteme\",\"success\":true}")
assert.Equal(t, strings.TrimSpace(resp.Body.String()), "{\"message\":\"Successfully deleted deleteme\",\"success\":true}")
}

func TestCalculate(t *testing.T) {
Expand All @@ -65,7 +65,7 @@ func TestCalculate(t *testing.T) {
resp := httptest.NewRecorder()
router.ServeHTTP(resp, req)

assert.Equal(t, resp.Body.String(), "{\"message\":\"Parameters optimized.\",\"success\":true}")
assert.Equal(t, strings.TrimSpace(resp.Body.String()), "{\"message\":\"Parameters optimized.\",\"success\":true}")
}

func TestUserLocations(t *testing.T) {
Expand All @@ -87,7 +87,7 @@ func TestGetUserLocations(t *testing.T) {
resp := httptest.NewRecorder()
router.ServeHTTP(resp, req)

assert.Equal(t, resp.Body.String(), "{\"message\":\"Error parsing request\",\"success\":false}")
assert.Equal(t, strings.TrimSpace(resp.Body.String()), "{\"message\":\"Error parsing request\",\"success\":false}")
}

func TestGetUserLocations2(t *testing.T) {
Expand All @@ -108,7 +108,7 @@ func TestPutMixinOverrideBad(t *testing.T) {
resp := httptest.NewRecorder()
router.ServeHTTP(resp, req)
response := `{"message":"mixin must be between 0 and 1","success":false}`
assert.Equal(t, resp.Body.String(), response)
assert.Equal(t, strings.TrimSpace(resp.Body.String()), response)
}

func TestPutMixinOverrideGood(t *testing.T) {
Expand All @@ -119,7 +119,7 @@ func TestPutMixinOverrideGood(t *testing.T) {
resp := httptest.NewRecorder()
router.ServeHTTP(resp, req)
response := `{"message":"Overriding mixin for testdb, now set to 0","success":true}`
assert.Equal(t, resp.Body.String(), response)
assert.Equal(t, strings.TrimSpace(resp.Body.String()), response)
}

func TestEditNetworkName(t *testing.T) {
Expand All @@ -130,7 +130,7 @@ func TestEditNetworkName(t *testing.T) {
resp := httptest.NewRecorder()
router.ServeHTTP(resp, req)
response := "{\"message\":\"Finished\",\"success\":true}"
assert.Equal(t, resp.Body.String(), response)
assert.Equal(t, strings.TrimSpace(resp.Body.String()), response)
}

func TestEditName(t *testing.T) {
Expand All @@ -141,7 +141,7 @@ func TestEditName(t *testing.T) {
resp := httptest.NewRecorder()
router.ServeHTTP(resp, req)
response := "{\"message\":\"Changed name of 175 things\",\"success\":true}"
assert.Equal(t, resp.Body.String(), response)
assert.Equal(t, strings.TrimSpace(resp.Body.String()), response)
}

func TestEditUserName(t *testing.T) {
Expand All @@ -152,7 +152,7 @@ func TestEditUserName(t *testing.T) {
resp := httptest.NewRecorder()
router.ServeHTTP(resp, req)
response := "{\"message\":\"Changed name of 344 things\",\"success\":true}"
assert.Equal(t, resp.Body.String(), response)
assert.Equal(t, strings.TrimSpace(resp.Body.String()), response)
}

func TestDeleteUser(t *testing.T) {
Expand All @@ -163,5 +163,5 @@ func TestDeleteUser(t *testing.T) {
resp := httptest.NewRecorder()
router.ServeHTTP(resp, req)
response := "{\"message\":\"Deletes 0 things with user zack2@gmail.com\",\"success\":true}"
assert.Equal(t, resp.Body.String(), response)
assert.Equal(t, strings.TrimSpace(resp.Body.String()), response)
}
8 changes: 4 additions & 4 deletions fingerprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ func TestLearnFingerprintPOST(t *testing.T) {
resp := httptest.NewRecorder()
router.ServeHTTP(resp, req)
response := "{\"message\":\"Inserted fingerprint containing 18 APs for zack (find) at zakhome floor 2 office\",\"success\":true}"
assert.Equal(t, response, resp.Body.String())
assert.Equal(t, response, strings.TrimSpace(resp.Body.String()))
}

func TestLearnFingerprint(t *testing.T) {
jsonTest := `{"username": "zack", "group": "Find", "wifi-fingerprint": [{"rssi": -45, "mac": "80:37:73:ba:f7:d8"}, {"rssi": -58, "mac": "80:37:73:ba:f7:dc"}, {"rssi": -61, "mac": "a0:63:91:2b:9e:65"}, {"rssi": -68, "mac": "a0:63:91:2b:9e:64"}, {"rssi": -70, "mac": "70:73:cb:bd:9f:b5"}, {"rssi": -75, "mac": "d4:05:98:57:b3:10"}, {"rssi": -75, "mac": "00:23:69:d4:47:9f"}, {"rssi": -76, "mac": "30:46:9a:a0:28:c4"}, {"rssi": -81, "mac": "2c:b0:5d:36:e3:b8"}, {"rssi": -82, "mac": "00:1a:1e:46:cd:10"}, {"rssi": -82, "mac": "20:aa:4b:b8:31:c8"}, {"rssi": -83, "mac": "e8:ed:05:55:21:10"}, {"rssi": -83, "mac": "ec:1a:59:4a:9c:ed"}, {"rssi": -88, "mac": "b8:3e:59:78:35:99"}, {"rssi": -84, "mac": "e0:46:9a:6d:02:ea"}, {"rssi": -84, "mac": "00:1a:1e:46:cd:11"}, {"rssi": -84, "mac": "f8:35:dd:0a:da:be"}, {"rssi": -84, "mac": "b4:75:0e:03:cd:69"}], "location": "zakhome floor 2 office", "time": 1439596533831, "password": "frusciante_0128"}`
res := Fingerprint{}
json.Unmarshal([]byte(jsonTest), &res)
message, _ := learnFingerprint(res)
assert.Equal(t, message, "Inserted fingerprint containing 18 APs for zack (find) at zakhome floor 2 office")
assert.Equal(t, strings.TrimSpace(message), "Inserted fingerprint containing 18 APs for zack (find) at zakhome floor 2 office")
}

func TestTrackFingerprintPOST(t *testing.T) {
Expand All @@ -184,15 +184,15 @@ func TestTrackFingerprintPOST(t *testing.T) {
resp := httptest.NewRecorder()
router.ServeHTTP(resp, req)
response := "{\"message\":\"Inserted fingerprint containing 18 APs for zack (find) at zakhome floor 2 office\",\"success\":true}"
assert.Equal(t, response, resp.Body.String())
assert.Equal(t, response, strings.TrimSpace(resp.Body.String()))
}

func TestTrackFingerprintFunction(t *testing.T) {
jsonTest := `{"username": "zack", "group": "Find", "wifi-fingerprint": [{"rssi": -45, "mac": "80:37:73:ba:f7:d8"}, {"rssi": -58, "mac": "80:37:73:ba:f7:dc"}, {"rssi": -61, "mac": "a0:63:91:2b:9e:65"}, {"rssi": -68, "mac": "a0:63:91:2b:9e:64"}, {"rssi": -70, "mac": "70:73:cb:bd:9f:b5"}, {"rssi": -75, "mac": "d4:05:98:57:b3:10"}, {"rssi": -75, "mac": "00:23:69:d4:47:9f"}, {"rssi": -76, "mac": "30:46:9a:a0:28:c4"}, {"rssi": -81, "mac": "2c:b0:5d:36:e3:b8"}, {"rssi": -82, "mac": "00:1a:1e:46:cd:10"}, {"rssi": -82, "mac": "20:aa:4b:b8:31:c8"}, {"rssi": -83, "mac": "e8:ed:05:55:21:10"}, {"rssi": -83, "mac": "ec:1a:59:4a:9c:ed"}, {"rssi": -88, "mac": "b8:3e:59:78:35:99"}, {"rssi": -84, "mac": "e0:46:9a:6d:02:ea"}, {"rssi": -84, "mac": "00:1a:1e:46:cd:11"}, {"rssi": -84, "mac": "f8:35:dd:0a:da:be"}, {"rssi": -84, "mac": "b4:75:0e:03:cd:69"}], "location": "zakhome floor 2 office", "time": 1439596533831, "password": "frusciante_0128"}`
res := Fingerprint{}
json.Unmarshal([]byte(jsonTest), &res)
message, _, _, _, _, _ := trackFingerprint(res)
assert.Equal(t, message, "Current location: zakhome floor 2 office")
assert.Equal(t, strings.TrimSpace(message), "Current location: zakhome floor 2 office")
}

//
Expand Down

0 comments on commit 0b77efa

Please sign in to comment.