DL-1 use dotenv, tagValue passes tests

This commit is contained in:
Patrick McDonagh
2017-10-05 16:20:37 -05:00
parent 877cc2ae6c
commit 3f20496dfa
7 changed files with 58 additions and 39 deletions

View File

@@ -3,7 +3,6 @@ package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"strconv"
"testing"
@@ -45,23 +44,26 @@ func TestGetNonExistentTagValue(t *testing.T) {
func TestCreateTagValue(t *testing.T) {
clearTagValueTable()
seedDataTypeData(a.DB)
seedDeviceTypeData(a.DB)
seedTagClassData(a.DB)
seedDeviceData(a.DB)
addTags(1)
payload := []byte(`{"tagId":1,"val":"1234.56"}`)
payload := []byte(`{"tagId":2,"val":"1234.56"}`)
req, _ := http.NewRequest("POST", "/api/v1/tagValue", bytes.NewBuffer(payload))
response := executeRequest(req)
fmt.Printf("\n\n%s\n\n", response.Body)
checkResponseCode(t, http.StatusCreated, response.Code)
var m map[string]interface{}
json.Unmarshal(response.Body.Bytes(), &m)
if m["tagId"] != 1.0 {
t.Errorf("Expected tagValue name to be '1'. Got '%v'", m["name"])
if m["tagId"] != 2.0 {
t.Errorf("Expected tagValue tagId to be '2'. Got '%v'", m["tagId"])
}
if m["val"] != "1234.56" {
t.Errorf("Expected tagValue address to be '1234.56'. Got '%v'", m["address"])
t.Errorf("Expected tagValue val to be '1234.56'. Got '%v'", m["val"])
}
}
@@ -87,7 +89,7 @@ func addTagValues(count int) {
defer insStmt.Close() // Close the statement when we leave main() / the program terminates
for i := 0; i < count; i++ {
insStmt.Exec(1, strconv.Itoa(i*10), time.Now(), time.Now())
insStmt.Exec(2, strconv.Itoa(i*10), time.Now(), time.Now())
}
}
@@ -100,7 +102,7 @@ func TestUpdateTagValue(t *testing.T) {
var originalTagValue map[string]interface{}
json.Unmarshal(response.Body.Bytes(), &originalTagValue)
payload := []byte(`{"tagId":1,"val":"111.111"}`)
payload := []byte(`{"tagId":2,"val":"111.111"}`)
req, _ = http.NewRequest("PUT", "/api/v1/tagValue/1", bytes.NewBuffer(payload))
response = executeRequest(req)