mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
replace some fmt. calls with log. calls #17
This commit is contained in:
parent
de4ac7b9b5
commit
9f56b66213
5 changed files with 10 additions and 13 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||||
"github.com/streadway/amqp"
|
"github.com/streadway/amqp"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -102,7 +103,7 @@ func ConnectAMQP(uri string) error {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
err = db.Where("UUID = ?", gjson.Get(content, "properties.uuid")).Find(sToBeUpdated).Error
|
err = db.Where("UUID = ?", gjson.Get(content, "properties.uuid")).Find(sToBeUpdated).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("AMQP: Unable to find simulator with UUID: ", gjson.Get(content, "properties.uuid"), " DB error message: ", err)
|
log.Println("AMQP: Unable to find simulator with UUID: ", gjson.Get(content, "properties.uuid"), " DB error message: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.Model(&sToBeUpdated).Updates(map[string]interface{}{
|
err = db.Model(&sToBeUpdated).Updates(map[string]interface{}{
|
||||||
|
@ -114,10 +115,10 @@ func ConnectAMQP(uri string) error {
|
||||||
"RawProperties": gjson.Get(content, "properties"),
|
"RawProperties": gjson.Get(content, "properties"),
|
||||||
}).Error
|
}).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("AMQP: Unable to update simulator in DB: ", err)
|
log.Println("AMQP: Unable to update simulator in DB: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("AMQP: Updated simulator with UUID ", gjson.Get(content, "properties.uuid"))
|
log.Println("AMQP: Updated simulator with UUID ", gjson.Get(content, "properties.uuid"))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -155,7 +156,7 @@ func SendActionAMQP(action Action, uuid string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func PingAMQP() error {
|
func PingAMQP() error {
|
||||||
fmt.Println("AMQP: sending ping command to all simulators")
|
log.Println("AMQP: sending ping command to all simulators")
|
||||||
|
|
||||||
var a Action
|
var a Action
|
||||||
a.Act = "ping"
|
a.Act = "ping"
|
||||||
|
|
|
@ -3,6 +3,7 @@ package database
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -26,8 +27,7 @@ func TestMain(m *testing.M) {
|
||||||
// Verify that you can connect to the database
|
// Verify that you can connect to the database
|
||||||
err = db.DB().Ping()
|
err = db.DB().Ping()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error: DB must ping to run tests")
|
log.Panic("Error: DB must ping to run tests")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
|
@ -170,7 +170,7 @@ func CompareResponse(resp *bytes.Buffer, expected interface{}) error {
|
||||||
opts := jsondiff.DefaultConsoleOptions()
|
opts := jsondiff.DefaultConsoleOptions()
|
||||||
diff, text := jsondiff.Compare(resp.Bytes(), expectedBytes, &opts)
|
diff, text := jsondiff.Compare(resp.Bytes(), expectedBytes, &opts)
|
||||||
if diff.String() != "FullMatch" && diff.String() != "SupersetMatch" {
|
if diff.String() != "FullMatch" && diff.String() != "SupersetMatch" {
|
||||||
fmt.Println(text)
|
log.Println(text)
|
||||||
return fmt.Errorf("Response: Expected \"%v\". Got \"%v\".",
|
return fmt.Errorf("Response: Expected \"%v\". Got \"%v\".",
|
||||||
"(FullMatch OR SupersetMatch)", diff.String())
|
"(FullMatch OR SupersetMatch)", diff.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
"github.com/jinzhu/gorm/dialects/postgres"
|
"github.com/jinzhu/gorm/dialects/postgres"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -41,7 +42,7 @@ func addScenario(token string) (scenarioID uint) {
|
||||||
_, resp, err := helper.TestEndpoint(router, token,
|
_, resp, err := helper.TestEndpoint(router, token,
|
||||||
"/api/scenarios", "POST", helper.KeyModels{"scenario": newScenario})
|
"/api/scenarios", "POST", helper.KeyModels{"scenario": newScenario})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprint("The following error happend on POSTing a scenario: ", err.Error()))
|
log.Panic("The following error happend on POSTing a scenario: ", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read newScenario's ID from the response
|
// Read newScenario's ID from the response
|
||||||
|
|
|
@ -286,7 +286,6 @@ func TestAddFile(t *testing.T) {
|
||||||
router.ServeHTTP(w, req)
|
router.ServeHTTP(w, req)
|
||||||
|
|
||||||
assert.Equalf(t, 200, w.Code, "Response body: \n%v\n", w.Body)
|
assert.Equalf(t, 200, w.Code, "Response body: \n%v\n", w.Body)
|
||||||
//fmt.Println(w.Body)
|
|
||||||
|
|
||||||
newFileID, err := helper.GetResponseID(w.Body)
|
newFileID, err := helper.GetResponseID(w.Body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -360,7 +359,6 @@ func TestUpdateFile(t *testing.T) {
|
||||||
router.ServeHTTP(w, req)
|
router.ServeHTTP(w, req)
|
||||||
|
|
||||||
assert.Equalf(t, 200, w.Code, "Response body: \n%v\n", w.Body)
|
assert.Equalf(t, 200, w.Code, "Response body: \n%v\n", w.Body)
|
||||||
//fmt.Println(w.Body)
|
|
||||||
|
|
||||||
newFileID, err := helper.GetResponseID(w.Body)
|
newFileID, err := helper.GetResponseID(w.Body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -435,8 +433,6 @@ func TestUpdateFile(t *testing.T) {
|
||||||
req.Header.Add("Authorization", "Bearer "+token)
|
req.Header.Add("Authorization", "Bearer "+token)
|
||||||
router.ServeHTTP(w_updated, req)
|
router.ServeHTTP(w_updated, req)
|
||||||
assert.Equalf(t, 200, w_updated.Code, "Response body: \n%v\n", w_updated.Body)
|
assert.Equalf(t, 200, w_updated.Code, "Response body: \n%v\n", w_updated.Body)
|
||||||
//fmt.Println(w_updated.Body)
|
|
||||||
//assert.Equal(t, c2, w_updated.Header().Get("file"))
|
|
||||||
|
|
||||||
newFileIDUpdated, err := helper.GetResponseID(w_updated.Body)
|
newFileIDUpdated, err := helper.GetResponseID(w_updated.Body)
|
||||||
|
|
||||||
|
@ -484,7 +480,6 @@ func TestDeleteFile(t *testing.T) {
|
||||||
assert.NoError(t, err, "IO copy")
|
assert.NoError(t, err, "IO copy")
|
||||||
contentType := bodyWriter.FormDataContentType()
|
contentType := bodyWriter.FormDataContentType()
|
||||||
bodyWriter.Close()
|
bodyWriter.Close()
|
||||||
//req, err := http.NewRequest("POST", "/api/files?objectID=1&objectType=widget", bodyBuf)
|
|
||||||
|
|
||||||
// Create the request
|
// Create the request
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
Loading…
Add table
Reference in a new issue