Skip to content

Commit

Permalink
fix: db tests
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Aug 4, 2023
1 parent 8cfd8ae commit db3ef32
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions database/pipeline/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package pipeline

import (
"context"
"database/sql/driver"
"reflect"
"testing"
Expand Down Expand Up @@ -65,6 +66,7 @@ func TestPipeline_New(t *testing.T) {
want: &engine{
client: _postgres,
config: &config{CompressionLevel: 1, SkipCreation: false},
ctx: context.TODO(),
logger: logger,
},
},
Expand All @@ -78,6 +80,7 @@ func TestPipeline_New(t *testing.T) {
want: &engine{
client: _sqlite,
config: &config{CompressionLevel: 1, SkipCreation: false},
ctx: context.TODO(),
logger: logger,
},
},
Expand All @@ -87,6 +90,7 @@ func TestPipeline_New(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := New(
WithContext(context.TODO()),
WithClient(test.client),
WithCompressionLevel(test.level),
WithLogger(test.logger),
Expand Down
3 changes: 2 additions & 1 deletion database/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package database

import (
"context"
"testing"

"github.com/DATA-DOG/go-sqlmock"
Expand Down Expand Up @@ -94,7 +95,7 @@ func TestDatabase_Engine_NewResources(t *testing.T) {
// run tests
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
err := test.database.NewResources()
err := test.database.NewResources(context.TODO())

if test.failure {
if err == nil {
Expand Down
3 changes: 2 additions & 1 deletion router/middleware/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func Establish() gin.HandlerFunc {
o := org.Retrieve(c)
r := repo.Retrieve(c)
u := user.Retrieve(c)
ctx := c.Request.Context()

if r == nil {
retErr := fmt.Errorf("repo %s/%s not found", util.PathParameter(c, "org"), util.PathParameter(c, "repo"))
Expand Down Expand Up @@ -62,7 +63,7 @@ func Establish() gin.HandlerFunc {
"user": u.GetName(),
}).Debugf("reading pipeline %s", entry)

pipeline, err := database.FromContext(c).GetPipelineForRepo(p, r)
pipeline, err := database.FromContext(c).GetPipelineForRepo(ctx, p, r)
if err != nil { // assume the pipeline doesn't exist in the database yet (before pipeline support was added)
// send API call to capture the pipeline configuration file
config, err := scm.FromContext(c).ConfigBackoff(u, r, p)
Expand Down
5 changes: 3 additions & 2 deletions router/middleware/pipeline/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package pipeline

import (
"context"
"flag"
"fmt"
"net/http"
Expand Down Expand Up @@ -102,13 +103,13 @@ func TestPipeline_Establish(t *testing.T) {
}

defer func() {
db.DeletePipeline(want)
db.DeletePipeline(context.TODO(), want)
db.DeleteRepo(r)
db.Close()
}()

_, _ = db.CreateRepo(r)
_, _ = db.CreatePipeline(want)
_, _ = db.CreatePipeline(context.TODO(), want)

// setup context
gin.SetMode(gin.TestMode)
Expand Down

0 comments on commit db3ef32

Please sign in to comment.