diff --git a/api/log/create_service.go b/api/log/create_service.go index c6014f09b..bf8cd4ec1 100644 --- a/api/log/create_service.go +++ b/api/log/create_service.go @@ -61,8 +61,6 @@ import ( // responses: // '201': // description: Successfully created the service logs -// schema: -// "$ref": "#/definitions/Log" // '400': // description: Unable to create the service logs // schema: @@ -113,7 +111,7 @@ func CreateServiceLog(c *gin.Context) { input.SetRepoID(r.GetID()) // send API call to create the logs - l, err := database.FromContext(c).CreateLog(input) + err = database.FromContext(c).CreateLog(input) if err != nil { retErr := fmt.Errorf("unable to create logs for service %s: %w", entry, err) @@ -122,5 +120,5 @@ func CreateServiceLog(c *gin.Context) { return } - c.JSON(http.StatusCreated, l) + c.JSON(http.StatusCreated, nil) } diff --git a/api/log/create_step.go b/api/log/create_step.go index 5bc83c646..d2abed7a9 100644 --- a/api/log/create_step.go +++ b/api/log/create_step.go @@ -61,8 +61,6 @@ import ( // responses: // '201': // description: Successfully created the logs for step -// schema: -// "$ref": "#/definitions/Log" // '400': // description: Unable to create the logs for a step // schema: @@ -113,7 +111,7 @@ func CreateStepLog(c *gin.Context) { input.SetRepoID(r.GetID()) // send API call to create the logs - l, err := database.FromContext(c).CreateLog(input) + err = database.FromContext(c).CreateLog(input) if err != nil { retErr := fmt.Errorf("unable to create logs for step %s: %w", entry, err) @@ -122,5 +120,5 @@ func CreateStepLog(c *gin.Context) { return } - c.JSON(http.StatusCreated, l) + c.JSON(http.StatusCreated, nil) } diff --git a/api/log/update_service.go b/api/log/update_service.go index 82b56f13b..92d96e1f1 100644 --- a/api/log/update_service.go +++ b/api/log/update_service.go @@ -124,7 +124,7 @@ func UpdateServiceLog(c *gin.Context) { } // send API call to update the log - l, err = database.FromContext(c).UpdateLog(l) + err = database.FromContext(c).UpdateLog(l) if err != nil { retErr := fmt.Errorf("unable to update logs for service %s: %w", entry, err) @@ -133,5 +133,5 @@ func UpdateServiceLog(c *gin.Context) { return } - c.JSON(http.StatusOK, l) + c.JSON(http.StatusOK, nil) } diff --git a/api/log/update_step.go b/api/log/update_step.go index dcb4a99d1..14a642d57 100644 --- a/api/log/update_step.go +++ b/api/log/update_step.go @@ -124,7 +124,7 @@ func UpdateStepLog(c *gin.Context) { } // send API call to update the log - l, err = database.FromContext(c).UpdateLog(l) + err = database.FromContext(c).UpdateLog(l) if err != nil { retErr := fmt.Errorf("unable to update logs for step %s: %w", entry, err) @@ -133,5 +133,5 @@ func UpdateStepLog(c *gin.Context) { return } - c.JSON(http.StatusOK, l) + c.JSON(http.StatusOK, nil) } diff --git a/api/service/plan.go b/api/service/plan.go index fecd03f24..4912f38d1 100644 --- a/api/service/plan.go +++ b/api/service/plan.go @@ -61,7 +61,7 @@ func PlanServices(database database.Interface, p *pipeline.Build, b *library.Bui l.SetData([]byte{}) // send API call to create the service logs - _, err = database.CreateLog(l) + err = database.CreateLog(l) if err != nil { return services, fmt.Errorf("unable to create service logs for service %s: %w", s.GetName(), err) } diff --git a/api/step/plan.go b/api/step/plan.go index c74a52614..b072cf4f7 100644 --- a/api/step/plan.go +++ b/api/step/plan.go @@ -88,7 +88,7 @@ func planStep(database database.Interface, b *library.Build, c *pipeline.Contain l.SetData([]byte{}) // send API call to create the step logs - _, err = database.CreateLog(l) + err = database.CreateLog(l) if err != nil { return nil, fmt.Errorf("unable to create logs for step %s: %w", s.GetName(), err) } diff --git a/database/log/count_build_test.go b/database/log/count_build_test.go index e168f80ec..d462eedf0 100644 --- a/database/log/count_build_test.go +++ b/database/log/count_build_test.go @@ -43,12 +43,12 @@ func TestLog_Engine_CountLogsForBuild(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - _, err := _sqlite.CreateLog(_service) + err := _sqlite.CreateLog(_service) if err != nil { t.Errorf("unable to create test service log for sqlite: %v", err) } - _, err = _sqlite.CreateLog(_step) + err = _sqlite.CreateLog(_step) if err != nil { t.Errorf("unable to create test step log for sqlite: %v", err) } diff --git a/database/log/count_test.go b/database/log/count_test.go index 2af820203..99e75a767 100644 --- a/database/log/count_test.go +++ b/database/log/count_test.go @@ -37,12 +37,12 @@ func TestLog_Engine_CountLogs(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - _, err := _sqlite.CreateLog(_service) + err := _sqlite.CreateLog(_service) if err != nil { t.Errorf("unable to create test service log for sqlite: %v", err) } - _, err = _sqlite.CreateLog(_step) + err = _sqlite.CreateLog(_step) if err != nil { t.Errorf("unable to create test step log for sqlite: %v", err) } diff --git a/database/log/create.go b/database/log/create.go index b1767c01e..978da9a1f 100644 --- a/database/log/create.go +++ b/database/log/create.go @@ -14,7 +14,7 @@ import ( ) // CreateLog creates a new log in the database. -func (e *engine) CreateLog(l *library.Log) (*library.Log, error) { +func (e *engine) CreateLog(l *library.Log) error { // check what the log entry is for switch { case l.GetServiceID() > 0: @@ -33,7 +33,7 @@ func (e *engine) CreateLog(l *library.Log) (*library.Log, error) { // https://pkg.go.dev/github.com/go-vela/types/database#Log.Validate err := log.Validate() if err != nil { - return nil, err + return err } // compress log data for the resource @@ -43,14 +43,15 @@ func (e *engine) CreateLog(l *library.Log) (*library.Log, error) { if err != nil { switch { case l.GetServiceID() > 0: - return nil, fmt.Errorf("unable to compress log for service %d for build %d: %w", l.GetServiceID(), l.GetBuildID(), err) + return fmt.Errorf("unable to compress log for service %d for build %d: %w", l.GetServiceID(), l.GetBuildID(), err) case l.GetStepID() > 0: - return nil, fmt.Errorf("unable to compress log for step %d for build %d: %w", l.GetStepID(), l.GetBuildID(), err) + return fmt.Errorf("unable to compress log for step %d for build %d: %w", l.GetStepID(), l.GetBuildID(), err) } } // send query to the database - result := e.client.Table(constants.TableLog).Create(log) - - return log.ToLibrary(), result.Error + return e.client. + Table(constants.TableLog). + Create(log). + Error } diff --git a/database/log/create_test.go b/database/log/create_test.go index 68e0a2d40..1574e88a8 100644 --- a/database/log/create_test.go +++ b/database/log/create_test.go @@ -73,7 +73,7 @@ VALUES ($1,$2,$3,$4,$5,$6) RETURNING "id"`). for _, test := range tests { t.Run(test.name, func(t *testing.T) { for _, log := range test.logs { - _, err := test.database.CreateLog(log) + err := test.database.CreateLog(log) if test.failure { if err == nil { diff --git a/database/log/delete_test.go b/database/log/delete_test.go index dbfdbca00..15329a0af 100644 --- a/database/log/delete_test.go +++ b/database/log/delete_test.go @@ -29,7 +29,7 @@ func TestLog_Engine_DeleteLog(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - _, err := _sqlite.CreateLog(_log) + err := _sqlite.CreateLog(_log) if err != nil { t.Errorf("unable to create test log for sqlite: %v", err) } diff --git a/database/log/get_service_test.go b/database/log/get_service_test.go index 3ff82d6c8..26f42813c 100644 --- a/database/log/get_service_test.go +++ b/database/log/get_service_test.go @@ -42,7 +42,7 @@ func TestLog_Engine_GetLogForService(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - _, err := _sqlite.CreateLog(_log) + err := _sqlite.CreateLog(_log) if err != nil { t.Errorf("unable to create test log for sqlite: %v", err) } diff --git a/database/log/get_step_test.go b/database/log/get_step_test.go index d092e30a9..39f019039 100644 --- a/database/log/get_step_test.go +++ b/database/log/get_step_test.go @@ -42,7 +42,7 @@ func TestLog_Engine_GetLogForStep(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - _, err := _sqlite.CreateLog(_log) + err := _sqlite.CreateLog(_log) if err != nil { t.Errorf("unable to create test log for sqlite: %v", err) } diff --git a/database/log/get_test.go b/database/log/get_test.go index 7127d3165..31325e3ac 100644 --- a/database/log/get_test.go +++ b/database/log/get_test.go @@ -35,7 +35,7 @@ func TestLog_Engine_GetLog(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - _, err := _sqlite.CreateLog(_log) + err := _sqlite.CreateLog(_log) if err != nil { t.Errorf("unable to create test log for sqlite: %v", err) } diff --git a/database/log/interface.go b/database/log/interface.go index 5b71be967..8c72a5098 100644 --- a/database/log/interface.go +++ b/database/log/interface.go @@ -31,7 +31,7 @@ type LogInterface interface { // CountLogsForBuild defines a function that gets the count of logs by build ID. CountLogsForBuild(*library.Build) (int64, error) // CreateLog defines a function that creates a new log. - CreateLog(*library.Log) (*library.Log, error) + CreateLog(*library.Log) error // DeleteLog defines a function that deletes an existing log. DeleteLog(*library.Log) error // GetLog defines a function that gets a log by ID. @@ -45,5 +45,5 @@ type LogInterface interface { // ListLogsForBuild defines a function that gets a list of logs by build ID. ListLogsForBuild(*library.Build, int, int) ([]*library.Log, int64, error) // UpdateLog defines a function that updates an existing log. - UpdateLog(*library.Log) (*library.Log, error) + UpdateLog(*library.Log) error } diff --git a/database/log/list_build_test.go b/database/log/list_build_test.go index 7ffcc0f46..fb08236e9 100644 --- a/database/log/list_build_test.go +++ b/database/log/list_build_test.go @@ -54,12 +54,12 @@ func TestLog_Engine_ListLogsForBuild(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - _, err := _sqlite.CreateLog(_service) + err := _sqlite.CreateLog(_service) if err != nil { t.Errorf("unable to create test service log for sqlite: %v", err) } - _, err = _sqlite.CreateLog(_step) + err = _sqlite.CreateLog(_step) if err != nil { t.Errorf("unable to create test step log for sqlite: %v", err) } diff --git a/database/log/list_test.go b/database/log/list_test.go index 343af9d5a..0cf420255 100644 --- a/database/log/list_test.go +++ b/database/log/list_test.go @@ -48,12 +48,12 @@ func TestLog_Engine_ListLogs(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - _, err := _sqlite.CreateLog(_service) + err := _sqlite.CreateLog(_service) if err != nil { t.Errorf("unable to create test service log for sqlite: %v", err) } - _, err = _sqlite.CreateLog(_step) + err = _sqlite.CreateLog(_step) if err != nil { t.Errorf("unable to create test step log for sqlite: %v", err) } diff --git a/database/log/update.go b/database/log/update.go index 62ba865bc..fb7165004 100644 --- a/database/log/update.go +++ b/database/log/update.go @@ -14,7 +14,7 @@ import ( ) // UpdateLog updates an existing log in the database. -func (e *engine) UpdateLog(l *library.Log) (*library.Log, error) { +func (e *engine) UpdateLog(l *library.Log) error { // check what the log entry is for switch { case l.GetServiceID() > 0: @@ -33,7 +33,7 @@ func (e *engine) UpdateLog(l *library.Log) (*library.Log, error) { // https://pkg.go.dev/github.com/go-vela/types/database#Log.Validate err := log.Validate() if err != nil { - return nil, err + return err } // compress log data for the resource @@ -43,14 +43,15 @@ func (e *engine) UpdateLog(l *library.Log) (*library.Log, error) { if err != nil { switch { case l.GetServiceID() > 0: - return nil, fmt.Errorf("unable to compress log for service %d for build %d: %w", l.GetServiceID(), l.GetBuildID(), err) + return fmt.Errorf("unable to compress log for service %d for build %d: %w", l.GetServiceID(), l.GetBuildID(), err) case l.GetStepID() > 0: - return nil, fmt.Errorf("unable to compress log for step %d for build %d: %w", l.GetStepID(), l.GetBuildID(), err) + return fmt.Errorf("unable to compress log for step %d for build %d: %w", l.GetStepID(), l.GetBuildID(), err) } } // send query to the database - result := e.client.Table(constants.TableLog).Save(log) - - return log.ToLibrary(), result.Error + return e.client. + Table(constants.TableLog). + Save(log). + Error } diff --git a/database/log/update_test.go b/database/log/update_test.go index 9659cfb65..0b4e8e127 100644 --- a/database/log/update_test.go +++ b/database/log/update_test.go @@ -47,12 +47,12 @@ WHERE "id" = $6`). _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - _, err := _sqlite.CreateLog(_service) + err := _sqlite.CreateLog(_service) if err != nil { t.Errorf("unable to create test service log for sqlite: %v", err) } - _, err = _sqlite.CreateLog(_step) + err = _sqlite.CreateLog(_step) if err != nil { t.Errorf("unable to create test step log for sqlite: %v", err) } @@ -82,7 +82,7 @@ WHERE "id" = $6`). for _, test := range tests { t.Run(test.name, func(t *testing.T) { for _, log := range test.logs { - _, err = test.database.UpdateLog(log) + err = test.database.UpdateLog(log) if test.failure { if err == nil { diff --git a/mock/server/log.go b/mock/server/log.go index 8a101c4d2..3becfff38 100644 --- a/mock/server/log.go +++ b/mock/server/log.go @@ -51,12 +51,7 @@ func getServiceLog(c *gin.Context) { // addServiceLog returns mock JSON for a http GET. func addServiceLog(c *gin.Context) { - data := []byte(LogResp) - - var body library.Log - _ = json.Unmarshal(data, &body) - - c.JSON(http.StatusCreated, body) + c.JSON(http.StatusCreated, nil) } // updateServiceLog has a param :service returns mock JSON for a http PUT. @@ -73,12 +68,7 @@ func updateServiceLog(c *gin.Context) { return } - data := []byte(LogResp) - - var body library.Log - _ = json.Unmarshal(data, &body) - - c.JSON(http.StatusOK, body) + c.JSON(http.StatusOK, nil) } // removeServiceLog has a param :service returns mock JSON for a http DELETE. @@ -122,12 +112,7 @@ func getStepLog(c *gin.Context) { // addStepLog returns mock JSON for a http GET. func addStepLog(c *gin.Context) { - data := []byte(LogResp) - - var body library.Log - _ = json.Unmarshal(data, &body) - - c.JSON(http.StatusCreated, body) + c.JSON(http.StatusCreated, nil) } // updateStepLog has a param :step returns mock JSON for a http PUT. @@ -144,12 +129,7 @@ func updateStepLog(c *gin.Context) { return } - data := []byte(LogResp) - - var body library.Log - _ = json.Unmarshal(data, &body) - - c.JSON(http.StatusOK, body) + c.JSON(http.StatusOK, nil) } // removeStepLog has a param :step returns mock JSON for a http DELETE.