mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
use jsondiff in endpoint testing
This commit is contained in:
parent
22e83240e5
commit
eb277fc92e
12 changed files with 112 additions and 76 deletions
|
@ -101,8 +101,8 @@ func DummyPopulateDB(test_db *gorm.DB) {
|
|||
|
||||
// Create two entries of each model
|
||||
|
||||
propertiesA := json.RawMessage(`{"name" : "TestNameA"}`)
|
||||
propertiesB := json.RawMessage(`{"name" : "TestNameB"}`)
|
||||
propertiesA := json.RawMessage(`{"name" : "TestNameA", "category" : "CategoryA", "location" : "anywhere on earth", "type": "dummy"}`)
|
||||
propertiesB := json.RawMessage(`{"name" : "TestNameB", "category" : "CategoryB", "location" : "where ever you want", "type": "generic"}`)
|
||||
simr_A := Simulator{UUID: "4854af30-325f-44a5-ad59-b67b2597de68", Host: "Host_A", State: "running", Modeltype: "ModelTypeA", StateUpdateAt: "placeholder", Properties: postgres.Jsonb{propertiesA}, RawProperties: postgres.Jsonb{propertiesA}}
|
||||
simr_B := Simulator{UUID: "7be0322d-354e-431e-84bd-ae4c9633138b", Host: "Host_B", State: "idle", Modeltype: "ModelTypeB", StateUpdateAt: "placeholder", Properties: postgres.Jsonb{propertiesB}, RawProperties: postgres.Jsonb{propertiesB}}
|
||||
checkErr(test_db.Create(&simr_A).Error)
|
||||
|
|
|
@ -79,23 +79,23 @@ type Signal struct {
|
|||
// Simulator data model
|
||||
type Simulator struct {
|
||||
// ID of the simulator
|
||||
ID uint `gorm:"primary_key;auto_increment"`
|
||||
ID uint `gorm:"primary_key;auto_increment",json:"id"`
|
||||
// UUID of the simulator
|
||||
UUID string `gorm:"not null"`
|
||||
UUID string `gorm:"not null",json:"uuid"`
|
||||
// Host if the simulator
|
||||
Host string `gorm:"default:''"`
|
||||
Host string `gorm:"default:''",json:"host"`
|
||||
// Model type supported by the simulator
|
||||
Modeltype string `gorm:"default:''"`
|
||||
Modeltype string `gorm:"default:''",json:"modelType"`
|
||||
// Uptime of the simulator
|
||||
Uptime int `gorm:"default:0"`
|
||||
Uptime int `gorm:"default:0",json:"uptime"`
|
||||
// State of the simulator
|
||||
State string `gorm:"default:''"`
|
||||
State string `gorm:"default:''",json:"state"`
|
||||
// Time of last state update
|
||||
StateUpdateAt string `gorm:"default:''"`
|
||||
StateUpdateAt string `gorm:"default:''",json:"stateUpdateAt"`
|
||||
// Properties of simulator as JSON string
|
||||
Properties postgres.Jsonb
|
||||
Properties postgres.Jsonb `json:"properties"`
|
||||
// Raw properties of simulator as JSON string
|
||||
RawProperties postgres.Jsonb
|
||||
RawProperties postgres.Jsonb `json:"rawProperties"`
|
||||
// SimulationModels in which the simulator is used
|
||||
SimulationModels []SimulationModel `gorm:"foreignkey:SimulatorID"`
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/nsf/jsondiff"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -35,7 +36,7 @@ func ProvideErrorResponse(c *gin.Context, err error) bool {
|
|||
return false // No error
|
||||
}
|
||||
|
||||
func TestEndpoint(t *testing.T, router *gin.Engine, token string, url string, method string, body []byte, expected_code int, expected_response string) {
|
||||
func TestEndpoint(t *testing.T, router *gin.Engine, token string, url string, method string, body []byte, expected_code int, expected_response []byte) {
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
if body != nil {
|
||||
|
@ -51,7 +52,10 @@ func TestEndpoint(t *testing.T, router *gin.Engine, token string, url string, me
|
|||
|
||||
assert.Equal(t, expected_code, w.Code)
|
||||
fmt.Println(w.Body.String())
|
||||
assert.Equal(t, expected_response, w.Body.String())
|
||||
opts := jsondiff.DefaultConsoleOptions()
|
||||
diff, _ := jsondiff.Compare(w.Body.Bytes(), expected_response, &opts)
|
||||
assert.Equal(t, diff.String(), "FullMatch")
|
||||
|
||||
}
|
||||
|
||||
func AuthenticateForTest(t *testing.T, router *gin.Engine, url string, method string, body []byte, expected_code int) string {
|
||||
|
|
1
go.mod
1
go.mod
|
@ -11,6 +11,7 @@ require (
|
|||
github.com/jinzhu/gorm v1.9.10
|
||||
github.com/leodido/go-urn v1.1.0 // indirect
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e // indirect
|
||||
github.com/nsf/jsondiff v0.0.0-20190712045011-8443391ee9b6
|
||||
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94
|
||||
github.com/stretchr/testify v1.3.0
|
||||
github.com/swaggo/gin-swagger v1.2.0
|
||||
|
|
2
go.sum
2
go.sum
|
@ -130,6 +130,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
|
|||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/nsf/jsondiff v0.0.0-20190712045011-8443391ee9b6 h1:qsqscDgSJy+HqgMTR+3NwjYJBbp1+honwDsszLoS+pA=
|
||||
github.com/nsf/jsondiff v0.0.0-20190712045011-8443391ee9b6/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
|
|
|
@ -141,21 +141,21 @@ func TestEndpoints(t *testing.T) {
|
|||
token = common.AuthenticateForTest(t, router, "/api/authenticate", "POST", credjson, 200)
|
||||
|
||||
// test GET dashboards
|
||||
common.TestEndpoint(t, router, token, "/api/dashboards?scenarioID=1", "GET", nil, 200, string(msgDashboardsjson))
|
||||
common.TestEndpoint(t, router, token, "/api/dashboards?scenarioID=1", "GET", nil, 200, msgDashboardsjson)
|
||||
|
||||
// test POST dashboards
|
||||
common.TestEndpoint(t, router, token, "/api/dashboards", "POST", dabCjson, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/dashboards", "POST", dabCjson, 200, msgOKjson)
|
||||
|
||||
// test GET dashboards/:dashboardID to check if previous POST worked correctly
|
||||
common.TestEndpoint(t, router, token, "/api/dashboards/3", "GET", nil, 200, string(msgDabjson))
|
||||
common.TestEndpoint(t, router, token, "/api/dashboards/3", "GET", nil, 200, msgDabjson)
|
||||
|
||||
// test PUT dashboards/:dashboardID
|
||||
common.TestEndpoint(t, router, token, "/api/dashboards/3", "PUT", dabCupdatedjson, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/dashboards/3", "GET", nil, 200, string(msgDabupdatedjson))
|
||||
common.TestEndpoint(t, router, token, "/api/dashboards/3", "PUT", dabCupdatedjson, 200, msgOKjson)
|
||||
common.TestEndpoint(t, router, token, "/api/dashboards/3", "GET", nil, 200, msgDabupdatedjson)
|
||||
|
||||
// test DELETE dashboards/:dashboardID
|
||||
common.TestEndpoint(t, router, token, "/api/dashboards/3", "DELETE", nil, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/dashboards?scenarioID=1", "GET", nil, 200, string(msgDashboardsjson))
|
||||
common.TestEndpoint(t, router, token, "/api/dashboards/3", "DELETE", nil, 200, msgOKjson)
|
||||
common.TestEndpoint(t, router, token, "/api/dashboards?scenarioID=1", "GET", nil, 200, msgDashboardsjson)
|
||||
|
||||
// TODO add testing for other return codes
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ func TestSignalEndpoints(t *testing.T) {
|
|||
token = common.AuthenticateForTest(t, router, "/api/authenticate", "POST", credjson, 200)
|
||||
|
||||
// test GET files
|
||||
common.TestEndpoint(t, router, token, "/api/files?objectID=1&objectType=widget", "GET", nil, 200, string(msgFilesjson))
|
||||
common.TestEndpoint(t, router, token, "/api/files?objectID=1&objectType=widget", "GET", nil, 200, msgFilesjson)
|
||||
|
||||
// test POST files
|
||||
bodyBuf := &bytes.Buffer{}
|
||||
|
@ -151,7 +151,15 @@ func TestSignalEndpoints(t *testing.T) {
|
|||
assert.Equal(t, string(msgOKjson), w.Body.String())
|
||||
|
||||
// test GET files/:fileID
|
||||
common.TestEndpoint(t, router, token, "/api/files/5", "GET", nil, 200, filecontent)
|
||||
w2 := httptest.NewRecorder()
|
||||
req2, _ := http.NewRequest("GET", "/api/files/5", nil)
|
||||
req2.Header.Add("Authorization", "Bearer "+token)
|
||||
router.ServeHTTP(w2, req2)
|
||||
|
||||
assert.Equal(t, 200, w2.Code)
|
||||
fmt.Println(w2.Body.String())
|
||||
assert.Equal(t, filecontent, w2.Body.String())
|
||||
|
||||
//common.TestEndpoint(t, router, token, "/api/files?objectID=1&objectType=widget", "GET", nil, 200, string(msgFilesjson))
|
||||
|
||||
// test PUT files/:fileID
|
||||
|
@ -195,11 +203,19 @@ func TestSignalEndpoints(t *testing.T) {
|
|||
fmt.Println(w_update.Body.String())
|
||||
assert.Equal(t, string(msgOKjson), w_update.Body.String())
|
||||
|
||||
common.TestEndpoint(t, router, token, "/api/files/5", "GET", nil, 200, filecontent_update)
|
||||
// Test GET on updated file content
|
||||
w3 := httptest.NewRecorder()
|
||||
req3, _ := http.NewRequest("GET", "/api/files/5", nil)
|
||||
req3.Header.Add("Authorization", "Bearer "+token)
|
||||
router.ServeHTTP(w3, req3)
|
||||
|
||||
assert.Equal(t, 200, w3.Code)
|
||||
fmt.Println(w3.Body.String())
|
||||
assert.Equal(t, filecontent_update, w3.Body.String())
|
||||
|
||||
// test DELETE files/:fileID
|
||||
common.TestEndpoint(t, router, token, "/api/files/5", "DELETE", nil, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/files?objectID=1&objectType=widget", "GET", nil, 200, string(msgFilesjson))
|
||||
common.TestEndpoint(t, router, token, "/api/files/5", "DELETE", nil, 200, msgOKjson)
|
||||
common.TestEndpoint(t, router, token, "/api/files?objectID=1&objectType=widget", "GET", nil, 200, msgFilesjson)
|
||||
|
||||
// TODO add testing for other return codes
|
||||
|
||||
|
|
|
@ -2,6 +2,10 @@ package scenario
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/user"
|
||||
|
@ -149,32 +153,41 @@ func TestScenarioEndpoints(t *testing.T) {
|
|||
token = common.AuthenticateForTest(t, router, "/api/authenticate", "POST", credjson, 200)
|
||||
|
||||
// test GET scenarios/
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios", "GET", nil, 200, string(msgScenariosjson))
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios", "GET", nil, 200, msgScenariosjson)
|
||||
|
||||
// test POST scenarios/
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios", "POST", scenarioCjson, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios", "POST", scenarioCjson, 200, msgOKjson)
|
||||
|
||||
// test GET scenarios/:ScenarioID
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/3", "GET", nil, 200, string(msgScenariojson))
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/3", "GET", nil, 200, msgScenariojson)
|
||||
|
||||
// test DELETE scenarios/:ScenarioID
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/3", "DELETE", nil, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios", "GET", nil, 200, string(msgScenariosjson))
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/3", "DELETE", nil, 200, msgOKjson)
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios", "GET", nil, 200, msgScenariosjson)
|
||||
|
||||
// test GET scenarios/:ScenarioID/users
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/1/users", "GET", nil, 200, string(msgUsersjson))
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/1/users", "GET", nil, 200, msgUsersjson)
|
||||
|
||||
// test DELETE scenarios/:ScenarioID/user
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/1/user?username=User_B", "DELETE", nil, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/1/users", "GET", nil, 200, string(msgUserAjson))
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/1/user?username=User_B", "DELETE", nil, 200, msgOKjson)
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/1/users", "GET", nil, 200, msgUserAjson)
|
||||
|
||||
// test PUT scenarios/:ScenarioID/user
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/1/user?username=User_B", "PUT", nil, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/1/users", "GET", nil, 200, string(msgUsersjson))
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/1/user?username=User_B", "PUT", nil, 200, msgOKjson)
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/1/users", "GET", nil, 200, msgUsersjson)
|
||||
|
||||
// test DELETE scenarios/:ScenarioID/user for logged in user User_A
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/1/user?username=User_A", "DELETE", nil, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/1/users", "GET", nil, 422, "\"Access denied (for scenario ID).\"")
|
||||
common.TestEndpoint(t, router, token, "/api/scenarios/1/user?username=User_A", "DELETE", nil, 200, msgOKjson)
|
||||
|
||||
// test if deletion of user from scenario has worked
|
||||
w2 := httptest.NewRecorder()
|
||||
req2, _ := http.NewRequest("GET", "/api/scenarios/1/users", nil)
|
||||
req2.Header.Add("Authorization", "Bearer "+token)
|
||||
router.ServeHTTP(w2, req2)
|
||||
|
||||
assert.Equal(t, 422, w2.Code)
|
||||
fmt.Println(w2.Body.String())
|
||||
assert.Equal(t, "\"Access denied (for scenario ID).\"", w2.Body.String())
|
||||
|
||||
// TODO add tests for other return codes
|
||||
}
|
||||
|
|
|
@ -163,23 +163,23 @@ func TestSignalEndpoints(t *testing.T) {
|
|||
token = common.AuthenticateForTest(t, router, "/api/authenticate", "POST", credjson, 200)
|
||||
|
||||
// test GET signals
|
||||
common.TestEndpoint(t, router, token, "/api/signals?modelID=1&direction=in", "GET", nil, 200, string(msgInSignalsjson))
|
||||
common.TestEndpoint(t, router, token, "/api/signals?modelID=1&direction=out", "GET", nil, 200, string(msgOutSignalsjson))
|
||||
common.TestEndpoint(t, router, token, "/api/signals?modelID=1&direction=in", "GET", nil, 200, msgInSignalsjson)
|
||||
common.TestEndpoint(t, router, token, "/api/signals?modelID=1&direction=out", "GET", nil, 200, msgOutSignalsjson)
|
||||
|
||||
// test POST signals
|
||||
common.TestEndpoint(t, router, token, "/api/signals", "POST", inSignalCjson, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/signals", "POST", inSignalCjson, 200, msgOKjson)
|
||||
|
||||
// test GET signals/:signalID
|
||||
common.TestEndpoint(t, router, token, "/api/signals/5", "GET", nil, 200, string(msgInSignalCjson))
|
||||
common.TestEndpoint(t, router, token, "/api/signals/5", "GET", nil, 200, msgInSignalCjson)
|
||||
|
||||
// test PUT signals/:signalID
|
||||
common.TestEndpoint(t, router, token, "/api/signals/5", "PUT", inSignalCupdatedjson, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/signals/5", "GET", nil, 200, string(msgInSignalCupdatedjson))
|
||||
common.TestEndpoint(t, router, token, "/api/signals/5", "PUT", inSignalCupdatedjson, 200, msgOKjson)
|
||||
common.TestEndpoint(t, router, token, "/api/signals/5", "GET", nil, 200, msgInSignalCupdatedjson)
|
||||
|
||||
// test DELETE signals/:signalID
|
||||
common.TestEndpoint(t, router, token, "/api/signals/5", "DELETE", nil, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/signals?modelID=1&direction=in", "GET", nil, 200, string(msgInSignalsjson))
|
||||
common.TestEndpoint(t, router, token, "/api/signals?modelID=1&direction=out", "GET", nil, 200, string(msgOutSignalsjson))
|
||||
common.TestEndpoint(t, router, token, "/api/signals/5", "DELETE", nil, 200, msgOKjson)
|
||||
common.TestEndpoint(t, router, token, "/api/signals?modelID=1&direction=in", "GET", nil, 200, msgInSignalsjson)
|
||||
common.TestEndpoint(t, router, token, "/api/signals?modelID=1&direction=out", "GET", nil, 200, msgOutSignalsjson)
|
||||
|
||||
// TODO test GET models/:ModelID to check if POST and DELETE adapt InputLength correctly??
|
||||
//common.TestEndpoint(t, router, token, "/api/models/1", "GET", nil, 200, string(msgModelAUpdated2json))
|
||||
|
|
|
@ -163,21 +163,21 @@ func TestSimulationModelEndpoints(t *testing.T) {
|
|||
token = common.AuthenticateForTest(t, router, "/api/authenticate", "POST", credjson, 200)
|
||||
|
||||
// test GET models
|
||||
common.TestEndpoint(t, router, token, "/api/models?scenarioID=1", "GET", nil, 200, string(msgModelsjson))
|
||||
common.TestEndpoint(t, router, token, "/api/models?scenarioID=1", "GET", nil, 200, msgModelsjson)
|
||||
|
||||
// test POST models
|
||||
common.TestEndpoint(t, router, token, "/api/models", "POST", modelCjson, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/models", "POST", modelCjson, 200, msgOKjson)
|
||||
|
||||
// test GET models/:ModelID to check if previous POST worked correctly
|
||||
common.TestEndpoint(t, router, token, "/api/models/3", "GET", nil, 200, string(msgModeljson))
|
||||
common.TestEndpoint(t, router, token, "/api/models/3", "GET", nil, 200, msgModeljson)
|
||||
|
||||
// test PUT models/:ModelID
|
||||
common.TestEndpoint(t, router, token, "/api/models/3", "PUT", modelCupdatedjson, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/models/3", "GET", nil, 200, string(msgModelupdatedjson))
|
||||
common.TestEndpoint(t, router, token, "/api/models/3", "PUT", modelCupdatedjson, 200, msgOKjson)
|
||||
common.TestEndpoint(t, router, token, "/api/models/3", "GET", nil, 200, msgModelupdatedjson)
|
||||
|
||||
// test DELETE models/:ModelID
|
||||
common.TestEndpoint(t, router, token, "/api/models/3", "DELETE", nil, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/models?scenarioID=1", "GET", nil, 200, string(msgModelsjson))
|
||||
common.TestEndpoint(t, router, token, "/api/models/3", "DELETE", nil, 200, msgOKjson)
|
||||
common.TestEndpoint(t, router, token, "/api/models?scenarioID=1", "GET", nil, 200, msgModelsjson)
|
||||
|
||||
// TODO add testing for other return codes
|
||||
|
||||
|
|
|
@ -64,8 +64,8 @@ var simulatorA = common.SimulatorResponse{
|
|||
Uptime: 0,
|
||||
State: "running",
|
||||
StateUpdateAt: "placeholder",
|
||||
Properties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameA"}`)},
|
||||
RawProperties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameA"}`)},
|
||||
Properties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameA", "category" : "CategoryA", "location" : "anywhere on earth", "type": "dummy"}`)},
|
||||
RawProperties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameA", "category" : "CategoryA", "location" : "anywhere on earth", "type": "dummy"}`)},
|
||||
}
|
||||
|
||||
var simulatorB = common.SimulatorResponse{
|
||||
|
@ -76,8 +76,8 @@ var simulatorB = common.SimulatorResponse{
|
|||
Uptime: 0,
|
||||
State: "idle",
|
||||
StateUpdateAt: "placeholder",
|
||||
Properties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameB"}`)},
|
||||
RawProperties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameB"}`)},
|
||||
Properties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameB", "category" : "CategoryB", "location" : "where ever you want", "type": "generic"}`)},
|
||||
RawProperties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameB", "category" : "CategoryB", "location" : "where ever you want", "type": "generic"}`)},
|
||||
}
|
||||
|
||||
var simulatorC = common.Simulator{
|
||||
|
@ -88,8 +88,8 @@ var simulatorC = common.Simulator{
|
|||
Uptime: 0,
|
||||
State: "idle",
|
||||
StateUpdateAt: "placeholder",
|
||||
Properties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameC"}`)},
|
||||
RawProperties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameC"}`)},
|
||||
Properties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameC", "category" : "CategoryC", "location" : "my desk", "type": "blubb"}`)},
|
||||
RawProperties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameC", "category" : "CategoryC", "location" : "my desk", "type": "blubb"}`)},
|
||||
}
|
||||
|
||||
var simulatorCupdated = common.Simulator{
|
||||
|
@ -100,8 +100,8 @@ var simulatorCupdated = common.Simulator{
|
|||
Uptime: 0,
|
||||
State: "running",
|
||||
StateUpdateAt: "placeholder",
|
||||
Properties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameCupdate"}`)},
|
||||
RawProperties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameCupdate"}`)},
|
||||
Properties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameCUpdate", "category" : "CategoryC", "location" : "my desk", "type": "blubb"}`)},
|
||||
RawProperties: postgres.Jsonb{json.RawMessage(`{"name" : "TestNameCUpdate", "category" : "CategoryC", "location" : "my desk", "type": "blubb"}`)},
|
||||
}
|
||||
|
||||
var simulatorC_response = common.SimulatorResponse{
|
||||
|
@ -203,24 +203,24 @@ func TestSimulatorEndpoints(t *testing.T) {
|
|||
token = common.AuthenticateForTest(t, router, "/api/authenticate", "POST", credjson, 200)
|
||||
|
||||
// test GET simulators/
|
||||
common.TestEndpoint(t, router, token, "/api/simulators", "GET", nil, 200, string(msgSimulatorsjson))
|
||||
common.TestEndpoint(t, router, token, "/api/simulators", "GET", nil, 200, msgSimulatorsjson)
|
||||
|
||||
// test POST simulators/
|
||||
common.TestEndpoint(t, router, token, "/api/simulators", "POST", simulatorCjson, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/simulators", "POST", simulatorCjson, 200, msgOKjson)
|
||||
|
||||
// test GET simulators/:SimulatorID
|
||||
common.TestEndpoint(t, router, token, "/api/simulators/3", "GET", nil, 200, string(msgSimulatorjson))
|
||||
common.TestEndpoint(t, router, token, "/api/simulators/3", "GET", nil, 200, msgSimulatorjson)
|
||||
|
||||
// test PUT simulators/:SimulatorID
|
||||
common.TestEndpoint(t, router, token, "/api/simulators/3", "PUT", simulatorCupdatedjson, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/simulators/3", "GET", nil, 200, string(msgSimulatorUpdatedjson))
|
||||
common.TestEndpoint(t, router, token, "/api/simulators/3", "PUT", simulatorCupdatedjson, 200, msgOKjson)
|
||||
common.TestEndpoint(t, router, token, "/api/simulators/3", "GET", nil, 200, msgSimulatorUpdatedjson)
|
||||
|
||||
// test DELETE simulators/:SimulatorID
|
||||
common.TestEndpoint(t, router, token, "/api/simulators/3", "DELETE", nil, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/simulators", "GET", nil, 200, string(msgSimulatorsjson))
|
||||
common.TestEndpoint(t, router, token, "/api/simulators/3", "DELETE", nil, 200, msgOKjson)
|
||||
common.TestEndpoint(t, router, token, "/api/simulators", "GET", nil, 200, msgSimulatorsjson)
|
||||
|
||||
// test GET simulators/:SimulatorID/models
|
||||
common.TestEndpoint(t, router, token, "/api/simulators/1/models", "GET", nil, 200, string(msgModelsjson))
|
||||
common.TestEndpoint(t, router, token, "/api/simulators/1/models", "GET", nil, 200, msgModelsjson)
|
||||
|
||||
// TODO add tests for other return codes
|
||||
}
|
||||
|
|
|
@ -195,21 +195,21 @@ func TestWidgetEndpoints(t *testing.T) {
|
|||
token = common.AuthenticateForTest(t, router, "/api/authenticate", "POST", credjson, 200)
|
||||
|
||||
// test GET widgets
|
||||
common.TestEndpoint(t, router, token, "/api/widgets?dashboardID=1", "GET", nil, 200, string(msgWidgetsjson))
|
||||
common.TestEndpoint(t, router, token, "/api/widgets?dashboardID=1", "GET", nil, 200, msgWidgetsjson)
|
||||
|
||||
// test POST widgets
|
||||
common.TestEndpoint(t, router, token, "/api/widgets", "POST", wdgCjson, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/widgets", "POST", wdgCjson, 200, msgOKjson)
|
||||
|
||||
// test GET widgets/:widgetID to check if previous POST worked correctly
|
||||
common.TestEndpoint(t, router, token, "/api/widgets/3", "GET", nil, 200, string(msgWdgjson))
|
||||
common.TestEndpoint(t, router, token, "/api/widgets/3", "GET", nil, 200, msgWdgjson)
|
||||
|
||||
// test PUT widgets/:widgetID
|
||||
common.TestEndpoint(t, router, token, "/api/widgets/3", "PUT", wdgCupdatedjson, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/widgets/3", "GET", nil, 200, string(msgWdgupdatedjson))
|
||||
common.TestEndpoint(t, router, token, "/api/widgets/3", "PUT", wdgCupdatedjson, 200, msgOKjson)
|
||||
common.TestEndpoint(t, router, token, "/api/widgets/3", "GET", nil, 200, msgWdgupdatedjson)
|
||||
|
||||
// test DELETE widgets/:widgetID
|
||||
common.TestEndpoint(t, router, token, "/api/widgets/3", "DELETE", nil, 200, string(msgOKjson))
|
||||
common.TestEndpoint(t, router, token, "/api/widgets?dashboardID=1", "GET", nil, 200, string(msgWidgetsjson))
|
||||
common.TestEndpoint(t, router, token, "/api/widgets/3", "DELETE", nil, 200, msgOKjson)
|
||||
common.TestEndpoint(t, router, token, "/api/widgets?dashboardID=1", "GET", nil, 200, msgWidgetsjson)
|
||||
|
||||
// TODO add testing for other return codes
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue