From 9f56b662139e4b2ca023d5b9a1754ca664c015ed Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Wed, 20 Nov 2019 10:12:20 +0100 Subject: [PATCH] replace some fmt. calls with log. calls #17 --- amqp/amqpclient.go | 9 +++++---- database/database_test.go | 4 ++-- helper/test_utilities.go | 2 +- routes/dashboard/dashboard_test.go | 3 ++- routes/file/file_test.go | 5 ----- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/amqp/amqpclient.go b/amqp/amqpclient.go index de4f6b4..765c977 100644 --- a/amqp/amqpclient.go +++ b/amqp/amqpclient.go @@ -6,6 +6,7 @@ import ( "git.rwth-aachen.de/acs/public/villas/web-backend-go/database" "github.com/streadway/amqp" "github.com/tidwall/gjson" + "log" "strings" "time" ) @@ -102,7 +103,7 @@ func ConnectAMQP(uri string) error { db := database.GetDB() err = db.Where("UUID = ?", gjson.Get(content, "properties.uuid")).Find(sToBeUpdated).Error 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{}{ @@ -114,10 +115,10 @@ func ConnectAMQP(uri string) error { "RawProperties": gjson.Get(content, "properties"), }).Error 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 { - fmt.Println("AMQP: sending ping command to all simulators") + log.Println("AMQP: sending ping command to all simulators") var a Action a.Act = "ping" diff --git a/database/database_test.go b/database/database_test.go index 8bdba39..99be200 100644 --- a/database/database_test.go +++ b/database/database_test.go @@ -3,6 +3,7 @@ package database import ( "fmt" "github.com/jinzhu/gorm" + "log" "os" "testing" @@ -26,8 +27,7 @@ func TestMain(m *testing.M) { // Verify that you can connect to the database err = db.DB().Ping() if err != nil { - fmt.Println("Error: DB must ping to run tests") - return + log.Panic("Error: DB must ping to run tests") } defer db.Close() diff --git a/helper/test_utilities.go b/helper/test_utilities.go index 669da8a..14673e7 100644 --- a/helper/test_utilities.go +++ b/helper/test_utilities.go @@ -170,7 +170,7 @@ func CompareResponse(resp *bytes.Buffer, expected interface{}) error { opts := jsondiff.DefaultConsoleOptions() diff, text := jsondiff.Compare(resp.Bytes(), expectedBytes, &opts) if diff.String() != "FullMatch" && diff.String() != "SupersetMatch" { - fmt.Println(text) + log.Println(text) return fmt.Errorf("Response: Expected \"%v\". Got \"%v\".", "(FullMatch OR SupersetMatch)", diff.String()) } diff --git a/routes/dashboard/dashboard_test.go b/routes/dashboard/dashboard_test.go index 159e26a..c26f133 100644 --- a/routes/dashboard/dashboard_test.go +++ b/routes/dashboard/dashboard_test.go @@ -11,6 +11,7 @@ import ( "github.com/jinzhu/gorm" "github.com/jinzhu/gorm/dialects/postgres" "github.com/stretchr/testify/assert" + "log" "os" "testing" ) @@ -41,7 +42,7 @@ func addScenario(token string) (scenarioID uint) { _, resp, err := helper.TestEndpoint(router, token, "/api/scenarios", "POST", helper.KeyModels{"scenario": newScenario}) 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 diff --git a/routes/file/file_test.go b/routes/file/file_test.go index 659752f..6bb8f48 100644 --- a/routes/file/file_test.go +++ b/routes/file/file_test.go @@ -286,7 +286,6 @@ func TestAddFile(t *testing.T) { router.ServeHTTP(w, req) assert.Equalf(t, 200, w.Code, "Response body: \n%v\n", w.Body) - //fmt.Println(w.Body) newFileID, err := helper.GetResponseID(w.Body) assert.NoError(t, err) @@ -360,7 +359,6 @@ func TestUpdateFile(t *testing.T) { router.ServeHTTP(w, req) assert.Equalf(t, 200, w.Code, "Response body: \n%v\n", w.Body) - //fmt.Println(w.Body) newFileID, err := helper.GetResponseID(w.Body) assert.NoError(t, err) @@ -435,8 +433,6 @@ func TestUpdateFile(t *testing.T) { req.Header.Add("Authorization", "Bearer "+token) router.ServeHTTP(w_updated, req) 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) @@ -484,7 +480,6 @@ func TestDeleteFile(t *testing.T) { assert.NoError(t, err, "IO copy") contentType := bodyWriter.FormDataContentType() bodyWriter.Close() - //req, err := http.NewRequest("POST", "/api/files?objectID=1&objectType=widget", bodyBuf) // Create the request w := httptest.NewRecorder()