Skip to content

Commit

Permalink
fixing lint things
Browse files Browse the repository at this point in the history
  • Loading branch information
Claire.Nicholas authored and Claire.Nicholas committed Dec 22, 2023
1 parent 5ff37bd commit fbea7f5
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 113 deletions.
1 change: 0 additions & 1 deletion api/admin/step.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: Apache-2.0

//nolint:dupl // ignore similar code
package admin

import (
Expand Down
2 changes: 1 addition & 1 deletion api/deployment/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func GetDeployment(c *gin.Context) {
u := user.Retrieve(c)
deployment := util.PathParameter(c, "deployment")
ctx := c.Request.Context()

var (
dep *library.Deployment
err error
Expand Down Expand Up @@ -103,7 +104,6 @@ func GetDeployment(c *gin.Context) {

return
}

} else {
dep = d
}
Expand Down
1 change: 1 addition & 0 deletions api/schedule/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func UpdateSchedule(c *gin.Context) {

// set the updated by field using claims
s.SetUpdatedBy(u.GetName())

if input.GetBranch() != "" {
s.SetBranch(input.GetBranch())
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/vela-server/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func processSchedules(ctx context.Context, start time.Time, compiler compiler.En
//
// The previous occurrence of the schedule must be after the starting time of processing schedules.
if !prevTime.After(start) {
logrus.Tracef("%s %s: previous occurence not after starting point", scheduleWait, schedule.GetName())
logrus.Tracef("%s %s: previous occurrence not after starting point", scheduleWait, schedule.GetName())

continue
}
Expand Down Expand Up @@ -277,6 +277,7 @@ func processSchedule(ctx context.Context, s *library.Schedule, compiler compiler
// parent should be "1" if it's the first build ran
b.SetParent(1)
}

r.SetCounter(r.GetCounter() + 1)

// set the build link if a web address is provided
Expand Down
2 changes: 1 addition & 1 deletion database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ type (
logger *logrus.Entry

build.BuildInterface
deployment.DeploymentInterface
executable.BuildExecutableInterface
deployment.DeploymentInterface
hook.HookInterface
log.LogInterface
pipeline.PipelineInterface
Expand Down
4 changes: 1 addition & 3 deletions database/deployment/count.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.
// SPDX-License-Identifier: Apache-2.0

package deployment

Expand Down
4 changes: 1 addition & 3 deletions database/deployment/count_repo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.
// SPDX-License-Identifier: Apache-2.0

package deployment

Expand Down
4 changes: 1 addition & 3 deletions database/deployment/create.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.
// SPDX-License-Identifier: Apache-2.0

package deployment

Expand Down
1 change: 1 addition & 0 deletions database/deployment/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (e *engine) ListDeployments(ctx context.Context) ([]*library.Deployment, er
if err2 != nil {
return nil, err
}

builds = append(builds, b.ToLibrary())
}

Expand Down
1 change: 1 addition & 0 deletions database/deployment/list_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (e *engine) ListDeploymentsForRepo(ctx context.Context, r *library.Repo, pa
if err2 != nil {
return nil, err
}

builds = append(builds, b.ToLibrary())
}

Expand Down
4 changes: 1 addition & 3 deletions database/deployment/list_repo_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright (c) 2023 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.
// SPDX-License-Identifier: Apache-2.0

package deployment

Expand Down
4 changes: 1 addition & 3 deletions database/deployment/list_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright (c) 2023 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.
// SPDX-License-Identifier: Apache-2.0

package deployment

Expand Down
4 changes: 1 addition & 3 deletions database/deployment/opts_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright (c) 2023 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.
// SPDX-License-Identifier: Apache-2.0

package deployment

Expand Down
150 changes: 75 additions & 75 deletions database/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,81 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) {
}
}

func testExecutables(t *testing.T, db Interface, resources *Resources) {
// create a variable to track the number of methods called for pipelines
methods := make(map[string]bool)
// capture the element type of the pipeline interface
element := reflect.TypeOf(new(executable.BuildExecutableInterface)).Elem()
// iterate through all methods found in the pipeline interface
for i := 0; i < element.NumMethod(); i++ {
// skip tracking the methods to create indexes and tables for pipelines
// since those are already called when the database engine starts
if strings.Contains(element.Method(i).Name, "Index") ||
strings.Contains(element.Method(i).Name, "Table") {
continue
}

// add the method name to the list of functions
methods[element.Method(i).Name] = false
}

// create the pipelines
for _, executable := range resources.Executables {
err := db.CreateBuildExecutable(context.TODO(), executable)

Check failure on line 423 in database/integration_test.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] database/integration_test.go#L423

db.CreateBuildExecutable undefined (type Interface has no field or method CreateBuildExecutable) (typecheck)
Raw output
database/integration_test.go:423:13: db.CreateBuildExecutable undefined (type Interface has no field or method CreateBuildExecutable) (typecheck)
		err := db.CreateBuildExecutable(context.TODO(), executable)
		          ^
if err != nil {
t.Errorf("unable to create executable %d: %v", executable.GetID(), err)
}
}
methods["CreateBuildExecutable"] = true

// pop executables for builds
for _, executable := range resources.Executables {
got, err := db.PopBuildExecutable(context.TODO(), executable.GetBuildID())

Check failure on line 432 in database/integration_test.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] database/integration_test.go#L432

db.PopBuildExecutable undefined (type Interface has no field or method PopBuildExecutable) (typecheck)
Raw output
database/integration_test.go:432:18: db.PopBuildExecutable undefined (type Interface has no field or method PopBuildExecutable) (typecheck)
		got, err := db.PopBuildExecutable(context.TODO(), executable.GetBuildID())
		               ^
if err != nil {
t.Errorf("unable to get executable %d for build %d: %v", executable.GetID(), executable.GetBuildID(), err)
}
if !cmp.Equal(got, executable) {
t.Errorf("PopBuildExecutable() is %v, want %v", got, executable)
}
}
methods["PopBuildExecutable"] = true

resources.Builds[0].SetStatus(constants.StatusError)

_, err := db.UpdateBuild(context.TODO(), resources.Builds[0])

Check failure on line 444 in database/integration_test.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] database/integration_test.go#L444

db.UpdateBuild undefined (type Interface has no field or method UpdateBuild) (typecheck)
Raw output
database/integration_test.go:444:15: db.UpdateBuild undefined (type Interface has no field or method UpdateBuild) (typecheck)
	_, err := db.UpdateBuild(context.TODO(), resources.Builds[0])
	             ^
if err != nil {
t.Errorf("unable to update build for clean executables test")
}

err = db.CreateBuildExecutable(context.TODO(), resources.Executables[0])

Check failure on line 449 in database/integration_test.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] database/integration_test.go#L449

db.CreateBuildExecutable undefined (type Interface has no field or method CreateBuildExecutable) (typecheck)
Raw output
database/integration_test.go:449:11: db.CreateBuildExecutable undefined (type Interface has no field or method CreateBuildExecutable) (typecheck)
	err = db.CreateBuildExecutable(context.TODO(), resources.Executables[0])
	         ^
if err != nil {
t.Errorf("unable to create executable %d: %v", resources.Executables[0].GetID(), err)
}

count, err := db.CleanBuildExecutables(context.TODO())

Check failure on line 454 in database/integration_test.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] database/integration_test.go#L454

db.CleanBuildExecutables undefined (type Interface has no field or method CleanBuildExecutables) (typecheck)
Raw output
database/integration_test.go:454:19: db.CleanBuildExecutables undefined (type Interface has no field or method CleanBuildExecutables) (typecheck)
	count, err := db.CleanBuildExecutables(context.TODO())
	                 ^
if err != nil {
t.Errorf("unable to clean executable %d: %v", resources.Executables[0].GetID(), err)
}

if count != 1 {
t.Errorf("CleanBuildExecutables should have affected 1 row, affected %d", count)
}

_, err = db.PopBuildExecutable(context.TODO(), resources.Builds[0].GetID())

Check failure on line 463 in database/integration_test.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] database/integration_test.go#L463

db.PopBuildExecutable undefined (type Interface has no field or method PopBuildExecutable) (typecheck)
Raw output
database/integration_test.go:463:14: db.PopBuildExecutable undefined (type Interface has no field or method PopBuildExecutable) (typecheck)
	_, err = db.PopBuildExecutable(context.TODO(), resources.Builds[0].GetID())
	            ^
if err == nil {
t.Errorf("build executable not cleaned")
}

methods["CleanBuildExecutables"] = true

// ensure we called all the methods we expected to
for method, called := range methods {
if !called {
t.Errorf("method %s was not called for pipelines", method)
}
}
}

func testDeployments(t *testing.T, db Interface, resources *Resources) {
// create a variable to track the number of methods called for deployments
methods := make(map[string]bool)
Expand Down Expand Up @@ -519,81 +594,6 @@ func testDeployments(t *testing.T, db Interface, resources *Resources) {
}
}

func testExecutables(t *testing.T, db Interface, resources *Resources) {
// create a variable to track the number of methods called for pipelines
methods := make(map[string]bool)
// capture the element type of the pipeline interface
element := reflect.TypeOf(new(executable.BuildExecutableInterface)).Elem()
// iterate through all methods found in the pipeline interface
for i := 0; i < element.NumMethod(); i++ {
// skip tracking the methods to create indexes and tables for pipelines
// since those are already called when the database engine starts
if strings.Contains(element.Method(i).Name, "Index") ||
strings.Contains(element.Method(i).Name, "Table") {
continue
}

// add the method name to the list of functions
methods[element.Method(i).Name] = false
}

// create the pipelines
for _, executable := range resources.Executables {
err := db.CreateBuildExecutable(context.TODO(), executable)
if err != nil {
t.Errorf("unable to create executable %d: %v", executable.GetID(), err)
}
}
methods["CreateBuildExecutable"] = true

// pop executables for builds
for _, executable := range resources.Executables {
got, err := db.PopBuildExecutable(context.TODO(), executable.GetBuildID())
if err != nil {
t.Errorf("unable to get executable %d for build %d: %v", executable.GetID(), executable.GetBuildID(), err)
}
if !cmp.Equal(got, executable) {
t.Errorf("PopBuildExecutable() is %v, want %v", got, executable)
}
}
methods["PopBuildExecutable"] = true

resources.Builds[0].SetStatus(constants.StatusError)

_, err := db.UpdateBuild(context.TODO(), resources.Builds[0])
if err != nil {
t.Errorf("unable to update build for clean executables test")
}

err = db.CreateBuildExecutable(context.TODO(), resources.Executables[0])
if err != nil {
t.Errorf("unable to create executable %d: %v", resources.Executables[0].GetID(), err)
}

count, err := db.CleanBuildExecutables(context.TODO())
if err != nil {
t.Errorf("unable to clean executable %d: %v", resources.Executables[0].GetID(), err)
}

if count != 1 {
t.Errorf("CleanBuildExecutables should have affected 1 row, affected %d", count)
}

_, err = db.PopBuildExecutable(context.TODO(), resources.Builds[0].GetID())
if err == nil {
t.Errorf("build executable not cleaned")
}

methods["CleanBuildExecutables"] = true

// ensure we called all the methods we expected to
for method, called := range methods {
if !called {
t.Errorf("method %s was not called for pipelines", method)
}
}
}

func testHooks(t *testing.T, db Interface, resources *Resources) {
// create a variable to track the number of methods called for hooks
methods := make(map[string]bool)
Expand Down
6 changes: 3 additions & 3 deletions database/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ type Interface interface {
// BuildInterface defines the interface for builds stored in the database.
build.BuildInterface

// DeploymentInterface defines the interface for deployments stored in the database.
deployment.DeploymentInterface

// BuildExecutableInterface defines the interface for build executables stored in the database.
executable.BuildExecutableInterface

// DeploymentInterface defines the interface for deployments stored in the database.
deployment.DeploymentInterface

// HookInterface defines the interface for hooks stored in the database.
hook.HookInterface

Expand Down
22 changes: 11 additions & 11 deletions database/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ func (e *engine) NewResources(ctx context.Context) error {
return err
}

// create the database agnostic engine for deployments
e.DeploymentInterface, err = deployment.New(
deployment.WithContext(e.ctx),
deployment.WithClient(e.client),
deployment.WithLogger(e.logger),
deployment.WithSkipCreation(e.config.SkipCreation),
)
if err != nil {
return err
}

// create the database agnostic engine for build_executables
e.BuildExecutableInterface, err = executable.New(
executable.WithContext(e.ctx),
Expand All @@ -59,6 +48,17 @@ func (e *engine) NewResources(ctx context.Context) error {
return err
}

// create the database agnostic engine for deployments
e.DeploymentInterface, err = deployment.New(
deployment.WithContext(e.ctx),
deployment.WithClient(e.client),
deployment.WithLogger(e.logger),
deployment.WithSkipCreation(e.config.SkipCreation),
)
if err != nil {
return err
}

// create the database agnostic engine for hooks
e.HookInterface, err = hook.New(
hook.WithContext(e.ctx),
Expand Down
1 change: 1 addition & 0 deletions router/middleware/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,6 @@ func (f *ECSFormatter) Format(e *logrus.Entry) ([]byte, error) {
TimestampFormat: "2006-01-02T15:04:05.000Z0700",
FieldMap: ecsFieldMap,
}

return jf.Format(e)
}
2 changes: 0 additions & 2 deletions router/middleware/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ func TestMiddleware_Logger_Sanitize(t *testing.T) {
}

func TestMiddleware_Format(t *testing.T) {

wantLabels := "labels.vela"

// setup data, fields, and logger
Expand Down Expand Up @@ -265,5 +264,4 @@ func TestMiddleware_Format(t *testing.T) {
if !strings.Contains(string(got), "/foobar") {
t.Errorf("Format returned %v, want to contain /foobar", string(got))
}

}

0 comments on commit fbea7f5

Please sign in to comment.