diff --git a/common/database.go b/common/database.go index 75efb37..b412623 100644 --- a/common/database.go +++ b/common/database.go @@ -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) diff --git a/common/models.go b/common/models.go index 29aadeb..aa43f09 100644 --- a/common/models.go +++ b/common/models.go @@ -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"` } diff --git a/common/utilities.go b/common/utilities.go index 06a8a79..6cd85a2 100644 --- a/common/utilities.go +++ b/common/utilities.go @@ -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 { diff --git a/go.mod b/go.mod index 3f5b0d6..9300b3e 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index e69c89b..9fb3bea 100644 --- a/go.sum +++ b/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= diff --git a/routes/dashboard/dashboard_test.go b/routes/dashboard/dashboard_test.go index 8162df6..2cc0237 100644 --- a/routes/dashboard/dashboard_test.go +++ b/routes/dashboard/dashboard_test.go @@ -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 diff --git a/routes/file/file_test.go b/routes/file/file_test.go index 7fa7361..f783f91 100644 --- a/routes/file/file_test.go +++ b/routes/file/file_test.go @@ -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 diff --git a/routes/scenario/scenario_test.go b/routes/scenario/scenario_test.go index b591876..98b85eb 100644 --- a/routes/scenario/scenario_test.go +++ b/routes/scenario/scenario_test.go @@ -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 } diff --git a/routes/signal/signal_test.go b/routes/signal/signal_test.go index c728819..aaa5c40 100644 --- a/routes/signal/signal_test.go +++ b/routes/signal/signal_test.go @@ -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)) diff --git a/routes/simulationmodel/simulationmodel_test.go b/routes/simulationmodel/simulationmodel_test.go index 45e5b59..bede18f 100644 --- a/routes/simulationmodel/simulationmodel_test.go +++ b/routes/simulationmodel/simulationmodel_test.go @@ -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 diff --git a/routes/simulator/simulator_test.go b/routes/simulator/simulator_test.go index c0abc0b..8f538ad 100644 --- a/routes/simulator/simulator_test.go +++ b/routes/simulator/simulator_test.go @@ -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 } diff --git a/routes/widget/widget_test.go b/routes/widget/widget_test.go index 0994a3f..14534c3 100644 --- a/routes/widget/widget_test.go +++ b/routes/widget/widget_test.go @@ -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