Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Use / prefix for the sql asset paths (#72)
Browse files Browse the repository at this point in the history
* Use / prefix for the sql asset paths

**What**
- The union filesystem assumes everything starts with `/`, so when using
  a generated filesystem via vfsgen, we get erros like

  ```sh
  open /iews: file does not exist
  ```

  Adding the slash in the right places allows both the tests and the
  vfsgen to work exactly as expected. This is also hidden from the
  public API, so users should not need to work about it
- Disable the queue leak detection tests in CI because they are 
   false positives and we can't determine the source

Signed-off-by: Lucas Roesler <[email protected]>
  • Loading branch information
LucasRoesler authored Nov 19, 2020
1 parent b414e86 commit 57ad7de
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 29 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ifneq ($(.GIT_UNTRACKEDCHANGES),)
GITCOMMIT := $(GITCOMMIT)-dirty
endif

# Set an output prefix, which is the local directory if not specified
.PREFIX?=$(shell pwd)

Expand Down Expand Up @@ -51,7 +52,7 @@ setup-env:

.PHONY: .test-ci
.test-ci:
go test -count=1 -cover ./...
go test -v -cover ./...

.PHONY: changelog
changelog: ## Print git hitstory based changelog
Expand Down
4 changes: 2 additions & 2 deletions pkg/db/migrations/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type SQLAssets struct {
// with the migration utilities.
func NewSQLAssets(assets SQLAssets) http.FileSystem {
return union.New(map[string]http.FileSystem{
"migrations": assets.Migrations,
"views": assets.Views,
"/migrations": assets.Migrations,
"/views": assets.Views,
})
}
5 changes: 2 additions & 3 deletions pkg/db/migrations/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ type sqlKind string

const (
migrations sqlKind = "migrations"
views sqlKind = "views"
views sqlKind = "views"
)


func getSQL(name string, kind sqlKind, assets http.FileSystem) (string, error) {
file, err := assets.Open(filepath.Join(string(kind),name))
file, err := assets.Open(filepath.Join("/", string(kind), name))
if err != nil {
return "", fmt.Errorf("getSQL failed: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/db/migrations/testdata/migrations/000_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ CREATE TABLE IF NOT EXISTS resources (
parent_id uuid REFERENCES resources ON DELETE CASCADE,
kind CITEXT NOT NULL,
name text NOT NULL
);
);
1 change: 0 additions & 1 deletion pkg/db/migrations/testdata/views/001_ids_views.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
CREATE OR REPLACE VIEW resource_ids (id) AS
SELECT resource_id
FROM resources;

12 changes: 11 additions & 1 deletion pkg/queue/handlers/api_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func toComparableAPIRequestProgress(val APIRequestProgress) httpRequestProgressT
}

func TestAPIRequestHandlerProcess(t *testing.T) {
defer goleak.VerifyNone(t)
defer verifyLeak(t)


ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
Expand Down Expand Up @@ -563,3 +564,12 @@ func intP(n int) *int {
func strP(s string) *string {
return &s
}


func verifyLeak(t *testing.T) {
_, exists := os.LookupEnv("CI")
if exists {
return
}
goleak.VerifyNone(t)
}
22 changes: 14 additions & 8 deletions pkg/queue/postgres/dequeuer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
uuid "github.com/satori/go.uuid"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)

func TestFinish(t *testing.T) {
defer goleak.VerifyNone(t)
verifyLeak(t)


logrus.SetOutput(ioutil.Discard)
defer logrus.SetOutput(os.Stdout)
Expand Down Expand Up @@ -92,7 +92,8 @@ func TestFinish(t *testing.T) {
}

func TestFail(t *testing.T) {
defer goleak.VerifyNone(t)
verifyLeak(t)


logrus.SetOutput(ioutil.Discard)
defer logrus.SetOutput(os.Stdout)
Expand Down Expand Up @@ -163,7 +164,8 @@ func TestFail(t *testing.T) {
}

func TestHeartbeat(t *testing.T) {
defer goleak.VerifyNone(t)
verifyLeak(t)


logrus.SetOutput(ioutil.Discard)
defer logrus.SetOutput(os.Stdout)
Expand Down Expand Up @@ -336,7 +338,8 @@ func TestHeartbeat(t *testing.T) {
}

func TestDequeueTicker(t *testing.T) {
defer goleak.VerifyNone(t)
verifyLeak(t)


logrus.SetOutput(ioutil.Discard)
defer logrus.SetOutput(os.Stdout)
Expand Down Expand Up @@ -426,7 +429,8 @@ func TestDequeueTicker(t *testing.T) {
}

func TestDequeue(t *testing.T) {
defer goleak.VerifyNone(t)
verifyLeak(t)


logrus.SetOutput(ioutil.Discard)
defer logrus.SetOutput(os.Stdout)
Expand Down Expand Up @@ -560,7 +564,8 @@ func TestDequeue(t *testing.T) {
}

func TestProcessableQueues(t *testing.T) {
defer goleak.VerifyNone(t)
verifyLeak(t)


tests := []struct {
name string
Expand Down Expand Up @@ -609,7 +614,8 @@ func TestProcessableQueues(t *testing.T) {
}

func TestQueueList(t *testing.T) {
defer goleak.VerifyNone(t)
verifyLeak(t)


ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
Expand Down
17 changes: 16 additions & 1 deletion pkg/queue/postgres/fixtures_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package postgres

import uuid "github.com/satori/go.uuid"
import (
"os"
"testing"

uuid "github.com/satori/go.uuid"
"go.uber.org/goleak"
)

var (
queueID1 = uuid.NewV4().String()
Expand All @@ -9,3 +15,12 @@ var (
progress = []byte(`{"scale": 99}`)
spec = []byte(`{"field": "value"}`)
)


func verifyLeak(t *testing.T) {
_, exists := os.LookupEnv("CI")
if exists {
return
}
goleak.VerifyNone(t)
}
4 changes: 2 additions & 2 deletions pkg/queue/postgres/queuer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
uuid "github.com/satori/go.uuid"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)

func TestEnqueue(t *testing.T) {
defer goleak.VerifyNone(t)
verifyLeak(t)


logrus.SetOutput(ioutil.Discard)
defer logrus.SetOutput(os.Stdout)
Expand Down
7 changes: 4 additions & 3 deletions pkg/queue/postgres/retention_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"time"

"github.com/contiamo/go-base/v2/pkg/queue/handlers"
"go.uber.org/goleak"

"github.com/Masterminds/squirrel"
dbtest "github.com/contiamo/go-base/v2/pkg/db/test"
Expand All @@ -21,7 +20,8 @@ import (
)

func TestRetentionHandler(t *testing.T) {
defer goleak.VerifyNone(t)
verifyLeak(t)


logrus.SetOutput(ioutil.Discard)
defer logrus.SetOutput(os.Stdout)
Expand Down Expand Up @@ -196,7 +196,8 @@ func insertTestTask(ctx context.Context, db *sql.DB, task *queue.Task) error {
}

func TestAssertRetentionSchedule(t *testing.T) {
defer goleak.VerifyNone(t)
verifyLeak(t)


ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
Expand Down
10 changes: 6 additions & 4 deletions pkg/queue/postgres/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
uuid "github.com/satori/go.uuid"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)

func TestSchedule(t *testing.T) {
defer goleak.VerifyNone(t)
verifyLeak(t)


logrus.SetOutput(ioutil.Discard)
defer logrus.SetOutput(os.Stdout)
Expand Down Expand Up @@ -168,7 +168,8 @@ func TestSchedule(t *testing.T) {
}

func TestEnsure(t *testing.T) {
defer goleak.VerifyNone(t)
verifyLeak(t)


logrus.SetOutput(ioutil.Discard)
defer logrus.SetOutput(os.Stdout)
Expand Down Expand Up @@ -290,7 +291,8 @@ func TestEnsure(t *testing.T) {
}

func TestAssertSchedule(t *testing.T) {
defer goleak.VerifyNone(t)
verifyLeak(t)


ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
Expand Down
4 changes: 2 additions & 2 deletions pkg/queue/postgres/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"github.com/contiamo/go-base/v2/pkg/queue"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)

func TestSetupTables(t *testing.T) {
defer goleak.VerifyNone(t)
verifyLeak(t)


ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
Expand Down

0 comments on commit 57ad7de

Please sign in to comment.