From 683248dbbfa5a9d3508f005b6f65a1aaf90e7a79 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Wed, 28 Jun 2023 10:38:40 -0500 Subject: [PATCH 01/64] feat(database): add integration testing --- .github/workflows/test.yml | 4 ++-- Makefile | 14 +++++++++----- database/integration_test.go | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 database/integration_test.go diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f3cf03420..cdc0c6aa3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,10 +25,10 @@ jobs: - name: test run: | - go test -race -covermode=atomic -coverprofile=coverage.out ./... + make test - name: coverage uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} - file: coverage.out + file: coverage.out \ No newline at end of file diff --git a/Makefile b/Makefile index 61dce5988..be6b2818b 100644 --- a/Makefile +++ b/Makefile @@ -91,6 +91,13 @@ fix: @echo "### Fixing Go Code" @go fix ./... +# The `integration-test` target is intended to run all integration tests for the Go source code. +.PHONY: integration-test +integration-test: + @echo + @echo "### Integration Testing" + @go test -run TestDatabase_Integration ./... + # The `test` target is intended to run # the tests for the Go source code. # @@ -99,7 +106,7 @@ fix: test: @echo @echo "### Testing Go Code" - @go test -race ./... + @go test -race -covermode=atomic -coverprofile=coverage.out ./... # The `test-cover` target is intended to run # the tests for the Go source code and then @@ -107,10 +114,7 @@ test: # # Usage: `make test-cover` .PHONY: test-cover -test-cover: - @echo - @echo "### Creating test coverage report" - @go test -race -covermode=atomic -coverprofile=coverage.out ./... +test-cover: test @echo @echo "### Opening test coverage report" @go tool cover -html=coverage.out diff --git a/database/integration_test.go b/database/integration_test.go new file mode 100644 index 000000000..378dbd871 --- /dev/null +++ b/database/integration_test.go @@ -0,0 +1,16 @@ +// Copyright (c) 2023 Target Brands, Inc. All rights reserved. +// +// Use of this source code is governed by the LICENSE file in this repository. + +package database + +import ( + "fmt" + "testing" +) + +func TestDatabase_Integration(t *testing.T) { + fmt.Println("Hello") + + t.Error("demonstrating failure") +} From e2f9307f7eb149e882e34abae29f10cc2d8490fe Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Wed, 28 Jun 2023 10:48:00 -0500 Subject: [PATCH 02/64] feat(actions): add integration-test workflow --- .github/workflows/integration-test.yml | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/integration-test.yml diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml new file mode 100644 index 000000000..f8b08f49a --- /dev/null +++ b/.github/workflows/integration-test.yml @@ -0,0 +1,42 @@ +# name of the action +name: integration-test + +# trigger on pull_request events +on: + pull_request: + +# pipeline to execute +jobs: + database: + runs-on: ubuntu-latest + + services: + postgres: + image: postgres:15-alpine + env: + POSTGRES_DB: vela + POSTGRES_PASSWORD: notARealPassword1234 + POSTGRES_USER: vela + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + steps: + - name: clone + uses: actions/checkout@v3 + + - name: install go + uses: actions/setup-go@v4 + with: + # use version from go.mod file + go-version-file: 'go.mod' + cache: true + check-latest: true + + - name: test + run: | + make integration-test \ No newline at end of file From b910bfc05ab62701f98c75c055910234f21ffc16 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Wed, 28 Jun 2023 10:48:12 -0500 Subject: [PATCH 03/64] feat(database): add integration tests --- database/integration_test.go | 59 ++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 378dbd871..c9f0e73ce 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -5,12 +5,65 @@ package database import ( - "fmt" + "strings" "testing" + "time" ) func TestDatabase_Integration(t *testing.T) { - fmt.Println("Hello") + // setup tests + tests := []struct { + failure bool + name string + config *config + }{ + { + name: "success with postgres", + failure: false, + config: &config{ + Driver: "postgres", + Address: "postgres://vela:notARealPassword12345@localhost:5432/vela", + CompressionLevel: 3, + ConnectionLife: 10 * time.Second, + ConnectionIdle: 5, + ConnectionOpen: 20, + EncryptionKey: "A1B2C3D4E5G6H7I8J9K0LMNOPQRSTUVW", + SkipCreation: false, + }, + }, + } - t.Error("demonstrating failure") + // run tests + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + db, err := New( + WithAddress(test.config.Address), + WithCompressionLevel(test.config.CompressionLevel), + WithConnectionLife(test.config.ConnectionLife), + WithConnectionIdle(test.config.ConnectionIdle), + WithConnectionOpen(test.config.ConnectionOpen), + WithDriver(test.config.Driver), + WithEncryptionKey(test.config.EncryptionKey), + WithSkipCreation(test.config.SkipCreation), + ) + if err != nil { + t.Errorf("unable to create new database engine for %s: %v", test.name, err) + } + + driver := db.Driver() + if !strings.EqualFold(driver, test.config.Driver) { + t.Errorf("Driver() is %v, want %v", driver, test.config.Driver) + } + + err = db.Ping() + if err != nil { + t.Errorf("unable to ping database engine for %s: %v", test.name, err) + } + + err = db.Close() + if err != nil { + t.Errorf("unable to close database engine for %s: %v", test.name, err) + } + }) + } } From 09fd21775b90104a6949d4a2559b3428d5dbb9dc Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Wed, 28 Jun 2023 10:59:35 -0500 Subject: [PATCH 04/64] fix: use env var to skip integration tests --- Makefile | 2 +- database/integration_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index be6b2818b..f46e05a3f 100644 --- a/Makefile +++ b/Makefile @@ -96,7 +96,7 @@ fix: integration-test: @echo @echo "### Integration Testing" - @go test -run TestDatabase_Integration ./... + INTEGRATION=1 go test -run TestDatabase_Integration ./... # The `test` target is intended to run # the tests for the Go source code. diff --git a/database/integration_test.go b/database/integration_test.go index c9f0e73ce..9e8e8f843 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -5,12 +5,18 @@ package database import ( + "os" "strings" "testing" "time" ) func TestDatabase_Integration(t *testing.T) { + // check if we should skip the integration test + if os.Getenv("INTEGRATION") == "" { + t.Skipf("skipping %s integration test due to environment variable constraint", t.Name()) + } + // setup tests tests := []struct { failure bool From 643f27a0984ef20946fd7e495a74491213d5ece3 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Wed, 28 Jun 2023 11:12:32 -0500 Subject: [PATCH 05/64] fix: password for integration tests --- .github/workflows/integration-test.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index f8b08f49a..2b400f4fa 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -1,9 +1,12 @@ # name of the action name: integration-test -# trigger on pull_request events +# trigger on pull_request events that modify this file or any database files on: pull_request: + paths: + - '.github/workflows/integration-test.yml' + - 'database/**' # pipeline to execute jobs: @@ -15,7 +18,7 @@ jobs: image: postgres:15-alpine env: POSTGRES_DB: vela - POSTGRES_PASSWORD: notARealPassword1234 + POSTGRES_PASSWORD: notARealPassword12345 POSTGRES_USER: vela options: >- --health-cmd pg_isready From ffca1a22975247308ea063e78a4d2c28bb1308c8 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Wed, 28 Jun 2023 11:23:28 -0500 Subject: [PATCH 06/64] test: comment out paths for prs --- .github/workflows/integration-test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 2b400f4fa..56d5e828f 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -4,9 +4,9 @@ name: integration-test # trigger on pull_request events that modify this file or any database files on: pull_request: - paths: - - '.github/workflows/integration-test.yml' - - 'database/**' +# paths: +# - '.github/workflows/integration-test.yml' +# - 'database/**' # pipeline to execute jobs: From 4f57c940bc1124eaa0d17c1033bc99e5d25ede19 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Wed, 28 Jun 2023 11:24:01 -0500 Subject: [PATCH 07/64] revert: comment out paths for prs --- .github/workflows/integration-test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 56d5e828f..2b400f4fa 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -4,9 +4,9 @@ name: integration-test # trigger on pull_request events that modify this file or any database files on: pull_request: -# paths: -# - '.github/workflows/integration-test.yml' -# - 'database/**' + paths: + - '.github/workflows/integration-test.yml' + - 'database/**' # pipeline to execute jobs: From 7bfb032e610067c3e613bcb7e4e4cbc1d0fdddc9 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Wed, 28 Jun 2023 12:58:51 -0500 Subject: [PATCH 08/64] enhance(database): add worker integration tests --- database/integration_test.go | 102 +++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/database/integration_test.go b/database/integration_test.go index 9e8e8f843..ea75394ad 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -6,9 +6,12 @@ package database import ( "os" + "reflect" "strings" "testing" "time" + + "github.com/go-vela/types/library" ) func TestDatabase_Integration(t *testing.T) { @@ -66,6 +69,10 @@ func TestDatabase_Integration(t *testing.T) { t.Errorf("unable to ping database engine for %s: %v", test.name, err) } + t.Run("test_workers", func(t *testing.T) { + testWorkers(t, db) + }) + err = db.Close() if err != nil { t.Errorf("unable to close database engine for %s: %v", test.name, err) @@ -73,3 +80,98 @@ func TestDatabase_Integration(t *testing.T) { }) } } + +func testWorkers(t *testing.T, db Interface) { + one := new(library.Worker) + one.SetID(1) + one.SetHostname("worker-1.example.com") + one.SetAddress("https://worker-1.example.com") + one.SetRoutes([]string{"vela"}) + one.SetActive(true) + one.SetStatus("available") + one.SetLastStatusUpdateAt(time.Time{}.UTC().Unix()) + one.SetRunningBuildIDs([]string{"12345"}) + one.SetLastBuildStartedAt(time.Time{}.UTC().Unix()) + one.SetLastBuildFinishedAt(time.Time{}.UTC().Unix()) + one.SetLastCheckedIn(time.Time{}.UTC().Unix()) + one.SetBuildLimit(1) + + two := new(library.Worker) + two.SetID(2) + two.SetHostname("worker-2.example.com") + two.SetAddress("https://worker-2.example.com") + two.SetRoutes([]string{"vela"}) + two.SetActive(true) + two.SetStatus("available") + two.SetLastStatusUpdateAt(time.Time{}.UTC().Unix()) + two.SetRunningBuildIDs([]string{"12345"}) + two.SetLastBuildStartedAt(time.Time{}.UTC().Unix()) + two.SetLastBuildFinishedAt(time.Time{}.UTC().Unix()) + two.SetLastCheckedIn(time.Time{}.UTC().Unix()) + two.SetBuildLimit(1) + + workers := []*library.Worker{one, two} + + // create the workers + for _, worker := range workers { + err := db.CreateWorker(worker) + if err != nil { + t.Errorf("unable to create worker %s: %v", worker.GetHostname(), err) + } + } + + // count the workers + count, err := db.CountWorkers() + if err != nil { + t.Errorf("unable to count workers: %v", err) + } + if count != 2 { + t.Errorf("CountWorkers() is %v, want 2", count) + } + + // list the workers + list, err := db.ListWorkers() + if err != nil { + t.Errorf("unable to list workers: %v", err) + } + if !reflect.DeepEqual(list, workers) { + t.Errorf("ListWorkers() is %v, want %v", list, workers) + } + + // lookup the workers by hostname + for _, worker := range workers { + got, err := db.GetWorkerForHostname(worker.GetHostname()) + if err != nil { + t.Errorf("unable to get worker %s by hostname: %v", worker.GetHostname(), err) + } + if !reflect.DeepEqual(got, worker) { + t.Errorf("GetWorkerForHostname() is %v, want %v", got, worker) + } + } + + // update the workers + for _, worker := range workers { + worker.SetActive(false) + err = db.UpdateWorker(worker) + if err != nil { + t.Errorf("unable to update worker %s: %v", worker.GetHostname(), err) + } + + // lookup the worker by ID + got, err := db.GetWorker(worker.GetID()) + if err != nil { + t.Errorf("unable to get worker %s by ID: %v", worker.GetHostname(), err) + } + if !reflect.DeepEqual(got, worker) { + t.Errorf("GetWorker() is %v, want %v", got, worker) + } + } + + // delete the workers + for _, worker := range workers { + err = db.DeleteWorker(worker) + if err != nil { + t.Errorf("unable to delete worker %s: %v", worker.GetHostname(), err) + } + } +} From aa52426c02b5cffb896af414ea203f39f00926cd Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Wed, 28 Jun 2023 13:05:54 -0500 Subject: [PATCH 09/64] fix(database): timestamps for worker tests --- database/integration_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index ea75394ad..b952dbcdf 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -89,11 +89,11 @@ func testWorkers(t *testing.T, db Interface) { one.SetRoutes([]string{"vela"}) one.SetActive(true) one.SetStatus("available") - one.SetLastStatusUpdateAt(time.Time{}.UTC().Unix()) + one.SetLastStatusUpdateAt(time.Now().UTC().Unix()) one.SetRunningBuildIDs([]string{"12345"}) - one.SetLastBuildStartedAt(time.Time{}.UTC().Unix()) - one.SetLastBuildFinishedAt(time.Time{}.UTC().Unix()) - one.SetLastCheckedIn(time.Time{}.UTC().Unix()) + one.SetLastBuildStartedAt(time.Now().UTC().Unix()) + one.SetLastBuildFinishedAt(time.Now().UTC().Unix()) + one.SetLastCheckedIn(time.Now().UTC().Unix()) one.SetBuildLimit(1) two := new(library.Worker) @@ -103,11 +103,11 @@ func testWorkers(t *testing.T, db Interface) { two.SetRoutes([]string{"vela"}) two.SetActive(true) two.SetStatus("available") - two.SetLastStatusUpdateAt(time.Time{}.UTC().Unix()) + two.SetLastStatusUpdateAt(time.Now().UTC().Unix()) two.SetRunningBuildIDs([]string{"12345"}) - two.SetLastBuildStartedAt(time.Time{}.UTC().Unix()) - two.SetLastBuildFinishedAt(time.Time{}.UTC().Unix()) - two.SetLastCheckedIn(time.Time{}.UTC().Unix()) + two.SetLastBuildStartedAt(time.Now().UTC().Unix()) + two.SetLastBuildFinishedAt(time.Now().UTC().Unix()) + two.SetLastCheckedIn(time.Now().UTC().Unix()) two.SetBuildLimit(1) workers := []*library.Worker{one, two} From 23a9c597446481daab065548d64d03a2fec0f838 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Wed, 28 Jun 2023 13:30:07 -0500 Subject: [PATCH 10/64] chore: save work --- database/integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/integration_test.go b/database/integration_test.go index b952dbcdf..0c7326e7d 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -125,7 +125,7 @@ func testWorkers(t *testing.T, db Interface) { if err != nil { t.Errorf("unable to count workers: %v", err) } - if count != 2 { + if int(count) != len(workers) { t.Errorf("CountWorkers() is %v, want 2", count) } From 1dcb17bbb364730b6b773747645fa231a1f26bfe Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Wed, 28 Jun 2023 15:35:04 -0500 Subject: [PATCH 11/64] enhance(database): add method counter --- database/integration_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/database/integration_test.go b/database/integration_test.go index 0c7326e7d..2a8b44ab4 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -11,6 +11,8 @@ import ( "testing" "time" + "github.com/go-vela/server/database/worker" + "github.com/go-vela/types/library" ) @@ -82,6 +84,9 @@ func TestDatabase_Integration(t *testing.T) { } func testWorkers(t *testing.T, db Interface) { + // used to track the number of methods we call for workers + counter := 0 + one := new(library.Worker) one.SetID(1) one.SetHostname("worker-1.example.com") @@ -119,6 +124,7 @@ func testWorkers(t *testing.T, db Interface) { t.Errorf("unable to create worker %s: %v", worker.GetHostname(), err) } } + counter++ // count the workers count, err := db.CountWorkers() @@ -128,6 +134,7 @@ func testWorkers(t *testing.T, db Interface) { if int(count) != len(workers) { t.Errorf("CountWorkers() is %v, want 2", count) } + counter++ // list the workers list, err := db.ListWorkers() @@ -137,6 +144,7 @@ func testWorkers(t *testing.T, db Interface) { if !reflect.DeepEqual(list, workers) { t.Errorf("ListWorkers() is %v, want %v", list, workers) } + counter++ // lookup the workers by hostname for _, worker := range workers { @@ -148,6 +156,7 @@ func testWorkers(t *testing.T, db Interface) { t.Errorf("GetWorkerForHostname() is %v, want %v", got, worker) } } + counter++ // update the workers for _, worker := range workers { @@ -166,6 +175,8 @@ func testWorkers(t *testing.T, db Interface) { t.Errorf("GetWorker() is %v, want %v", got, worker) } } + counter++ + counter++ // delete the workers for _, worker := range workers { @@ -174,4 +185,11 @@ func testWorkers(t *testing.T, db Interface) { t.Errorf("unable to delete worker %s: %v", worker.GetHostname(), err) } } + counter++ + + // ensure we called all the functions we should have + methods := reflect.TypeOf(new(worker.WorkerInterface)).Elem().NumMethod() + if counter != methods { + t.Errorf("total number of methods called is %v, want %v", counter, methods) + } } From 77eb03eab1e6361f548b08066a84d87b89b92933 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Wed, 28 Jun 2023 15:41:55 -0500 Subject: [PATCH 12/64] fix(database): subtract 2 from methods --- database/integration_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/database/integration_test.go b/database/integration_test.go index 2a8b44ab4..474e045ad 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -188,7 +188,10 @@ func testWorkers(t *testing.T, db Interface) { counter++ // ensure we called all the functions we should have - methods := reflect.TypeOf(new(worker.WorkerInterface)).Elem().NumMethod() + // + // we subtract 2 for creating the table and indexes for workers + // since those are already called when the database engine starts + methods := reflect.TypeOf(new(worker.WorkerInterface)).Elem().NumMethod() - 2 if counter != methods { t.Errorf("total number of methods called is %v, want %v", counter, methods) } From ad25372f31ba2c5d503877f92156011b1c9325a6 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 09:12:38 -0500 Subject: [PATCH 13/64] enhance(database): add user integration tests --- database/integration_test.go | 127 ++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 1 deletion(-) diff --git a/database/integration_test.go b/database/integration_test.go index 474e045ad..76c1fa3e7 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -11,6 +11,8 @@ import ( "testing" "time" + "github.com/go-vela/server/database/user" + "github.com/go-vela/server/database/worker" "github.com/go-vela/types/library" @@ -71,6 +73,10 @@ func TestDatabase_Integration(t *testing.T) { t.Errorf("unable to ping database engine for %s: %v", test.name, err) } + t.Run("test_users", func(t *testing.T) { + testUsers(t, db) + }) + t.Run("test_workers", func(t *testing.T) { testWorkers(t, db) }) @@ -83,6 +89,125 @@ func TestDatabase_Integration(t *testing.T) { } } +func testUsers(t *testing.T, db Interface) { + // used to track the number of methods we call for users + counter := 0 + + one := new(library.User) + one.SetID(1) + one.SetName("octocat") + one.SetToken("superSecretToken") + one.SetRefreshToken("superSecretRefreshToken") + one.SetHash("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy") + one.SetFavorites([]string{"github/octocat"}) + one.SetActive(true) + one.SetAdmin(false) + + two := new(library.User) + two.SetID(2) + two.SetName("octocat") + two.SetToken("superSecretToken") + two.SetRefreshToken("superSecretRefreshToken") + two.SetHash("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy") + two.SetFavorites([]string{"github/octocat"}) + two.SetActive(true) + two.SetAdmin(false) + + users := []*library.User{one, two} + + // create the users + for _, user := range users { + err := db.CreateUser(user) + if err != nil { + t.Errorf("unable to create user %s: %v", user.GetName(), err) + } + } + counter++ + + // count the users + count, err := db.CountUsers() + if err != nil { + t.Errorf("unable to count users: %v", err) + } + if int(count) != len(users) { + t.Errorf("CountUsers() is %v, want 2", count) + } + counter++ + + // list the users + list, err := db.ListUsers() + if err != nil { + t.Errorf("unable to list users: %v", err) + } + if !reflect.DeepEqual(list, users) { + t.Errorf("ListUsers() is %v, want %v", list, users) + } + counter++ + + // list the users + lite, count, err := db.ListLiteUsers(1, 10) + if err != nil { + t.Errorf("unable to list lite users: %v", err) + } + if !reflect.DeepEqual(lite, users) { + t.Errorf("ListLiteUsers() is %v, want %v", list, users) + } + if int(count) != len(users) { + t.Errorf("ListLiteUsers() is %v, want %v", count, len(users)) + } + counter++ + + // lookup the users by name + for _, user := range users { + got, err := db.GetUserForName(user.GetName()) + if err != nil { + t.Errorf("unable to get user %s by hostname: %v", user.GetName(), err) + } + if !reflect.DeepEqual(got, user) { + t.Errorf("GetUserForName() is %v, want %v", got, user) + } + } + counter++ + + // update the users + for _, user := range users { + user.SetActive(false) + err = db.UpdateUser(user) + if err != nil { + t.Errorf("unable to update user %s: %v", user.GetName(), err) + } + + // lookup the user by ID + got, err := db.GetUser(user.GetID()) + if err != nil { + t.Errorf("unable to get user %s by ID: %v", user.GetName(), err) + } + if !reflect.DeepEqual(got, user) { + t.Errorf("GetUser() is %v, want %v", got, user) + } + } + counter++ + counter++ + + // delete the users + for _, user := range users { + err = db.DeleteUser(user) + if err != nil { + t.Errorf("unable to delete user %s: %v", user.GetName(), err) + } + } + counter++ + + // ensure we called all the functions we should have + // + // we subtract 2 for creating the table and indexes for users + // since those are already called when the database engine starts + methods := reflect.TypeOf(new(user.UserInterface)).Elem().NumMethod() - 2 + if counter != methods { + t.Errorf("total number of methods called is %v, want %v", counter, methods) + } +} + func testWorkers(t *testing.T, db Interface) { // used to track the number of methods we call for workers counter := 0 @@ -132,7 +257,7 @@ func testWorkers(t *testing.T, db Interface) { t.Errorf("unable to count workers: %v", err) } if int(count) != len(workers) { - t.Errorf("CountWorkers() is %v, want 2", count) + t.Errorf("CountWorkers() is %v, want %v", count, len(workers)) } counter++ From b218eea68293593c62b3eb9c2ec4b5b06502508c Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 09:14:44 -0500 Subject: [PATCH 14/64] chore: address review feedback --- database/integration_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 76c1fa3e7..5023475cb 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -91,7 +91,10 @@ func TestDatabase_Integration(t *testing.T) { func testUsers(t *testing.T, db Interface) { // used to track the number of methods we call for users - counter := 0 + // + // we start at 2 for creating the table and indexes for users + // since those are already called when the database engine starts + counter := 2 one := new(library.User) one.SetID(1) @@ -199,10 +202,7 @@ func testUsers(t *testing.T, db Interface) { counter++ // ensure we called all the functions we should have - // - // we subtract 2 for creating the table and indexes for users - // since those are already called when the database engine starts - methods := reflect.TypeOf(new(user.UserInterface)).Elem().NumMethod() - 2 + methods := reflect.TypeOf(new(user.UserInterface)).Elem().NumMethod() if counter != methods { t.Errorf("total number of methods called is %v, want %v", counter, methods) } @@ -210,7 +210,10 @@ func testUsers(t *testing.T, db Interface) { func testWorkers(t *testing.T, db Interface) { // used to track the number of methods we call for workers - counter := 0 + // + // we start at 2 for creating the table and indexes for users + // since those are already called when the database engine starts + counter := 2 one := new(library.Worker) one.SetID(1) @@ -313,10 +316,7 @@ func testWorkers(t *testing.T, db Interface) { counter++ // ensure we called all the functions we should have - // - // we subtract 2 for creating the table and indexes for workers - // since those are already called when the database engine starts - methods := reflect.TypeOf(new(worker.WorkerInterface)).Elem().NumMethod() - 2 + methods := reflect.TypeOf(new(worker.WorkerInterface)).Elem().NumMethod() if counter != methods { t.Errorf("total number of methods called is %v, want %v", counter, methods) } From d99f960615e50674f28f8584797cdb6df04bf5eb Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 09:19:50 -0500 Subject: [PATCH 15/64] fix(database): names for users --- database/integration_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/database/integration_test.go b/database/integration_test.go index 5023475cb..e7fc167e5 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -20,6 +20,8 @@ import ( func TestDatabase_Integration(t *testing.T) { // check if we should skip the integration test + // + // https://konradreiche.com/blog/how-to-separate-integration-tests-in-go if os.Getenv("INTEGRATION") == "" { t.Skipf("skipping %s integration test due to environment variable constraint", t.Name()) } @@ -108,7 +110,7 @@ func testUsers(t *testing.T, db Interface) { two := new(library.User) two.SetID(2) - two.SetName("octocat") + two.SetName("octokitty") two.SetToken("superSecretToken") two.SetRefreshToken("superSecretRefreshToken") two.SetHash("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy") From 4a0601ae566fc2018e54e07a9fa45f953313bc71 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 09:53:08 -0500 Subject: [PATCH 16/64] enhance(database): add step integration tests --- database/integration_test.go | 213 ++++++++++++++++++++++++++++++++++- 1 file changed, 207 insertions(+), 6 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index e7fc167e5..5530c5fac 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -11,10 +11,11 @@ import ( "testing" "time" - "github.com/go-vela/server/database/user" + "github.com/go-vela/types/raw" + "github.com/go-vela/server/database/step" + "github.com/go-vela/server/database/user" "github.com/go-vela/server/database/worker" - "github.com/go-vela/types/library" ) @@ -51,6 +52,71 @@ func TestDatabase_Integration(t *testing.T) { // run tests for _, test := range tests { t.Run(test.name, func(t *testing.T) { + // create resources for testing + buildOne := new(library.Build) + buildOne.SetID(1) + buildOne.SetRepoID(1) + buildOne.SetPipelineID(1) + buildOne.SetNumber(1) + buildOne.SetParent(1) + buildOne.SetEvent("push") + buildOne.SetStatus("running") + buildOne.SetError("") + buildOne.SetEnqueued(1563474077) + buildOne.SetCreated(1563474076) + buildOne.SetStarted(1563474078) + buildOne.SetFinished(1563474079) + buildOne.SetDeploy("") + buildOne.SetDeployPayload(raw.StringSliceMap{"foo": "test1"}) + buildOne.SetClone("https://github.com/github/octocat.git") + buildOne.SetSource("https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135163") + buildOne.SetTitle("push received from https://github.com/github/octocat") + buildOne.SetMessage("First commit...") + buildOne.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") + buildOne.SetSender("OctoKitty") + buildOne.SetAuthor("OctoKitty") + buildOne.SetEmail("OctoKitty@github.com") + buildOne.SetLink("https://example.company.com/github/octocat/1") + buildOne.SetBranch("master") + buildOne.SetRef("refs/heads/master") + buildOne.SetBaseRef("") + buildOne.SetHeadRef("changes") + buildOne.SetHost("example.company.com") + buildOne.SetRuntime("docker") + buildOne.SetDistribution("linux") + + buildTwo := new(library.Build) + buildTwo.SetID(2) + buildTwo.SetRepoID(1) + buildTwo.SetPipelineID(1) + buildTwo.SetNumber(2) + buildTwo.SetParent(1) + buildTwo.SetEvent("pull_request") + buildTwo.SetStatus("running") + buildTwo.SetError("") + buildTwo.SetEnqueued(1563474077) + buildTwo.SetCreated(1563474076) + buildTwo.SetStarted(1563474078) + buildTwo.SetFinished(1563474079) + buildTwo.SetDeploy("") + buildTwo.SetDeployPayload(raw.StringSliceMap{"foo": "test1"}) + buildTwo.SetClone("https://github.com/github/octocat.git") + buildTwo.SetSource("https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135164") + buildTwo.SetTitle("pull_request received from https://github.com/github/octocat") + buildTwo.SetMessage("Second commit...") + buildTwo.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135164") + buildTwo.SetSender("OctoKitty") + buildTwo.SetAuthor("OctoKitty") + buildTwo.SetEmail("OctoKitty@github.com") + buildTwo.SetLink("https://example.company.com/github/octocat/2") + buildTwo.SetBranch("master") + buildTwo.SetRef("refs/heads/master") + buildTwo.SetBaseRef("") + buildTwo.SetHeadRef("changes") + buildTwo.SetHost("example.company.com") + buildTwo.SetRuntime("docker") + buildTwo.SetDistribution("linux") + db, err := New( WithAddress(test.config.Address), WithCompressionLevel(test.config.CompressionLevel), @@ -75,6 +141,10 @@ func TestDatabase_Integration(t *testing.T) { t.Errorf("unable to ping database engine for %s: %v", test.name, err) } + t.Run("test_steps", func(t *testing.T) { + testSteps(t, db, []*library.Build{buildOne, buildTwo}) + }) + t.Run("test_users", func(t *testing.T) { testUsers(t, db) }) @@ -91,6 +161,137 @@ func TestDatabase_Integration(t *testing.T) { } } +func testSteps(t *testing.T, db Interface, builds []*library.Build) { + // used to track the number of methods we call for steps + // + // we start at 2 for creating the table and indexes for steps + // since those are already called when the database engine starts + counter := 2 + + one := new(library.Step) + one.SetID(1) + one.SetBuildID(1) + one.SetRepoID(1) + one.SetNumber(1) + one.SetName("init") + one.SetImage("#init") + one.SetStatus("running") + one.SetExitCode(0) + one.SetCreated(1563474076) + one.SetStarted(1563474078) + one.SetFinished(1563474079) + one.SetHost("example.company.com") + one.SetRuntime("docker") + one.SetDistribution("linux") + + two := new(library.Step) + two.SetID(2) + two.SetBuildID(1) + two.SetRepoID(1) + two.SetNumber(2) + two.SetName("clone") + two.SetImage("target/vela-git:v0.3.0") + two.SetStatus("pending") + two.SetExitCode(0) + two.SetCreated(1563474077) + two.SetStarted(0) + two.SetFinished(0) + two.SetHost("example.company.com") + two.SetRuntime("docker") + two.SetDistribution("linux") + + steps := []*library.Step{one, two} + + // create the steps + for _, step := range steps { + err := db.CreateStep(step) + if err != nil { + t.Errorf("unable to create step %s: %v", step.GetName(), err) + } + } + counter++ + + // count the steps + count, err := db.CountSteps() + if err != nil { + t.Errorf("unable to count steps: %v", err) + } + if int(count) != len(steps) { + t.Errorf("CountSteps() is %v, want 2", count) + } + counter++ + + // list the steps + list, err := db.ListSteps() + if err != nil { + t.Errorf("unable to list steps: %v", err) + } + if !reflect.DeepEqual(list, steps) { + t.Errorf("ListSteps() is %v, want %v", list, steps) + } + counter++ + + // list the steps for a build + list, count, err = db.ListStepsForBuild(builds[0], nil, 1, 10) + if err != nil { + t.Errorf("unable to list steps for build: %v", err) + } + if !reflect.DeepEqual(list, steps) { + t.Errorf("ListStepsForBuild() is %v, want %v", list, steps) + } + if int(count) != len(steps) { + t.Errorf("ListStepsForBuild() is %v, want %v", count, len(steps)) + } + counter++ + + // lookup the steps by name + for _, step := range steps { + got, err := db.GetStepForBuild(builds[0], step.GetNumber()) + if err != nil { + t.Errorf("unable to get step %s for build %d: %v", builds[0].GetID(), err) + } + if !reflect.DeepEqual(got, step) { + t.Errorf("GetStepForBuild() is %v, want %v", got, step) + } + } + counter++ + + // update the steps + for _, step := range steps { + step.SetStatus("success") + err = db.UpdateStep(step) + if err != nil { + t.Errorf("unable to update step %s: %v", step.GetName(), err) + } + + // lookup the step by ID + got, err := db.GetStep(step.GetID()) + if err != nil { + t.Errorf("unable to get step %s by ID: %v", step.GetName(), err) + } + if !reflect.DeepEqual(got, step) { + t.Errorf("GetStep() is %v, want %v", got, step) + } + } + counter++ + counter++ + + // delete the steps + for _, step := range steps { + err = db.DeleteStep(step) + if err != nil { + t.Errorf("unable to delete step %s: %v", step.GetName(), err) + } + } + counter++ + + // ensure we called all the functions we should have + methods := reflect.TypeOf(new(step.StepInterface)).Elem().NumMethod() + if counter != methods { + t.Errorf("total number of methods called is %v, want %v", counter, methods) + } +} + func testUsers(t *testing.T, db Interface) { // used to track the number of methods we call for users // @@ -149,12 +350,12 @@ func testUsers(t *testing.T, db Interface) { } counter++ - // list the users - lite, count, err := db.ListLiteUsers(1, 10) + // lite list the users + list, count, err = db.ListLiteUsers(1, 10) if err != nil { t.Errorf("unable to list lite users: %v", err) } - if !reflect.DeepEqual(lite, users) { + if !reflect.DeepEqual(list, users) { t.Errorf("ListLiteUsers() is %v, want %v", list, users) } if int(count) != len(users) { @@ -166,7 +367,7 @@ func testUsers(t *testing.T, db Interface) { for _, user := range users { got, err := db.GetUserForName(user.GetName()) if err != nil { - t.Errorf("unable to get user %s by hostname: %v", user.GetName(), err) + t.Errorf("unable to get user %s by name: %v", user.GetName(), err) } if !reflect.DeepEqual(got, user) { t.Errorf("GetUserForName() is %v, want %v", got, user) From 541d2e34073635d170c29e3a86574114847f8c4e Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 09:59:50 -0500 Subject: [PATCH 17/64] fix: typo --- database/integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/integration_test.go b/database/integration_test.go index 5530c5fac..8800942ce 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -248,7 +248,7 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { for _, step := range steps { got, err := db.GetStepForBuild(builds[0], step.GetNumber()) if err != nil { - t.Errorf("unable to get step %s for build %d: %v", builds[0].GetID(), err) + t.Errorf("unable to get step %s for build %d: %v", step.GetName(), builds[0].GetID(), err) } if !reflect.DeepEqual(got, step) { t.Errorf("GetStepForBuild() is %v, want %v", got, step) From 43cc0628dbb3a0b1eb0dfed1933fedc2f2a01f26 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 10:23:09 -0500 Subject: [PATCH 18/64] test: output diff --- database/integration_test.go | 17 +++++++++++++---- go.mod | 2 ++ go.sum | 6 +++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 8800942ce..45e53f1ff 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -11,6 +11,8 @@ import ( "testing" "time" + "github.com/kr/pretty" + "github.com/go-vela/types/raw" "github.com/go-vela/server/database/step" @@ -193,9 +195,9 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { two.SetImage("target/vela-git:v0.3.0") two.SetStatus("pending") two.SetExitCode(0) - two.SetCreated(1563474077) - two.SetStarted(0) - two.SetFinished(0) + two.SetCreated(1563474086) + two.SetStarted(1563474088) + two.SetFinished(1563474089) two.SetHost("example.company.com") two.SetRuntime("docker") two.SetDistribution("linux") @@ -227,6 +229,7 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { t.Errorf("unable to list steps: %v", err) } if !reflect.DeepEqual(list, steps) { + pretty.Ldiff(t, list, steps) t.Errorf("ListSteps() is %v, want %v", list, steps) } counter++ @@ -237,6 +240,7 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { t.Errorf("unable to list steps for build: %v", err) } if !reflect.DeepEqual(list, steps) { + pretty.Ldiff(t, list, steps) t.Errorf("ListStepsForBuild() is %v, want %v", list, steps) } if int(count) != len(steps) { @@ -251,6 +255,7 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { t.Errorf("unable to get step %s for build %d: %v", step.GetName(), builds[0].GetID(), err) } if !reflect.DeepEqual(got, step) { + pretty.Ldiff(t, got, step) t.Errorf("GetStepForBuild() is %v, want %v", got, step) } } @@ -270,6 +275,7 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { t.Errorf("unable to get step %s by ID: %v", step.GetName(), err) } if !reflect.DeepEqual(got, step) { + pretty.Ldiff(t, got, step) t.Errorf("GetStep() is %v, want %v", got, step) } } @@ -355,7 +361,10 @@ func testUsers(t *testing.T, db Interface) { if err != nil { t.Errorf("unable to list lite users: %v", err) } - if !reflect.DeepEqual(list, users) { + if !reflect.DeepEqual(list, []*library.User{ + {ID: users[0].ID, Name: users[0].Name}, + {ID: users[1].ID, Name: users[1].Name}, + }) { t.Errorf("ListLiteUsers() is %v, want %v", list, users) } if int(count) != len(users) { diff --git a/go.mod b/go.mod index dea6f6204..2b381dd22 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require ( github.com/hashicorp/go-retryablehttp v0.7.4 github.com/hashicorp/vault/api v1.9.2 github.com/joho/godotenv v1.5.1 + github.com/kr/pretty v0.3.1 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.16.0 github.com/redis/go-redis/v9 v9.0.5 @@ -88,6 +89,7 @@ require ( github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect + github.com/kr/text v0.2.0 // indirect github.com/leodido/go-urn v1.2.4 // indirect github.com/lib/pq v1.10.9 // indirect github.com/mattn/go-colorable v0.1.8 // indirect diff --git a/go.sum b/go.sum index 2465b7cca..0f13f201a 100644 --- a/go.sum +++ b/go.sum @@ -101,6 +101,7 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -288,9 +289,11 @@ github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8t github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= @@ -329,6 +332,7 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= From cd8f56e6c7f1c31dfd5b8197b02210bc9838f164 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 10:39:27 -0500 Subject: [PATCH 19/64] chore: minor fixes --- database/integration_test.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 45e53f1ff..27bb39d7f 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -177,6 +177,7 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { one.SetNumber(1) one.SetName("init") one.SetImage("#init") + one.SetStage("init") one.SetStatus("running") one.SetExitCode(0) one.SetCreated(1563474076) @@ -193,6 +194,7 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { two.SetNumber(2) two.SetName("clone") two.SetImage("target/vela-git:v0.3.0") + two.SetStage("init") two.SetStatus("pending") two.SetExitCode(0) two.SetCreated(1563474086) @@ -325,6 +327,10 @@ func testUsers(t *testing.T, db Interface) { two.SetActive(true) two.SetAdmin(false) + liteUsers := []*library.User{ + {ID: one.ID, Name: one.Name}, + {ID: two.ID, Name: two.Name}, + } users := []*library.User{one, two} // create the users @@ -361,11 +367,9 @@ func testUsers(t *testing.T, db Interface) { if err != nil { t.Errorf("unable to list lite users: %v", err) } - if !reflect.DeepEqual(list, []*library.User{ - {ID: users[0].ID, Name: users[0].Name}, - {ID: users[1].ID, Name: users[1].Name}, - }) { - t.Errorf("ListLiteUsers() is %v, want %v", list, users) + if !reflect.DeepEqual(list, liteUsers) { + pretty.Ldiff(t, list, liteUsers) + t.Errorf("ListLiteUsers() is %v, want %v", list, liteUsers) } if int(count) != len(users) { t.Errorf("ListLiteUsers() is %v, want %v", count, len(users)) From 111916c25711a6762f624597f0308410e994b457 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 10:46:44 -0500 Subject: [PATCH 20/64] fix(database): users --- database/integration_test.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 27bb39d7f..ee7709e15 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -179,6 +179,7 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { one.SetImage("#init") one.SetStage("init") one.SetStatus("running") + one.SetError("") one.SetExitCode(0) one.SetCreated(1563474076) one.SetStarted(1563474078) @@ -196,6 +197,7 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { two.SetImage("target/vela-git:v0.3.0") two.SetStage("init") two.SetStatus("pending") + two.SetError("") two.SetExitCode(0) two.SetCreated(1563474086) two.SetStarted(1563474088) @@ -327,12 +329,30 @@ func testUsers(t *testing.T, db Interface) { two.SetActive(true) two.SetAdmin(false) - liteUsers := []*library.User{ - {ID: one.ID, Name: one.Name}, - {ID: two.ID, Name: two.Name}, - } users := []*library.User{one, two} + liteOne := new(library.User) + liteOne.SetID(1) + liteOne.SetName("octocat") + liteOne.SetToken("") + liteOne.SetRefreshToken("") + liteOne.SetHash("") + liteOne.SetFavorites([]string{}) + liteOne.SetActive(false) + liteOne.SetAdmin(false) + + liteTwo := new(library.User) + liteTwo.SetID(2) + liteTwo.SetName("octokitty") + liteTwo.SetToken("") + liteTwo.SetRefreshToken("") + liteTwo.SetHash("") + liteTwo.SetFavorites([]string{}) + liteTwo.SetActive(false) + liteTwo.SetAdmin(false) + + liteUsers := []*library.User{liteOne, liteTwo} + // create the users for _, user := range users { err := db.CreateUser(user) @@ -368,7 +388,6 @@ func testUsers(t *testing.T, db Interface) { t.Errorf("unable to list lite users: %v", err) } if !reflect.DeepEqual(list, liteUsers) { - pretty.Ldiff(t, list, liteUsers) t.Errorf("ListLiteUsers() is %v, want %v", list, liteUsers) } if int(count) != len(users) { From a6d0dcca804f755dd2a92e04f22d56019b8eb9a5 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 11:02:41 -0500 Subject: [PATCH 21/64] fix(database): steps --- database/integration_test.go | 39 +++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index ee7709e15..f6f7df4d7 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -227,6 +227,16 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { } counter++ + // count the steps for a build + count, err = db.CountStepsForBuild(builds[0], nil) + if err != nil { + t.Errorf("unable to count steps for build %d: %v", builds[0].GetID(), err) + } + if int(count) != len(steps) { + t.Errorf("CountStepsForBuild() is %v, want %v", count, len(steps)) + } + counter++ + // list the steps list, err := db.ListSteps() if err != nil { @@ -241,17 +251,35 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { // list the steps for a build list, count, err = db.ListStepsForBuild(builds[0], nil, 1, 10) if err != nil { - t.Errorf("unable to list steps for build: %v", err) + t.Errorf("unable to list steps for build %d: %v", builds[0].GetID(), err) } - if !reflect.DeepEqual(list, steps) { + if !reflect.DeepEqual(list, []*library.Step{two, one}) { pretty.Ldiff(t, list, steps) - t.Errorf("ListStepsForBuild() is %v, want %v", list, steps) + t.Errorf("ListStepsForBuild() is %v, want %v", list, []*library.Step{two, one}) } if int(count) != len(steps) { t.Errorf("ListStepsForBuild() is %v, want %v", count, len(steps)) } counter++ + images, err := db.ListStepImageCount() + if err != nil { + t.Errorf("unable to list step image count: %v",, err) + } + if len(images) != len(steps) { + t.Errorf("ListStepImageCount() is %v, want %v", len(images), len(steps)) + } + counter++ + + statuses, err := db.ListStepStatusCount() + if err != nil { + t.Errorf("unable to list step status count: %v", err) + } + if len(statuses) != len(steps) { + t.Errorf("ListStepStatusCount() is %v, want %v", len(images), len(steps)) + } + counter++ + // lookup the steps by name for _, step := range steps { got, err := db.GetStepForBuild(builds[0], step.GetNumber()) @@ -368,7 +396,7 @@ func testUsers(t *testing.T, db Interface) { t.Errorf("unable to count users: %v", err) } if int(count) != len(users) { - t.Errorf("CountUsers() is %v, want 2", count) + t.Errorf("CountUsers() is %v, want %v", count, len(users)) } counter++ @@ -388,6 +416,7 @@ func testUsers(t *testing.T, db Interface) { t.Errorf("unable to list lite users: %v", err) } if !reflect.DeepEqual(list, liteUsers) { + pretty.Ldiff(t, list, liteUsers) t.Errorf("ListLiteUsers() is %v, want %v", list, liteUsers) } if int(count) != len(users) { @@ -555,4 +584,4 @@ func testWorkers(t *testing.T, db Interface) { if counter != methods { t.Errorf("total number of methods called is %v, want %v", counter, methods) } -} +} \ No newline at end of file From c1f92cce9edd0f02c3b807a7f05add6429255f46 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 11:05:09 -0500 Subject: [PATCH 22/64] fix: typo --- database/integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index f6f7df4d7..5ee54e016 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -264,7 +264,7 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { images, err := db.ListStepImageCount() if err != nil { - t.Errorf("unable to list step image count: %v",, err) + t.Errorf("unable to list step image count: %v", err) } if len(images) != len(steps) { t.Errorf("ListStepImageCount() is %v, want %v", len(images), len(steps)) @@ -584,4 +584,4 @@ func testWorkers(t *testing.T, db Interface) { if counter != methods { t.Errorf("total number of methods called is %v, want %v", counter, methods) } -} \ No newline at end of file +} From 3a4ef4d70ed6e9970088169c7cf7afeba940736b Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 11:12:21 -0500 Subject: [PATCH 23/64] fix(database): steps --- database/integration_test.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 5ee54e016..f450c0bd1 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -262,21 +262,34 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { } counter++ + expected := map[string]float64{ + "#init": 1, + "target/vela-git:v0.3.0": 1, + } images, err := db.ListStepImageCount() if err != nil { t.Errorf("unable to list step image count: %v", err) } - if len(images) != len(steps) { - t.Errorf("ListStepImageCount() is %v, want %v", len(images), len(steps)) + if !reflect.DeepEqual(images, expected) { + pretty.Ldiff(t, images, expected) + t.Errorf("ListStepImageCount() is %v, want %v", images, expected) } counter++ + expected = map[string]float64{ + "pending": 1, + "failure": 0, + "killed": 0, + "running": 1, + "success": 0, + } statuses, err := db.ListStepStatusCount() if err != nil { t.Errorf("unable to list step status count: %v", err) } - if len(statuses) != len(steps) { - t.Errorf("ListStepStatusCount() is %v, want %v", len(images), len(steps)) + if !reflect.DeepEqual(statuses, expected) { + pretty.Ldiff(t, statuses, expected) + t.Errorf("ListStepStatusCount() is %v, want %v", statuses, expected) } counter++ From 6384b5ea714d6750060104f916dce1827b038160 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 11:19:48 -0500 Subject: [PATCH 24/64] feat(database): add services --- database/integration_test.go | 184 +++++++++++++++++++++++++++++++++-- 1 file changed, 178 insertions(+), 6 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index f450c0bd1..cbcd815f2 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -11,6 +11,8 @@ import ( "testing" "time" + "github.com/go-vela/server/database/service" + "github.com/kr/pretty" "github.com/go-vela/types/raw" @@ -143,6 +145,10 @@ func TestDatabase_Integration(t *testing.T) { t.Errorf("unable to ping database engine for %s: %v", test.name, err) } + t.Run("test_services", func(t *testing.T) { + testServices(t, db, []*library.Build{buildOne, buildTwo}) + }) + t.Run("test_steps", func(t *testing.T) { testSteps(t, db, []*library.Build{buildOne, buildTwo}) }) @@ -163,6 +169,178 @@ func TestDatabase_Integration(t *testing.T) { } } +func testServices(t *testing.T, db Interface, builds []*library.Build) { + // used to track the number of methods we call for services + // + // we start at 2 for creating the table and indexes for services + // since those are already called when the database engine starts + counter := 2 + + one := new(library.Service) + one.SetID(1) + one.SetBuildID(1) + one.SetRepoID(1) + one.SetNumber(1) + one.SetName("init") + one.SetImage("#init") + one.SetStatus("running") + one.SetError("") + one.SetExitCode(0) + one.SetCreated(1563474076) + one.SetStarted(1563474078) + one.SetFinished(1563474079) + one.SetHost("example.company.com") + one.SetRuntime("docker") + one.SetDistribution("linux") + + two := new(library.Service) + two.SetID(2) + two.SetBuildID(1) + two.SetRepoID(1) + two.SetNumber(2) + two.SetName("clone") + two.SetImage("target/vela-git:v0.3.0") + two.SetStatus("pending") + two.SetError("") + two.SetExitCode(0) + two.SetCreated(1563474086) + two.SetStarted(1563474088) + two.SetFinished(1563474089) + two.SetHost("example.company.com") + two.SetRuntime("docker") + two.SetDistribution("linux") + + services := []*library.Service{one, two} + + // create the services + for _, service := range services { + err := db.CreateService(service) + if err != nil { + t.Errorf("unable to create service %s: %v", service.GetName(), err) + } + } + counter++ + + // count the services + count, err := db.CountServices() + if err != nil { + t.Errorf("unable to count services: %v", err) + } + if int(count) != len(services) { + t.Errorf("CountServices() is %v, want 2", count) + } + counter++ + + // count the services for a build + count, err = db.CountServicesForBuild(builds[0], nil) + if err != nil { + t.Errorf("unable to count services for build %d: %v", builds[0].GetID(), err) + } + if int(count) != len(services) { + t.Errorf("CountServicesForBuild() is %v, want %v", count, len(services)) + } + counter++ + + // list the services + list, err := db.ListServices() + if err != nil { + t.Errorf("unable to list services: %v", err) + } + if !reflect.DeepEqual(list, services) { + t.Errorf("ListServices() is %v, want %v", list, services) + } + counter++ + + // list the services for a build + list, count, err = db.ListServicesForBuild(builds[0], nil, 1, 10) + if err != nil { + t.Errorf("unable to list services for build %d: %v", builds[0].GetID(), err) + } + if !reflect.DeepEqual(list, []*library.Service{two, one}) { + t.Errorf("ListServicesForBuild() is %v, want %v", list, []*library.Service{two, one}) + } + if int(count) != len(services) { + t.Errorf("ListServicesForBuild() is %v, want %v", count, len(services)) + } + counter++ + + expected := map[string]float64{ + "#init": 1, + "target/vela-git:v0.3.0": 1, + } + images, err := db.ListServiceImageCount() + if err != nil { + t.Errorf("unable to list service image count: %v", err) + } + if !reflect.DeepEqual(images, expected) { + t.Errorf("ListServiceImageCount() is %v, want %v", images, expected) + } + counter++ + + expected = map[string]float64{ + "pending": 1, + "failure": 0, + "killed": 0, + "running": 1, + "success": 0, + } + statuses, err := db.ListServiceStatusCount() + if err != nil { + t.Errorf("unable to list service status count: %v", err) + } + if !reflect.DeepEqual(statuses, expected) { + t.Errorf("ListServiceStatusCount() is %v, want %v", statuses, expected) + } + counter++ + + // lookup the services by name + for _, service := range services { + got, err := db.GetServiceForBuild(builds[0], service.GetNumber()) + if err != nil { + t.Errorf("unable to get service %s for build %d: %v", service.GetName(), builds[0].GetID(), err) + } + if !reflect.DeepEqual(got, service) { + t.Errorf("GetServiceForBuild() is %v, want %v", got, service) + } + } + counter++ + + // update the services + for _, service := range services { + service.SetStatus("success") + err = db.UpdateService(service) + if err != nil { + t.Errorf("unable to update service %s: %v", service.GetName(), err) + } + + // lookup the service by ID + got, err := db.GetService(service.GetID()) + if err != nil { + t.Errorf("unable to get service %s by ID: %v", service.GetName(), err) + } + if !reflect.DeepEqual(got, service) { + t.Errorf("GetService() is %v, want %v", got, service) + } + } + counter++ + counter++ + + // delete the services + for _, service := range services { + err = db.DeleteService(service) + if err != nil { + t.Errorf("unable to delete service %s: %v", service.GetName(), err) + } + } + counter++ + + // ensure we called all the functions we should have + methods := reflect.TypeOf(new(service.ServiceInterface)).Elem().NumMethod() + if counter != methods { + t.Errorf("total number of methods called is %v, want %v", counter, methods) + } +} + func testSteps(t *testing.T, db Interface, builds []*library.Build) { // used to track the number of methods we call for steps // @@ -243,7 +421,6 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { t.Errorf("unable to list steps: %v", err) } if !reflect.DeepEqual(list, steps) { - pretty.Ldiff(t, list, steps) t.Errorf("ListSteps() is %v, want %v", list, steps) } counter++ @@ -254,7 +431,6 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { t.Errorf("unable to list steps for build %d: %v", builds[0].GetID(), err) } if !reflect.DeepEqual(list, []*library.Step{two, one}) { - pretty.Ldiff(t, list, steps) t.Errorf("ListStepsForBuild() is %v, want %v", list, []*library.Step{two, one}) } if int(count) != len(steps) { @@ -271,7 +447,6 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { t.Errorf("unable to list step image count: %v", err) } if !reflect.DeepEqual(images, expected) { - pretty.Ldiff(t, images, expected) t.Errorf("ListStepImageCount() is %v, want %v", images, expected) } counter++ @@ -288,7 +463,6 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { t.Errorf("unable to list step status count: %v", err) } if !reflect.DeepEqual(statuses, expected) { - pretty.Ldiff(t, statuses, expected) t.Errorf("ListStepStatusCount() is %v, want %v", statuses, expected) } counter++ @@ -300,7 +474,6 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { t.Errorf("unable to get step %s for build %d: %v", step.GetName(), builds[0].GetID(), err) } if !reflect.DeepEqual(got, step) { - pretty.Ldiff(t, got, step) t.Errorf("GetStepForBuild() is %v, want %v", got, step) } } @@ -320,7 +493,6 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { t.Errorf("unable to get step %s by ID: %v", step.GetName(), err) } if !reflect.DeepEqual(got, step) { - pretty.Ldiff(t, got, step) t.Errorf("GetStep() is %v, want %v", got, step) } } From c34dcb3ad21a1e92ef4111e1d34cfb1bd3fdf268 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 11:35:13 -0500 Subject: [PATCH 25/64] feat(database): add builds --- database/integration_test.go | 153 +++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/database/integration_test.go b/database/integration_test.go index cbcd815f2..66ec71f1f 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -11,6 +11,10 @@ import ( "testing" "time" + "github.com/go-vela/server/database/build" + + "github.com/google/go-cmp/cmp" + "github.com/go-vela/server/database/service" "github.com/kr/pretty" @@ -121,6 +125,54 @@ func TestDatabase_Integration(t *testing.T) { buildTwo.SetRuntime("docker") buildTwo.SetDistribution("linux") + repoOne := new(library.Repo) + repoOne.SetID(1) + repoOne.SetOrg("github") + repoOne.SetName("octocat") + repoOne.SetFullName("github/octocat") + repoOne.SetLink("https://github.com/github/octocat") + repoOne.SetClone("https://github.com/github/octocat.git") + repoOne.SetBranch("main") + repoOne.SetTopics([]string{"cloud", "security"}) + repoOne.SetBuildLimit(10) + repoOne.SetTimeout(30) + repoOne.SetCounter(0) + repoOne.SetVisibility("public") + repoOne.SetPrivate(false) + repoOne.SetTrusted(false) + repoOne.SetActive(true) + repoOne.SetAllowPull(false) + repoOne.SetAllowPush(true) + repoOne.SetAllowDeploy(false) + repoOne.SetAllowTag(false) + repoOne.SetAllowComment(false) + repoOne.SetPipelineType("") + repoOne.SetPreviousName("") + + repoTwo := new(library.Repo) + repoTwo.SetID(2) + repoTwo.SetOrg("github") + repoTwo.SetName("octokitty") + repoTwo.SetFullName("github/octokitty") + repoTwo.SetLink("https://github.com/github/octokitty") + repoTwo.SetClone("https://github.com/github/octokitty.git") + repoTwo.SetBranch("master") + repoTwo.SetTopics([]string{"cloud", "security"}) + repoTwo.SetBuildLimit(10) + repoTwo.SetTimeout(30) + repoTwo.SetCounter(0) + repoTwo.SetVisibility("public") + repoTwo.SetPrivate(false) + repoTwo.SetTrusted(false) + repoTwo.SetActive(true) + repoTwo.SetAllowPull(false) + repoTwo.SetAllowPush(true) + repoTwo.SetAllowDeploy(false) + repoTwo.SetAllowTag(false) + repoTwo.SetAllowComment(false) + repoTwo.SetPipelineType("") + repoTwo.SetPreviousName("") + db, err := New( WithAddress(test.config.Address), WithCompressionLevel(test.config.CompressionLevel), @@ -145,6 +197,10 @@ func TestDatabase_Integration(t *testing.T) { t.Errorf("unable to ping database engine for %s: %v", test.name, err) } + t.Run("test_build", func(t *testing.T) { + testBuilds(t, db, []*library.Build{buildOne, buildTwo}, []*library.Repo{repoOne, repoTwo}) + }) + t.Run("test_services", func(t *testing.T) { testServices(t, db, []*library.Build{buildOne, buildTwo}) }) @@ -169,6 +225,100 @@ func TestDatabase_Integration(t *testing.T) { } } +func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*library.Repo) { + // used to track the number of methods we call for builds + // + // we start at 2 for creating the table and indexes for builds + // since those are already called when the database engine starts + counter := 2 + + // create the builds + for _, build := range builds { + _, err := db.CreateBuild(build) + if err != nil { + t.Errorf("unable to create build %d: %v", build.GetID(), err) + } + } + counter++ + + // count the builds + count, err := db.CountBuilds() + if err != nil { + t.Errorf("unable to count builds: %v", err) + } + if int(count) != len(builds) { + t.Errorf("CountBuilds() is %v, want 2", count) + } + counter++ + + // list the builds + list, err := db.ListBuilds() + if err != nil { + t.Errorf("unable to list builds: %v", err) + } + if !reflect.DeepEqual(list, builds) { + t.Errorf("ListBuilds() is %v, want %v", list, builds) + } + counter++ + + // lookup the last build by repo + got, err := db.LastBuildForRepo(repos[0], "main") + if err != nil { + t.Errorf("unable to get last build for repo %s: %v", repos[0].GetFullName(), err) + } + if !reflect.DeepEqual(got, builds[1]) { + t.Errorf("GetBuildForRepo() is %v, want %v", got, builds[1]) + } + counter++ + + // lookup the builds by repo and number + for _, build := range builds { + got, err = db.GetBuildForRepo(repos[0], build.GetNumber()) + if err != nil { + t.Errorf("unable to get build %d for repo %s: %v", build.GetID(), repos[0].GetFullName(), err) + } + if !reflect.DeepEqual(got, build) { + t.Errorf("GetBuildForRepo() is %v, want %v", got, build) + } + } + counter++ + + // update the builds + for _, build := range builds { + build.SetStatus("success") + _, err = db.UpdateBuild(build) + if err != nil { + t.Errorf("unable to update build %d: %v", build.GetID(), err) + } + + // lookup the build by ID + got, err = db.GetBuild(build.GetID()) + if err != nil { + t.Errorf("unable to get build %d by ID: %v", build.GetID(), err) + } + if !reflect.DeepEqual(got, build) { + t.Errorf("GetBuild() is %v, want %v", got, build) + } + } + counter++ + counter++ + + // delete the builds + for _, build := range builds { + err = db.DeleteBuild(build) + if err != nil { + t.Errorf("unable to delete build %d: %v", build.GetID(), err) + } + } + counter++ + + // ensure we called all the functions we should have + methods := reflect.TypeOf(new(build.BuildInterface)).Elem().NumMethod() + if counter != methods { + t.Errorf("total number of methods called is %v, want %v", counter, methods) + } +} + func testServices(t *testing.T, db Interface, builds []*library.Build) { // used to track the number of methods we call for services // @@ -602,6 +752,9 @@ func testUsers(t *testing.T, db Interface) { } if !reflect.DeepEqual(list, liteUsers) { pretty.Ldiff(t, list, liteUsers) + if diff := cmp.Diff(list, liteUsers); diff != "" { + t.Errorf("ListLiteUsers() mismatch (-want +got):\n%s", diff) + } t.Errorf("ListLiteUsers() is %v, want %v", list, liteUsers) } if int(count) != len(users) { From d6912ca3aa56969980922b1ce636ecead8928cb8 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 11:37:51 -0500 Subject: [PATCH 26/64] fix(database): users --- database/integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 66ec71f1f..12e4a1cca 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -700,7 +700,7 @@ func testUsers(t *testing.T, db Interface) { liteOne.SetToken("") liteOne.SetRefreshToken("") liteOne.SetHash("") - liteOne.SetFavorites([]string{}) + liteOne.SetFavorites(nil) liteOne.SetActive(false) liteOne.SetAdmin(false) @@ -710,7 +710,7 @@ func testUsers(t *testing.T, db Interface) { liteTwo.SetToken("") liteTwo.SetRefreshToken("") liteTwo.SetHash("") - liteTwo.SetFavorites([]string{}) + liteTwo.SetFavorites(nil) liteTwo.SetActive(false) liteTwo.SetAdmin(false) From 18a68fee43a05c6dc9ccb09ace7548ceb1ee2f2a Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 12:38:57 -0500 Subject: [PATCH 27/64] fix(database): integration tests --- database/integration_test.go | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 12e4a1cca..c7107380f 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -247,7 +247,17 @@ func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*li t.Errorf("unable to count builds: %v", err) } if int(count) != len(builds) { - t.Errorf("CountBuilds() is %v, want 2", count) + t.Errorf("CountBuilds() is %v, want %v", count, len(builds)) + } + counter++ + + // count the builds for a repo + count, err = db.CountBuildsForRepo(repos[0], nil) + if err != nil { + t.Errorf("unable to count builds for repo %s: %v", repos[0].GetFullName(), err) + } + if int(count) != len(builds) { + t.Errorf("CountBuildsForRepo() is %v, want %v", count, len(builds)) } counter++ @@ -257,10 +267,22 @@ func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*li t.Errorf("unable to list builds: %v", err) } if !reflect.DeepEqual(list, builds) { + pretty.Ldiff(t, list, builds) t.Errorf("ListBuilds() is %v, want %v", list, builds) } counter++ + // list the builds for a repo + list, count, err = db.ListBuildsForRepo(repos[0], nil, time.Now().UTC().Unix(), 0, 1, 10) + if err != nil { + t.Errorf("unable to list builds for repo %s: %v", repos[0].GetFullName(), err) + } + if !reflect.DeepEqual(list, builds) { + pretty.Ldiff(t, list, builds) + t.Errorf("ListBuildsForRepo() is %v, want %v", list, builds) + } + counter++ + // lookup the last build by repo got, err := db.LastBuildForRepo(repos[0], "main") if err != nil { @@ -377,7 +399,7 @@ func testServices(t *testing.T, db Interface, builds []*library.Build) { t.Errorf("unable to count services: %v", err) } if int(count) != len(services) { - t.Errorf("CountServices() is %v, want 2", count) + t.Errorf("CountServices() is %v, want %v", count, len(services)) } counter++ @@ -551,7 +573,7 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { t.Errorf("unable to count steps: %v", err) } if int(count) != len(steps) { - t.Errorf("CountSteps() is %v, want 2", count) + t.Errorf("CountSteps() is %v, want %v", count, len(steps)) } counter++ @@ -700,7 +722,7 @@ func testUsers(t *testing.T, db Interface) { liteOne.SetToken("") liteOne.SetRefreshToken("") liteOne.SetHash("") - liteOne.SetFavorites(nil) + liteOne.SetFavorites([]string{}) liteOne.SetActive(false) liteOne.SetAdmin(false) @@ -710,7 +732,7 @@ func testUsers(t *testing.T, db Interface) { liteTwo.SetToken("") liteTwo.SetRefreshToken("") liteTwo.SetHash("") - liteTwo.SetFavorites(nil) + liteTwo.SetFavorites([]string{}) liteTwo.SetActive(false) liteTwo.SetAdmin(false) From 63d6b193ae3455d03c8d27c3dcb726fe7b9d16a3 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 13:03:08 -0500 Subject: [PATCH 28/64] feat(database): add hooks --- database/integration_test.go | 99 +++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/database/integration_test.go b/database/integration_test.go index c7107380f..e69ba69c3 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -12,6 +12,7 @@ import ( "time" "github.com/go-vela/server/database/build" + "github.com/go-vela/server/database/hook" "github.com/google/go-cmp/cmp" @@ -197,10 +198,14 @@ func TestDatabase_Integration(t *testing.T) { t.Errorf("unable to ping database engine for %s: %v", test.name, err) } - t.Run("test_build", func(t *testing.T) { + t.Run("test_builds", func(t *testing.T) { testBuilds(t, db, []*library.Build{buildOne, buildTwo}, []*library.Repo{repoOne, repoTwo}) }) + t.Run("test_hooks", func(t *testing.T) { + testHooks(t, db, []*library.Repo{repoOne, repoTwo}) + }) + t.Run("test_services", func(t *testing.T) { testServices(t, db, []*library.Build{buildOne, buildTwo}) }) @@ -341,6 +346,98 @@ func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*li } } +func testHooks(t *testing.T, db Interface, repos []*library.Repo) { + // used to track the number of methods we call for hooks + // + // we start at 2 for creating the table and indexes for hooks + // since those are already called when the database engine starts + counter := 2 + + one := new(library.Hook) + one.SetID(1) + + two := new(library.Hook) + two.SetID(2) + + hooks := []*library.Hook{one, two} + + // create the hooks + for _, hook := range hooks { + _, err := db.CreateHook(hook) + if err != nil { + t.Errorf("unable to create hook %s: %v", hook.GetSourceID(), err) + } + } + counter++ + + // count the hooks + count, err := db.CountHooks() + if err != nil { + t.Errorf("unable to count hooks: %v", err) + } + if int(count) != len(hooks) { + t.Errorf("CountHooks() is %v, want %v", count, len(hooks)) + } + counter++ + + // list the hooks + list, err := db.ListHooks() + if err != nil { + t.Errorf("unable to list hooks: %v", err) + } + if !reflect.DeepEqual(list, hooks) { + t.Errorf("ListHooks() is %v, want %v", list, hooks) + } + counter++ + + // lookup the hooks by name + for _, hook := range hooks { + got, err := db.GetHookForRepo(repos[0], hook.GetNumber()) + if err != nil { + t.Errorf("unable to get hook %s for repo %s: %v", hook.GetSourceID(), repos[0].GetFullName(), err) + } + if !reflect.DeepEqual(got, hook) { + t.Errorf("GetHookForRepo() is %v, want %v", got, hook) + } + } + counter++ + + // update the hooks + for _, hook := range hooks { + hook.SetStatus("success") + _, err = db.UpdateHook(hook) + if err != nil { + t.Errorf("unable to update hook %s: %v", hook.GetSourceID(), err) + } + + // lookup the hook by ID + got, err := db.GetHook(hook.GetID()) + if err != nil { + t.Errorf("unable to get hook %s by ID: %v", hook.GetSourceID(), err) + } + if !reflect.DeepEqual(got, hook) { + t.Errorf("GetHook() is %v, want %v", got, hook) + } + } + counter++ + counter++ + + // delete the hooks + for _, hook := range hooks { + err = db.DeleteHook(hook) + if err != nil { + t.Errorf("unable to delete hook %s: %v", hook.GetSourceID(), err) + } + } + counter++ + + // ensure we called all the functions we should have + methods := reflect.TypeOf(new(hook.HookInterface)).Elem().NumMethod() + if counter != methods { + t.Errorf("total number of methods called is %v, want %v", counter, methods) + } +} + func testServices(t *testing.T, db Interface, builds []*library.Build) { // used to track the number of methods we call for services // From eddc01851e15aa186d7387851fffdf4c74cd5714 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 13:13:23 -0500 Subject: [PATCH 29/64] feat(database): add logs --- database/integration_test.go | 268 ++++++++++++++++++++++++----------- 1 file changed, 187 insertions(+), 81 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index e69ba69c3..e29ea1b5a 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -11,6 +11,8 @@ import ( "testing" "time" + "github.com/go-vela/server/database/log" + "github.com/go-vela/server/database/build" "github.com/go-vela/server/database/hook" @@ -174,6 +176,76 @@ func TestDatabase_Integration(t *testing.T) { repoTwo.SetPipelineType("") repoTwo.SetPreviousName("") + serviceOne := new(library.Service) + serviceOne.SetID(1) + serviceOne.SetBuildID(1) + serviceOne.SetRepoID(1) + serviceOne.SetNumber(1) + serviceOne.SetName("init") + serviceOne.SetImage("#init") + serviceOne.SetStatus("running") + serviceOne.SetError("") + serviceOne.SetExitCode(0) + serviceOne.SetCreated(1563474076) + serviceOne.SetStarted(1563474078) + serviceOne.SetFinished(1563474079) + serviceOne.SetHost("example.company.com") + serviceOne.SetRuntime("docker") + serviceOne.SetDistribution("linux") + + serviceTwo := new(library.Service) + serviceTwo.SetID(2) + serviceTwo.SetBuildID(1) + serviceTwo.SetRepoID(1) + serviceTwo.SetNumber(2) + serviceTwo.SetName("clone") + serviceTwo.SetImage("target/vela-git:v0.3.0") + serviceTwo.SetStatus("pending") + serviceTwo.SetError("") + serviceTwo.SetExitCode(0) + serviceTwo.SetCreated(1563474086) + serviceTwo.SetStarted(1563474088) + serviceTwo.SetFinished(1563474089) + serviceTwo.SetHost("example.company.com") + serviceTwo.SetRuntime("docker") + serviceTwo.SetDistribution("linux") + + stepOne := new(library.Step) + stepOne.SetID(1) + stepOne.SetBuildID(1) + stepOne.SetRepoID(1) + stepOne.SetNumber(1) + stepOne.SetName("init") + stepOne.SetImage("#init") + stepOne.SetStage("init") + stepOne.SetStatus("running") + stepOne.SetError("") + stepOne.SetExitCode(0) + stepOne.SetCreated(1563474076) + stepOne.SetStarted(1563474078) + stepOne.SetFinished(1563474079) + stepOne.SetHost("example.company.com") + stepOne.SetRuntime("docker") + stepOne.SetDistribution("linux") + + stepTwo := new(library.Step) + stepTwo.SetID(2) + stepTwo.SetBuildID(1) + stepTwo.SetRepoID(1) + stepTwo.SetNumber(2) + stepTwo.SetName("clone") + stepTwo.SetImage("target/vela-git:v0.3.0") + stepTwo.SetStage("init") + stepTwo.SetStatus("pending") + stepTwo.SetError("") + stepTwo.SetExitCode(0) + stepTwo.SetCreated(1563474086) + stepTwo.SetStarted(1563474088) + stepTwo.SetFinished(1563474089) + stepTwo.SetHost("example.company.com") + stepTwo.SetRuntime("docker") + stepTwo.SetDistribution("linux") + db, err := New( WithAddress(test.config.Address), WithCompressionLevel(test.config.CompressionLevel), @@ -206,12 +278,16 @@ func TestDatabase_Integration(t *testing.T) { testHooks(t, db, []*library.Repo{repoOne, repoTwo}) }) + t.Run("test_logs", func(t *testing.T) { + testLogs(t, db, []*library.Service{serviceOne, serviceTwo}, []*library.Step{stepOne, stepTwo}) + }) + t.Run("test_services", func(t *testing.T) { - testServices(t, db, []*library.Build{buildOne, buildTwo}) + testServices(t, db, []*library.Build{buildOne, buildTwo}, []*library.Service{serviceOne, serviceTwo}) }) t.Run("test_steps", func(t *testing.T) { - testSteps(t, db, []*library.Build{buildOne, buildTwo}) + testSteps(t, db, []*library.Build{buildOne, buildTwo}, []*library.Step{stepOne, stepTwo}) }) t.Run("test_users", func(t *testing.T) { @@ -438,48 +514,116 @@ func testHooks(t *testing.T, db Interface, repos []*library.Repo) { } } -func testServices(t *testing.T, db Interface, builds []*library.Build) { - // used to track the number of methods we call for services +func testLogs(t *testing.T, db Interface, services []*library.Service, steps []*library.Step) { + // used to track the number of methods we call for logs // - // we start at 2 for creating the table and indexes for services + // we start at 2 for creating the table and indexes for logs // since those are already called when the database engine starts counter := 2 - one := new(library.Service) + one := new(library.Log) one.SetID(1) - one.SetBuildID(1) - one.SetRepoID(1) - one.SetNumber(1) - one.SetName("init") - one.SetImage("#init") - one.SetStatus("running") - one.SetError("") - one.SetExitCode(0) - one.SetCreated(1563474076) - one.SetStarted(1563474078) - one.SetFinished(1563474079) - one.SetHost("example.company.com") - one.SetRuntime("docker") - one.SetDistribution("linux") - - two := new(library.Service) + + two := new(library.Log) two.SetID(2) - two.SetBuildID(1) - two.SetRepoID(1) - two.SetNumber(2) - two.SetName("clone") - two.SetImage("target/vela-git:v0.3.0") - two.SetStatus("pending") - two.SetError("") - two.SetExitCode(0) - two.SetCreated(1563474086) - two.SetStarted(1563474088) - two.SetFinished(1563474089) - two.SetHost("example.company.com") - two.SetRuntime("docker") - two.SetDistribution("linux") - - services := []*library.Service{one, two} + + logs := []*library.Log{one, two} + + // create the logs + for _, log := range logs { + err := db.CreateLog(log) + if err != nil { + t.Errorf("unable to create log %d: %v", log.GetID(), err) + } + } + counter++ + + // count the logs + count, err := db.CountLogs() + if err != nil { + t.Errorf("unable to count logs: %v", err) + } + if int(count) != len(logs) { + t.Errorf("CountLogs() is %v, want %v", count, len(logs)) + } + counter++ + + // list the logs + list, err := db.ListLogs() + if err != nil { + t.Errorf("unable to list logs: %v", err) + } + if !reflect.DeepEqual(list, logs) { + t.Errorf("ListLogs() is %v, want %v", list, logs) + } + counter++ + + // lookup the logs by service + for _, log := range logs { + got, err := db.GetLogForService(services[0]) + if err != nil { + t.Errorf("unable to get log %d for service %d: %v", log.GetID(), services[0].GetID(), err) + } + if !reflect.DeepEqual(got, log) { + t.Errorf("GetLogForService() is %v, want %v", got, log) + } + } + counter++ + + // lookup the logs by service + for _, log := range logs { + got, err := db.GetLogForStep(steps[0]) + if err != nil { + t.Errorf("unable to get log %d for step %d: %v", log.GetID(), steps[0].GetID(), err) + } + if !reflect.DeepEqual(got, log) { + t.Errorf("GetLogForStep() is %v, want %v", got, log) + } + } + counter++ + + // update the logs + for _, log := range logs { + log.SetData([]byte("bar")) + err = db.UpdateLog(log) + if err != nil { + t.Errorf("unable to update log %d: %v", log.GetID(), err) + } + + // lookup the log by ID + got, err := db.GetLog(log.GetID()) + if err != nil { + t.Errorf("unable to get log %d by ID: %v", log.GetID(), err) + } + if !reflect.DeepEqual(got, log) { + t.Errorf("GetLog() is %v, want %v", got, log) + } + } + counter++ + counter++ + + // delete the logs + for _, log := range logs { + err = db.DeleteLog(log) + if err != nil { + t.Errorf("unable to delete log %d: %v", log.GetID(), err) + } + } + counter++ + + // ensure we called all the functions we should have + methods := reflect.TypeOf(new(log.LogInterface)).Elem().NumMethod() + if counter != methods { + t.Errorf("total number of methods called is %v, want %v", counter, methods) + } +} + +func testServices(t *testing.T, db Interface, builds []*library.Build, services []*library.Service) { + // used to track the number of methods we call for services + // + // we start at 2 for creating the table and indexes for services + // since those are already called when the database engine starts + counter := 2 // create the services for _, service := range services { @@ -525,8 +669,8 @@ func testServices(t *testing.T, db Interface, builds []*library.Build) { if err != nil { t.Errorf("unable to list services for build %d: %v", builds[0].GetID(), err) } - if !reflect.DeepEqual(list, []*library.Service{two, one}) { - t.Errorf("ListServicesForBuild() is %v, want %v", list, []*library.Service{two, one}) + if !reflect.DeepEqual(list, []*library.Service{services[1], services[0]}) { + t.Errorf("ListServicesForBuild() is %v, want %v", list, []*library.Service{services[1], services[0]}) } if int(count) != len(services) { t.Errorf("ListServicesForBuild() is %v, want %v", count, len(services)) @@ -610,51 +754,13 @@ func testServices(t *testing.T, db Interface, builds []*library.Build) { } } -func testSteps(t *testing.T, db Interface, builds []*library.Build) { +func testSteps(t *testing.T, db Interface, builds []*library.Build, steps []*library.Step) { // used to track the number of methods we call for steps // // we start at 2 for creating the table and indexes for steps // since those are already called when the database engine starts counter := 2 - one := new(library.Step) - one.SetID(1) - one.SetBuildID(1) - one.SetRepoID(1) - one.SetNumber(1) - one.SetName("init") - one.SetImage("#init") - one.SetStage("init") - one.SetStatus("running") - one.SetError("") - one.SetExitCode(0) - one.SetCreated(1563474076) - one.SetStarted(1563474078) - one.SetFinished(1563474079) - one.SetHost("example.company.com") - one.SetRuntime("docker") - one.SetDistribution("linux") - - two := new(library.Step) - two.SetID(2) - two.SetBuildID(1) - two.SetRepoID(1) - two.SetNumber(2) - two.SetName("clone") - two.SetImage("target/vela-git:v0.3.0") - two.SetStage("init") - two.SetStatus("pending") - two.SetError("") - two.SetExitCode(0) - two.SetCreated(1563474086) - two.SetStarted(1563474088) - two.SetFinished(1563474089) - two.SetHost("example.company.com") - two.SetRuntime("docker") - two.SetDistribution("linux") - - steps := []*library.Step{one, two} - // create the steps for _, step := range steps { err := db.CreateStep(step) @@ -699,8 +805,8 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build) { if err != nil { t.Errorf("unable to list steps for build %d: %v", builds[0].GetID(), err) } - if !reflect.DeepEqual(list, []*library.Step{two, one}) { - t.Errorf("ListStepsForBuild() is %v, want %v", list, []*library.Step{two, one}) + if !reflect.DeepEqual(list, []*library.Step{steps[1], steps[0]}) { + t.Errorf("ListStepsForBuild() is %v, want %v", list, []*library.Step{steps[1], steps[0]}) } if int(count) != len(steps) { t.Errorf("ListStepsForBuild() is %v, want %v", count, len(steps)) From 39ed3ff66091ad54d87f6a46507aa6d99d544a3b Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 13:17:44 -0500 Subject: [PATCH 30/64] feat(database): add pipelines --- database/integration_test.go | 98 ++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/database/integration_test.go b/database/integration_test.go index e29ea1b5a..00c72c007 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -11,6 +11,8 @@ import ( "testing" "time" + "github.com/go-vela/server/database/pipeline" + "github.com/go-vela/server/database/log" "github.com/go-vela/server/database/build" @@ -282,6 +284,10 @@ func TestDatabase_Integration(t *testing.T) { testLogs(t, db, []*library.Service{serviceOne, serviceTwo}, []*library.Step{stepOne, stepTwo}) }) + t.Run("test_pipelines", func(t *testing.T) { + testPipelines(t, db, []*library.Repo{repoOne, repoTwo}) + }) + t.Run("test_services", func(t *testing.T) { testServices(t, db, []*library.Build{buildOne, buildTwo}, []*library.Service{serviceOne, serviceTwo}) }) @@ -618,6 +624,98 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* } } +func testPipelines(t *testing.T, db Interface, repos []*library.Repo) { + // used to track the number of methods we call for pipelines + // + // we start at 2 for creating the table and indexes for pipelines + // since those are already called when the database engine starts + counter := 2 + + one := new(library.Pipeline) + one.SetID(1) + + two := new(library.Pipeline) + two.SetID(2) + + pipelines := []*library.Pipeline{one, two} + + // create the pipelines + for _, pipeline := range pipelines { + _, err := db.CreatePipeline(pipeline) + if err != nil { + t.Errorf("unable to create pipeline %s: %v", pipeline.GetCommit(), err) + } + } + counter++ + + // count the pipelines + count, err := db.CountPipelines() + if err != nil { + t.Errorf("unable to count pipelines: %v", err) + } + if int(count) != len(pipelines) { + t.Errorf("CountPipelines() is %v, want %v", count, len(pipelines)) + } + counter++ + + // list the pipelines + list, err := db.ListPipelines() + if err != nil { + t.Errorf("unable to list pipelines: %v", err) + } + if !reflect.DeepEqual(list, pipelines) { + t.Errorf("ListPipelines() is %v, want %v", list, pipelines) + } + counter++ + + // lookup the pipelines by name + for _, pipeline := range pipelines { + got, err := db.GetPipelineForRepo(pipeline.GetCommit(), repos[0]) + if err != nil { + t.Errorf("unable to get pipeline %s for repo %s: %v", pipeline.GetCommit(), repos[0].GetFullName(), err) + } + if !reflect.DeepEqual(got, pipeline) { + t.Errorf("GetPipelineForRepo() is %v, want %v", got, pipeline) + } + } + counter++ + + // update the pipelines + for _, pipeline := range pipelines { + pipeline.SetVersion("2") + _, err = db.UpdatePipeline(pipeline) + if err != nil { + t.Errorf("unable to update pipeline %s: %v", pipeline.GetCommit(), err) + } + + // lookup the pipeline by ID + got, err := db.GetPipeline(pipeline.GetID()) + if err != nil { + t.Errorf("unable to get pipeline %s by ID: %v", pipeline.GetCommit(), err) + } + if !reflect.DeepEqual(got, pipeline) { + t.Errorf("GetPipeline() is %v, want %v", got, pipeline) + } + } + counter++ + counter++ + + // delete the pipelines + for _, pipeline := range pipelines { + err = db.DeletePipeline(pipeline) + if err != nil { + t.Errorf("unable to delete pipeline %s: %v", pipeline.GetCommit(), err) + } + } + counter++ + + // ensure we called all the functions we should have + methods := reflect.TypeOf(new(pipeline.PipelineInterface)).Elem().NumMethod() + if counter != methods { + t.Errorf("total number of methods called is %v, want %v", counter, methods) + } +} + func testServices(t *testing.T, db Interface, builds []*library.Build, services []*library.Service) { // used to track the number of methods we call for services // From d40a96d350f479ee9a8375de777d1244cfcc6623 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 13:21:43 -0500 Subject: [PATCH 31/64] feat(database): add repos --- database/integration_test.go | 90 ++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/database/integration_test.go b/database/integration_test.go index 00c72c007..bbc8902b6 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -11,6 +11,8 @@ import ( "testing" "time" + "github.com/go-vela/server/database/repo" + "github.com/go-vela/server/database/pipeline" "github.com/go-vela/server/database/log" @@ -288,6 +290,10 @@ func TestDatabase_Integration(t *testing.T) { testPipelines(t, db, []*library.Repo{repoOne, repoTwo}) }) + t.Run("test_repos", func(t *testing.T) { + testRepos(t, db, []*library.Repo{repoOne, repoTwo}) + }) + t.Run("test_services", func(t *testing.T) { testServices(t, db, []*library.Build{buildOne, buildTwo}, []*library.Service{serviceOne, serviceTwo}) }) @@ -716,6 +722,90 @@ func testPipelines(t *testing.T, db Interface, repos []*library.Repo) { } } +func testRepos(t *testing.T, db Interface, repos []*library.Repo) { + // used to track the number of methods we call for repos + // + // we start at 2 for creating the table and indexes for repos + // since those are already called when the database engine starts + counter := 2 + + // create the repos + for _, repo := range repos { + err := db.CreateRepo(repo) + if err != nil { + t.Errorf("unable to create repo %s: %v", repo.GetFullName(), err) + } + } + counter++ + + // count the repos + count, err := db.CountRepos() + if err != nil { + t.Errorf("unable to count repos: %v", err) + } + if int(count) != len(repos) { + t.Errorf("CountRepos() is %v, want %v", count, len(repos)) + } + counter++ + + // list the repos + list, err := db.ListRepos() + if err != nil { + t.Errorf("unable to list repos: %v", err) + } + if !reflect.DeepEqual(list, repos) { + t.Errorf("ListRepos() is %v, want %v", list, repos) + } + counter++ + + // lookup the repos by name + for _, repo := range repos { + got, err := db.GetRepoForOrg(repo.GetOrg(), repo.GetName()) + if err != nil { + t.Errorf("unable to get repo %s by org: %v", repo.GetFullName(), err) + } + if !reflect.DeepEqual(got, repo) { + t.Errorf("GetRepoForOrg() is %v, want %v", got, repo) + } + } + counter++ + + // update the repos + for _, repo := range repos { + repo.SetActive(false) + err = db.UpdateRepo(repo) + if err != nil { + t.Errorf("unable to update repo %s: %v", repo.GetFullName(), err) + } + + // lookup the repo by ID + got, err := db.GetRepo(repo.GetID()) + if err != nil { + t.Errorf("unable to get repo %s by ID: %v", repo.GetFullName(), err) + } + if !reflect.DeepEqual(got, repo) { + t.Errorf("GetRepo() is %v, want %v", got, repo) + } + } + counter++ + counter++ + + // delete the repos + for _, repo := range repos { + err = db.DeleteRepo(repo) + if err != nil { + t.Errorf("unable to delete repo %s: %v", repo.GetFullName(), err) + } + } + counter++ + + // ensure we called all the functions we should have + methods := reflect.TypeOf(new(repo.RepoInterface)).Elem().NumMethod() + if counter != methods { + t.Errorf("total number of methods called is %v, want %v", counter, methods) + } +} + func testServices(t *testing.T, db Interface, builds []*library.Build, services []*library.Service) { // used to track the number of methods we call for services // From 29881ac3bd81b8cdf46170c92a619d34ed1e5200 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 13:25:21 -0500 Subject: [PATCH 32/64] feat(database): add schedules --- database/integration_test.go | 98 ++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/database/integration_test.go b/database/integration_test.go index bbc8902b6..a3a03d4de 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -11,6 +11,8 @@ import ( "testing" "time" + "github.com/go-vela/server/database/schedule" + "github.com/go-vela/server/database/repo" "github.com/go-vela/server/database/pipeline" @@ -294,6 +296,10 @@ func TestDatabase_Integration(t *testing.T) { testRepos(t, db, []*library.Repo{repoOne, repoTwo}) }) + t.Run("test_schedules", func(t *testing.T) { + testSchedules(t, db, []*library.Repo{repoOne, repoTwo}) + }) + t.Run("test_services", func(t *testing.T) { testServices(t, db, []*library.Build{buildOne, buildTwo}, []*library.Service{serviceOne, serviceTwo}) }) @@ -806,6 +812,98 @@ func testRepos(t *testing.T, db Interface, repos []*library.Repo) { } } +func testSchedules(t *testing.T, db Interface, repos []*library.Repo) { + // used to track the number of methods we call for schedules + // + // we start at 2 for creating the table and indexes for schedules + // since those are already called when the database engine starts + counter := 2 + + one := new(library.Schedule) + one.SetID(1) + + two := new(library.Schedule) + two.SetID(2) + + schedules := []*library.Schedule{one, two} + + // create the schedules + for _, schedule := range schedules { + err := db.CreateSchedule(schedule) + if err != nil { + t.Errorf("unable to create schedule %s: %v", schedule.GetName(), err) + } + } + counter++ + + // count the schedules + count, err := db.CountSchedules() + if err != nil { + t.Errorf("unable to count schedules: %v", err) + } + if int(count) != len(schedules) { + t.Errorf("CountSchedules() is %v, want %v", count, len(schedules)) + } + counter++ + + // list the schedules + list, err := db.ListSchedules() + if err != nil { + t.Errorf("unable to list schedules: %v", err) + } + if !reflect.DeepEqual(list, schedules) { + t.Errorf("ListSchedules() is %v, want %v", list, schedules) + } + counter++ + + // lookup the schedules by name + for _, schedule := range schedules { + got, err := db.GetScheduleForRepo(repos[0], schedule.GetName()) + if err != nil { + t.Errorf("unable to get schedule %s for repo %s: %v", schedule.GetName(), repos[0].GetFullName(), err) + } + if !reflect.DeepEqual(got, schedule) { + t.Errorf("GetScheduleForRepo() is %v, want %v", got, schedule) + } + } + counter++ + + // update the schedules + for _, schedule := range schedules { + schedule.SetActive(false) + err = db.UpdateSchedule(schedule, false) + if err != nil { + t.Errorf("unable to update schedule %s: %v", schedule.GetName(), err) + } + + // lookup the schedule by ID + got, err := db.GetSchedule(schedule.GetID()) + if err != nil { + t.Errorf("unable to get schedule %s by ID: %v", schedule.GetName(), err) + } + if !reflect.DeepEqual(got, schedule) { + t.Errorf("GetSchedule() is %v, want %v", got, schedule) + } + } + counter++ + counter++ + + // delete the schedules + for _, schedule := range schedules { + err = db.DeleteSchedule(schedule) + if err != nil { + t.Errorf("unable to delete schedule %s: %v", schedule.GetName(), err) + } + } + counter++ + + // ensure we called all the functions we should have + methods := reflect.TypeOf(new(schedule.ScheduleInterface)).Elem().NumMethod() + if counter != methods { + t.Errorf("total number of methods called is %v, want %v", counter, methods) + } +} + func testServices(t *testing.T, db Interface, builds []*library.Build, services []*library.Service) { // used to track the number of methods we call for services // From 263b1df1adc7088d856337e3683108f7198d2011 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 13:29:21 -0500 Subject: [PATCH 33/64] feat(database): add secrets --- database/integration_test.go | 98 ++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/database/integration_test.go b/database/integration_test.go index a3a03d4de..5858fa292 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -11,6 +11,8 @@ import ( "testing" "time" + "github.com/go-vela/server/database/secret" + "github.com/go-vela/server/database/schedule" "github.com/go-vela/server/database/repo" @@ -300,6 +302,10 @@ func TestDatabase_Integration(t *testing.T) { testSchedules(t, db, []*library.Repo{repoOne, repoTwo}) }) + t.Run("test_secrets", func(t *testing.T) { + testSecrets(t, db, []*library.Repo{repoOne, repoTwo}) + }) + t.Run("test_services", func(t *testing.T) { testServices(t, db, []*library.Build{buildOne, buildTwo}, []*library.Service{serviceOne, serviceTwo}) }) @@ -904,6 +910,98 @@ func testSchedules(t *testing.T, db Interface, repos []*library.Repo) { } } +func testSecrets(t *testing.T, db Interface, repos []*library.Repo) { + // used to track the number of methods we call for secrets + // + // we start at 2 for creating the table and indexes for secrets + // since those are already called when the database engine starts + counter := 2 + + one := new(library.Secret) + one.SetID(1) + + two := new(library.Secret) + two.SetID(2) + + secrets := []*library.Secret{one, two} + + // create the secrets + for _, secret := range secrets { + err := db.CreateSecret(secret) + if err != nil { + t.Errorf("unable to create secret %s: %v", secret.GetName(), err) + } + } + counter++ + + // count the secrets + count, err := db.CountSecrets() + if err != nil { + t.Errorf("unable to count secrets: %v", err) + } + if int(count) != len(secrets) { + t.Errorf("CountSecrets() is %v, want %v", count, len(secrets)) + } + counter++ + + // list the secrets + list, err := db.ListSecrets() + if err != nil { + t.Errorf("unable to list secrets: %v", err) + } + if !reflect.DeepEqual(list, secrets) { + t.Errorf("ListSecrets() is %v, want %v", list, secrets) + } + counter++ + + // lookup the secrets by name + for _, secret := range secrets { + got, err := db.GetSecretForRepo(secret.GetName(), repos[0]) + if err != nil { + t.Errorf("unable to get secret %s for repo %s: %v", secret.GetName(), repos[0].GetFullName(), err) + } + if !reflect.DeepEqual(got, secret) { + t.Errorf("GetSecretForRepo() is %v, want %v", got, secret) + } + } + counter++ + + // update the secrets + for _, secret := range secrets { + secret.SetAllowCommand(false) + err = db.UpdateSecret(secret) + if err != nil { + t.Errorf("unable to update secret %s: %v", secret.GetName(), err) + } + + // lookup the secret by ID + got, err := db.GetSecret(secret.GetID()) + if err != nil { + t.Errorf("unable to get secret %s by ID: %v", secret.GetName(), err) + } + if !reflect.DeepEqual(got, secret) { + t.Errorf("GetSecret() is %v, want %v", got, secret) + } + } + counter++ + counter++ + + // delete the secrets + for _, secret := range secrets { + err = db.DeleteSecret(secret) + if err != nil { + t.Errorf("unable to delete secret %s: %v", secret.GetName(), err) + } + } + counter++ + + // ensure we called all the functions we should have + methods := reflect.TypeOf(new(secret.SecretInterface)).Elem().NumMethod() + if counter != methods { + t.Errorf("total number of methods called is %v, want %v", counter, methods) + } +} + func testServices(t *testing.T, db Interface, builds []*library.Build, services []*library.Service) { // used to track the number of methods we call for services // From d1a62327105c02d74456770599c80c3b2cd92cac Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 13:41:13 -0500 Subject: [PATCH 34/64] fix(database): integration tests --- database/integration_test.go | 84 +++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 5858fa292..10285ddee 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -79,6 +79,7 @@ func TestDatabase_Integration(t *testing.T) { buildOne.SetNumber(1) buildOne.SetParent(1) buildOne.SetEvent("push") + buildOne.SetEventAction("") buildOne.SetStatus("running") buildOne.SetError("") buildOne.SetEnqueued(1563474077) @@ -111,6 +112,7 @@ func TestDatabase_Integration(t *testing.T) { buildTwo.SetNumber(2) buildTwo.SetParent(1) buildTwo.SetEvent("pull_request") + buildTwo.SetEventAction("") buildTwo.SetStatus("running") buildTwo.SetError("") buildTwo.SetEnqueued(1563474077) @@ -382,9 +384,9 @@ func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*li if err != nil { t.Errorf("unable to list builds for repo %s: %v", repos[0].GetFullName(), err) } - if !reflect.DeepEqual(list, builds) { + if !reflect.DeepEqual(list, []*library.Build{builds[1], builds[0]}) { pretty.Ldiff(t, list, builds) - t.Errorf("ListBuildsForRepo() is %v, want %v", list, builds) + t.Errorf("ListBuildsForRepo() is %v, want %v", list, []*library.Build{builds[1], builds[0]}) } counter++ @@ -455,9 +457,35 @@ func testHooks(t *testing.T, db Interface, repos []*library.Repo) { one := new(library.Hook) one.SetID(1) + one.SetRepoID(1) + one.SetBuildID(1) + one.SetNumber(1) + one.SetSourceID("c8da1302-07d6-11ea-882f-4893bca275b8") + one.SetCreated(time.Now().UTC().Unix()) + one.SetHost("github.com") + one.SetEvent("push") + one.SetEventAction("") + one.SetBranch("master") + one.SetError("") + one.SetStatus("success") + one.SetLink("https://github.com/github/octocat/settings/hooks/1") + one.SetWebhookID(123456) two := new(library.Hook) two.SetID(2) + two.SetRepoID(1) + two.SetBuildID(1) + two.SetNumber(2) + two.SetSourceID("c8da1302-07d6-11ea-882f-4893bca275b8") + two.SetCreated(time.Now().UTC().Unix()) + two.SetHost("github.com") + two.SetEvent("push") + two.SetEventAction("") + two.SetBranch("master") + two.SetError("") + two.SetStatus("success") + two.SetLink("https://github.com/github/octocat/settings/hooks/1") + two.SetWebhookID(123456) hooks := []*library.Hook{one, two} @@ -547,9 +575,15 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* one := new(library.Log) one.SetID(1) + one.SetBuildID(1) + one.SetRepoID(1) + one.SetData([]byte("foo")) two := new(library.Log) two.SetID(2) + two.SetBuildID(1) + two.SetRepoID(1) + two.SetData([]byte("foo")) logs := []*library.Log{one, two} @@ -651,9 +685,37 @@ func testPipelines(t *testing.T, db Interface, repos []*library.Repo) { one := new(library.Pipeline) one.SetID(1) + one.SetRepoID(1) + one.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") + one.SetFlavor("large") + one.SetPlatform("docker") + one.SetRef("refs/heads/master") + one.SetRef("yaml") + one.SetVersion("1") + one.SetExternalSecrets(false) + one.SetInternalSecrets(false) + one.SetServices(true) + one.SetStages(false) + one.SetSteps(true) + one.SetTemplates(false) + one.SetData([]byte("version: 1")) two := new(library.Pipeline) two.SetID(2) + two.SetRepoID(1) + two.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") + two.SetFlavor("large") + two.SetPlatform("docker") + two.SetRef("refs/heads/master") + two.SetRef("yaml") + two.SetVersion("1") + two.SetExternalSecrets(false) + two.SetInternalSecrets(false) + two.SetServices(true) + two.SetStages(false) + two.SetSteps(true) + two.SetTemplates(false) + two.SetData([]byte("version: 1")) pipelines := []*library.Pipeline{one, two} @@ -827,9 +889,27 @@ func testSchedules(t *testing.T, db Interface, repos []*library.Repo) { one := new(library.Schedule) one.SetID(1) + one.SetRepoID(1) + one.SetActive(true) + one.SetName("nightly") + one.SetEntry("0 0 * * *") + one.SetCreatedAt(time.Now().UTC().Unix()) + one.SetCreatedBy("user1") + one.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix()) + one.SetUpdatedBy("user2") + one.SetScheduledAt(time.Now().Add(time.Hour * 2).UTC().Unix()) two := new(library.Schedule) two.SetID(2) + two.SetRepoID(1) + two.SetActive(true) + two.SetName("hourly") + two.SetEntry("0 * * * *") + two.SetCreatedAt(time.Now().UTC().Unix()) + two.SetCreatedBy("user1") + two.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix()) + two.SetUpdatedBy("user2") + two.SetScheduledAt(time.Now().Add(time.Hour * 2).UTC().Unix()) schedules := []*library.Schedule{one, two} From f50a30dbdb94e1cb23fd1b33da68e059beb215ca Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 13:58:03 -0500 Subject: [PATCH 35/64] fix(database): integration tests --- database/integration_test.go | 77 +++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 15 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 10285ddee..72e5e9121 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -140,6 +140,7 @@ func TestDatabase_Integration(t *testing.T) { repoOne := new(library.Repo) repoOne.SetID(1) + repoOne.SetUserID(1) repoOne.SetOrg("github") repoOne.SetName("octocat") repoOne.SetFullName("github/octocat") @@ -164,6 +165,7 @@ func TestDatabase_Integration(t *testing.T) { repoTwo := new(library.Repo) repoTwo.SetID(2) + repoTwo.SetUserID(1) repoTwo.SetOrg("github") repoTwo.SetName("octokitty") repoTwo.SetFullName("github/octokitty") @@ -374,7 +376,6 @@ func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*li t.Errorf("unable to list builds: %v", err) } if !reflect.DeepEqual(list, builds) { - pretty.Ldiff(t, list, builds) t.Errorf("ListBuilds() is %v, want %v", list, builds) } counter++ @@ -385,7 +386,6 @@ func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*li t.Errorf("unable to list builds for repo %s: %v", repos[0].GetFullName(), err) } if !reflect.DeepEqual(list, []*library.Build{builds[1], builds[0]}) { - pretty.Ldiff(t, list, builds) t.Errorf("ListBuildsForRepo() is %v, want %v", list, []*library.Build{builds[1], builds[0]}) } counter++ @@ -407,6 +407,7 @@ func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*li t.Errorf("unable to get build %d for repo %s: %v", build.GetID(), repos[0].GetFullName(), err) } if !reflect.DeepEqual(got, build) { + pretty.Ldiff(t, got, build) t.Errorf("GetBuildForRepo() is %v, want %v", got, build) } } @@ -573,19 +574,39 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* // since those are already called when the database engine starts counter := 2 - one := new(library.Log) - one.SetID(1) - one.SetBuildID(1) - one.SetRepoID(1) - one.SetData([]byte("foo")) + serviceOne := new(library.Log) + serviceOne.SetID(1) + serviceOne.SetBuildID(1) + serviceOne.SetRepoID(1) + serviceOne.SetServiceID(1) + serviceOne.SetData([]byte("foo")) - two := new(library.Log) - two.SetID(2) - two.SetBuildID(1) - two.SetRepoID(1) - two.SetData([]byte("foo")) + serviceTwo := new(library.Log) + serviceTwo.SetID(2) + serviceTwo.SetBuildID(1) + serviceTwo.SetRepoID(1) + serviceTwo.SetServiceID(2) + serviceTwo.SetData([]byte("foo")) + + serviceLogs := []*library.Log{serviceOne, serviceTwo} - logs := []*library.Log{one, two} + stepOne := new(library.Log) + stepOne.SetID(1) + stepOne.SetBuildID(1) + stepOne.SetRepoID(1) + stepOne.SetStepID(1) + stepOne.SetData([]byte("foo")) + + stepTwo := new(library.Log) + stepTwo.SetID(2) + stepTwo.SetBuildID(1) + stepTwo.SetRepoID(1) + stepTwo.SetStepID(2) + stepTwo.SetData([]byte("foo")) + + stepLogs := []*library.Log{stepOne, stepTwo} + + logs := append(serviceLogs, stepLogs...) // create the logs for _, log := range logs { @@ -617,7 +638,7 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* counter++ // lookup the logs by service - for _, log := range logs { + for _, log := range serviceLogs { got, err := db.GetLogForService(services[0]) if err != nil { t.Errorf("unable to get log %d for service %d: %v", log.GetID(), services[0].GetID(), err) @@ -629,7 +650,7 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* counter++ // lookup the logs by service - for _, log := range logs { + for _, log := range stepLogs { got, err := db.GetLogForStep(steps[0]) if err != nil { t.Errorf("unable to get log %d for step %d: %v", log.GetID(), steps[0].GetID(), err) @@ -999,9 +1020,35 @@ func testSecrets(t *testing.T, db Interface, repos []*library.Repo) { one := new(library.Secret) one.SetID(1) + one.SetOrg("github") + one.SetRepo("octocat") + one.SetTeam("") + one.SetName("foo") + one.SetValue("bar") + one.SetType("repo") + one.SetImages([]string{"alpine"}) + one.SetEvents([]string{"push", "tag", "deployment"}) + one.SetAllowCommand(true) + one.SetCreatedAt(time.Now().UTC().Unix()) + one.SetCreatedBy("octocat") + one.SetUpdatedAt(time.Now().UTC().Unix()) + one.SetUpdatedBy("octokitty") two := new(library.Secret) two.SetID(2) + two.SetOrg("github") + two.SetRepo("octocat") + two.SetTeam("") + two.SetName("bar") + two.SetValue("baz") + two.SetType("repo") + two.SetImages([]string{"alpine"}) + two.SetEvents([]string{"push", "tag", "deployment"}) + two.SetAllowCommand(true) + two.SetCreatedAt(time.Now().UTC().Unix()) + two.SetCreatedBy("octocat") + two.SetUpdatedAt(time.Now().UTC().Unix()) + two.SetUpdatedBy("octokitty") secrets := []*library.Secret{one, two} From e9766d45bb7cd23156de07248a640ba09fef1b0f Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 14:05:17 -0500 Subject: [PATCH 36/64] fix(database: fix logs --- database/integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 72e5e9121..3bc347b73 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -591,14 +591,14 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* serviceLogs := []*library.Log{serviceOne, serviceTwo} stepOne := new(library.Log) - stepOne.SetID(1) + stepOne.SetID(3) stepOne.SetBuildID(1) stepOne.SetRepoID(1) stepOne.SetStepID(1) stepOne.SetData([]byte("foo")) stepTwo := new(library.Log) - stepTwo.SetID(2) + stepTwo.SetID(4) stepTwo.SetBuildID(1) stepTwo.SetRepoID(1) stepTwo.SetStepID(2) From 0603090094ceb736b24e654004ec5b2d63a6ae7d Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 14:08:10 -0500 Subject: [PATCH 37/64] fix(database: fix pipelines --- database/integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 3bc347b73..e457dbf67 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -711,7 +711,7 @@ func testPipelines(t *testing.T, db Interface, repos []*library.Repo) { one.SetFlavor("large") one.SetPlatform("docker") one.SetRef("refs/heads/master") - one.SetRef("yaml") + one.SetType("yaml") one.SetVersion("1") one.SetExternalSecrets(false) one.SetInternalSecrets(false) @@ -728,7 +728,7 @@ func testPipelines(t *testing.T, db Interface, repos []*library.Repo) { two.SetFlavor("large") two.SetPlatform("docker") two.SetRef("refs/heads/master") - two.SetRef("yaml") + two.SetType("yaml") two.SetVersion("1") two.SetExternalSecrets(false) two.SetInternalSecrets(false) From 32b076ddb01998a219b937579eaf3a526039736f Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 14:17:46 -0500 Subject: [PATCH 38/64] fix(database): repos --- database/integration_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/database/integration_test.go b/database/integration_test.go index e457dbf67..6eab5d10d 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -141,6 +141,7 @@ func TestDatabase_Integration(t *testing.T) { repoOne := new(library.Repo) repoOne.SetID(1) repoOne.SetUserID(1) + repoOne.SetHash("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy") repoOne.SetOrg("github") repoOne.SetName("octocat") repoOne.SetFullName("github/octocat") @@ -166,6 +167,7 @@ func TestDatabase_Integration(t *testing.T) { repoTwo := new(library.Repo) repoTwo.SetID(2) repoTwo.SetUserID(1) + repoTwo.SetHash("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy") repoTwo.SetOrg("github") repoTwo.SetName("octokitty") repoTwo.SetFullName("github/octokitty") @@ -724,7 +726,7 @@ func testPipelines(t *testing.T, db Interface, repos []*library.Repo) { two := new(library.Pipeline) two.SetID(2) two.SetRepoID(1) - two.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") + two.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135164") two.SetFlavor("large") two.SetPlatform("docker") two.SetRef("refs/heads/master") From 8735c04063c25fa6b0864064e57208d8da8b6684 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 14:31:47 -0500 Subject: [PATCH 39/64] fix(database): integration tests --- database/integration_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 6eab5d10d..aad2d29fa 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -581,6 +581,7 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* serviceOne.SetBuildID(1) serviceOne.SetRepoID(1) serviceOne.SetServiceID(1) + serviceOne.SetStepID(0) serviceOne.SetData([]byte("foo")) serviceTwo := new(library.Log) @@ -588,6 +589,7 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* serviceTwo.SetBuildID(1) serviceTwo.SetRepoID(1) serviceTwo.SetServiceID(2) + serviceTwo.SetStepID(0) serviceTwo.SetData([]byte("foo")) serviceLogs := []*library.Log{serviceOne, serviceTwo} @@ -596,6 +598,7 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* stepOne.SetID(3) stepOne.SetBuildID(1) stepOne.SetRepoID(1) + stepOne.SetServiceID(0) stepOne.SetStepID(1) stepOne.SetData([]byte("foo")) @@ -603,6 +606,7 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* stepTwo.SetID(4) stepTwo.SetBuildID(1) stepTwo.SetRepoID(1) + stepTwo.SetServiceID(0) stepTwo.SetStepID(2) stepTwo.SetData([]byte("foo")) @@ -917,9 +921,9 @@ func testSchedules(t *testing.T, db Interface, repos []*library.Repo) { one.SetName("nightly") one.SetEntry("0 0 * * *") one.SetCreatedAt(time.Now().UTC().Unix()) - one.SetCreatedBy("user1") + one.SetCreatedBy("octocat") one.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix()) - one.SetUpdatedBy("user2") + one.SetUpdatedBy("octokitty") one.SetScheduledAt(time.Now().Add(time.Hour * 2).UTC().Unix()) two := new(library.Schedule) @@ -929,9 +933,9 @@ func testSchedules(t *testing.T, db Interface, repos []*library.Repo) { two.SetName("hourly") two.SetEntry("0 * * * *") two.SetCreatedAt(time.Now().UTC().Unix()) - two.SetCreatedBy("user1") + two.SetCreatedBy("octocat") two.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix()) - two.SetUpdatedBy("user2") + two.SetUpdatedBy("octokitty") two.SetScheduledAt(time.Now().Add(time.Hour * 2).UTC().Unix()) schedules := []*library.Schedule{one, two} From 94f66eb1bdb1c0980f6a718f6d4ac606b6c455c3 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 14:38:24 -0500 Subject: [PATCH 40/64] fix(database): integration tests --- database/integration_test.go | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index aad2d29fa..c53fbd6dc 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -11,31 +11,21 @@ import ( "testing" "time" - "github.com/go-vela/server/database/secret" - - "github.com/go-vela/server/database/schedule" - - "github.com/go-vela/server/database/repo" - - "github.com/go-vela/server/database/pipeline" - - "github.com/go-vela/server/database/log" - "github.com/go-vela/server/database/build" "github.com/go-vela/server/database/hook" - - "github.com/google/go-cmp/cmp" - + "github.com/go-vela/server/database/log" + "github.com/go-vela/server/database/pipeline" + "github.com/go-vela/server/database/repo" + "github.com/go-vela/server/database/schedule" + "github.com/go-vela/server/database/secret" "github.com/go-vela/server/database/service" - - "github.com/kr/pretty" - - "github.com/go-vela/types/raw" - "github.com/go-vela/server/database/step" "github.com/go-vela/server/database/user" "github.com/go-vela/server/database/worker" "github.com/go-vela/types/library" + "github.com/go-vela/types/raw" + "github.com/google/go-cmp/cmp" + "github.com/kr/pretty" ) func TestDatabase_Integration(t *testing.T) { @@ -404,12 +394,11 @@ func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*li // lookup the builds by repo and number for _, build := range builds { - got, err = db.GetBuildForRepo(repos[0], build.GetNumber()) + got, err = db.GetBuildForRepo(repos[build.GetRepoID()], build.GetNumber()) if err != nil { t.Errorf("unable to get build %d for repo %s: %v", build.GetID(), repos[0].GetFullName(), err) } if !reflect.DeepEqual(got, build) { - pretty.Ldiff(t, got, build) t.Errorf("GetBuildForRepo() is %v, want %v", got, build) } } @@ -645,7 +634,7 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* // lookup the logs by service for _, log := range serviceLogs { - got, err := db.GetLogForService(services[0]) + got, err := db.GetLogForService(services[log.GetServiceID()]) if err != nil { t.Errorf("unable to get log %d for service %d: %v", log.GetID(), services[0].GetID(), err) } @@ -657,7 +646,7 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* // lookup the logs by service for _, log := range stepLogs { - got, err := db.GetLogForStep(steps[0]) + got, err := db.GetLogForStep(steps[log.GetStepID()]) if err != nil { t.Errorf("unable to get log %d for step %d: %v", log.GetID(), steps[0].GetID(), err) } From dd2778575d36f5adc0eb227a7716d0ac9dd6a369 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Thu, 29 Jun 2023 14:45:48 -0500 Subject: [PATCH 41/64] fix(database): minus one --- database/integration_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index c53fbd6dc..dee3a627a 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -394,7 +394,7 @@ func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*li // lookup the builds by repo and number for _, build := range builds { - got, err = db.GetBuildForRepo(repos[build.GetRepoID()], build.GetNumber()) + got, err = db.GetBuildForRepo(repos[build.GetRepoID()-1], build.GetNumber()) if err != nil { t.Errorf("unable to get build %d for repo %s: %v", build.GetID(), repos[0].GetFullName(), err) } @@ -634,7 +634,7 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* // lookup the logs by service for _, log := range serviceLogs { - got, err := db.GetLogForService(services[log.GetServiceID()]) + got, err := db.GetLogForService(services[log.GetServiceID()-1]) if err != nil { t.Errorf("unable to get log %d for service %d: %v", log.GetID(), services[0].GetID(), err) } @@ -646,7 +646,7 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* // lookup the logs by service for _, log := range stepLogs { - got, err := db.GetLogForStep(steps[log.GetStepID()]) + got, err := db.GetLogForStep(steps[log.GetStepID()-1]) if err != nil { t.Errorf("unable to get log %d for step %d: %v", log.GetID(), steps[0].GetID(), err) } From e0e82b1431a82c4ddaab70e1db501c423d665a1f Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Fri, 30 Jun 2023 09:38:09 -0500 Subject: [PATCH 42/64] chore: cleanup --- database/integration_test.go | 1262 +++++++++++++++++----------------- 1 file changed, 631 insertions(+), 631 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index dee3a627a..8f80f42d8 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -28,6 +28,20 @@ import ( "github.com/kr/pretty" ) +type Resources struct { + Builds []*library.Build + Hooks []*library.Hook + Logs []*library.Log + Pipelines []*library.Pipeline + Repos []*library.Repo + Schedules []*library.Schedule + Secrets []*library.Secret + Services []*library.Service + Steps []*library.Step + Users []*library.User + Workers []*library.Worker +} + func TestDatabase_Integration(t *testing.T) { // check if we should skip the integration test // @@ -62,193 +76,7 @@ func TestDatabase_Integration(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { // create resources for testing - buildOne := new(library.Build) - buildOne.SetID(1) - buildOne.SetRepoID(1) - buildOne.SetPipelineID(1) - buildOne.SetNumber(1) - buildOne.SetParent(1) - buildOne.SetEvent("push") - buildOne.SetEventAction("") - buildOne.SetStatus("running") - buildOne.SetError("") - buildOne.SetEnqueued(1563474077) - buildOne.SetCreated(1563474076) - buildOne.SetStarted(1563474078) - buildOne.SetFinished(1563474079) - buildOne.SetDeploy("") - buildOne.SetDeployPayload(raw.StringSliceMap{"foo": "test1"}) - buildOne.SetClone("https://github.com/github/octocat.git") - buildOne.SetSource("https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135163") - buildOne.SetTitle("push received from https://github.com/github/octocat") - buildOne.SetMessage("First commit...") - buildOne.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") - buildOne.SetSender("OctoKitty") - buildOne.SetAuthor("OctoKitty") - buildOne.SetEmail("OctoKitty@github.com") - buildOne.SetLink("https://example.company.com/github/octocat/1") - buildOne.SetBranch("master") - buildOne.SetRef("refs/heads/master") - buildOne.SetBaseRef("") - buildOne.SetHeadRef("changes") - buildOne.SetHost("example.company.com") - buildOne.SetRuntime("docker") - buildOne.SetDistribution("linux") - - buildTwo := new(library.Build) - buildTwo.SetID(2) - buildTwo.SetRepoID(1) - buildTwo.SetPipelineID(1) - buildTwo.SetNumber(2) - buildTwo.SetParent(1) - buildTwo.SetEvent("pull_request") - buildTwo.SetEventAction("") - buildTwo.SetStatus("running") - buildTwo.SetError("") - buildTwo.SetEnqueued(1563474077) - buildTwo.SetCreated(1563474076) - buildTwo.SetStarted(1563474078) - buildTwo.SetFinished(1563474079) - buildTwo.SetDeploy("") - buildTwo.SetDeployPayload(raw.StringSliceMap{"foo": "test1"}) - buildTwo.SetClone("https://github.com/github/octocat.git") - buildTwo.SetSource("https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135164") - buildTwo.SetTitle("pull_request received from https://github.com/github/octocat") - buildTwo.SetMessage("Second commit...") - buildTwo.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135164") - buildTwo.SetSender("OctoKitty") - buildTwo.SetAuthor("OctoKitty") - buildTwo.SetEmail("OctoKitty@github.com") - buildTwo.SetLink("https://example.company.com/github/octocat/2") - buildTwo.SetBranch("master") - buildTwo.SetRef("refs/heads/master") - buildTwo.SetBaseRef("") - buildTwo.SetHeadRef("changes") - buildTwo.SetHost("example.company.com") - buildTwo.SetRuntime("docker") - buildTwo.SetDistribution("linux") - - repoOne := new(library.Repo) - repoOne.SetID(1) - repoOne.SetUserID(1) - repoOne.SetHash("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy") - repoOne.SetOrg("github") - repoOne.SetName("octocat") - repoOne.SetFullName("github/octocat") - repoOne.SetLink("https://github.com/github/octocat") - repoOne.SetClone("https://github.com/github/octocat.git") - repoOne.SetBranch("main") - repoOne.SetTopics([]string{"cloud", "security"}) - repoOne.SetBuildLimit(10) - repoOne.SetTimeout(30) - repoOne.SetCounter(0) - repoOne.SetVisibility("public") - repoOne.SetPrivate(false) - repoOne.SetTrusted(false) - repoOne.SetActive(true) - repoOne.SetAllowPull(false) - repoOne.SetAllowPush(true) - repoOne.SetAllowDeploy(false) - repoOne.SetAllowTag(false) - repoOne.SetAllowComment(false) - repoOne.SetPipelineType("") - repoOne.SetPreviousName("") - - repoTwo := new(library.Repo) - repoTwo.SetID(2) - repoTwo.SetUserID(1) - repoTwo.SetHash("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy") - repoTwo.SetOrg("github") - repoTwo.SetName("octokitty") - repoTwo.SetFullName("github/octokitty") - repoTwo.SetLink("https://github.com/github/octokitty") - repoTwo.SetClone("https://github.com/github/octokitty.git") - repoTwo.SetBranch("master") - repoTwo.SetTopics([]string{"cloud", "security"}) - repoTwo.SetBuildLimit(10) - repoTwo.SetTimeout(30) - repoTwo.SetCounter(0) - repoTwo.SetVisibility("public") - repoTwo.SetPrivate(false) - repoTwo.SetTrusted(false) - repoTwo.SetActive(true) - repoTwo.SetAllowPull(false) - repoTwo.SetAllowPush(true) - repoTwo.SetAllowDeploy(false) - repoTwo.SetAllowTag(false) - repoTwo.SetAllowComment(false) - repoTwo.SetPipelineType("") - repoTwo.SetPreviousName("") - - serviceOne := new(library.Service) - serviceOne.SetID(1) - serviceOne.SetBuildID(1) - serviceOne.SetRepoID(1) - serviceOne.SetNumber(1) - serviceOne.SetName("init") - serviceOne.SetImage("#init") - serviceOne.SetStatus("running") - serviceOne.SetError("") - serviceOne.SetExitCode(0) - serviceOne.SetCreated(1563474076) - serviceOne.SetStarted(1563474078) - serviceOne.SetFinished(1563474079) - serviceOne.SetHost("example.company.com") - serviceOne.SetRuntime("docker") - serviceOne.SetDistribution("linux") - - serviceTwo := new(library.Service) - serviceTwo.SetID(2) - serviceTwo.SetBuildID(1) - serviceTwo.SetRepoID(1) - serviceTwo.SetNumber(2) - serviceTwo.SetName("clone") - serviceTwo.SetImage("target/vela-git:v0.3.0") - serviceTwo.SetStatus("pending") - serviceTwo.SetError("") - serviceTwo.SetExitCode(0) - serviceTwo.SetCreated(1563474086) - serviceTwo.SetStarted(1563474088) - serviceTwo.SetFinished(1563474089) - serviceTwo.SetHost("example.company.com") - serviceTwo.SetRuntime("docker") - serviceTwo.SetDistribution("linux") - - stepOne := new(library.Step) - stepOne.SetID(1) - stepOne.SetBuildID(1) - stepOne.SetRepoID(1) - stepOne.SetNumber(1) - stepOne.SetName("init") - stepOne.SetImage("#init") - stepOne.SetStage("init") - stepOne.SetStatus("running") - stepOne.SetError("") - stepOne.SetExitCode(0) - stepOne.SetCreated(1563474076) - stepOne.SetStarted(1563474078) - stepOne.SetFinished(1563474079) - stepOne.SetHost("example.company.com") - stepOne.SetRuntime("docker") - stepOne.SetDistribution("linux") - - stepTwo := new(library.Step) - stepTwo.SetID(2) - stepTwo.SetBuildID(1) - stepTwo.SetRepoID(1) - stepTwo.SetNumber(2) - stepTwo.SetName("clone") - stepTwo.SetImage("target/vela-git:v0.3.0") - stepTwo.SetStage("init") - stepTwo.SetStatus("pending") - stepTwo.SetError("") - stepTwo.SetExitCode(0) - stepTwo.SetCreated(1563474086) - stepTwo.SetStarted(1563474088) - stepTwo.SetFinished(1563474089) - stepTwo.SetHost("example.company.com") - stepTwo.SetRuntime("docker") - stepTwo.SetDistribution("linux") + resources := newResources() db, err := New( WithAddress(test.config.Address), @@ -274,49 +102,27 @@ func TestDatabase_Integration(t *testing.T) { t.Errorf("unable to ping database engine for %s: %v", test.name, err) } - t.Run("test_builds", func(t *testing.T) { - testBuilds(t, db, []*library.Build{buildOne, buildTwo}, []*library.Repo{repoOne, repoTwo}) - }) + t.Run("test_builds", func(t *testing.T) { testBuilds(t, db, resources) }) - t.Run("test_hooks", func(t *testing.T) { - testHooks(t, db, []*library.Repo{repoOne, repoTwo}) - }) + t.Run("test_hooks", func(t *testing.T) { testHooks(t, db, resources) }) - t.Run("test_logs", func(t *testing.T) { - testLogs(t, db, []*library.Service{serviceOne, serviceTwo}, []*library.Step{stepOne, stepTwo}) - }) + t.Run("test_logs", func(t *testing.T) { testLogs(t, db, resources) }) - t.Run("test_pipelines", func(t *testing.T) { - testPipelines(t, db, []*library.Repo{repoOne, repoTwo}) - }) + t.Run("test_pipelines", func(t *testing.T) { testPipelines(t, db, resources) }) - t.Run("test_repos", func(t *testing.T) { - testRepos(t, db, []*library.Repo{repoOne, repoTwo}) - }) + t.Run("test_repos", func(t *testing.T) { testRepos(t, db, resources) }) - t.Run("test_schedules", func(t *testing.T) { - testSchedules(t, db, []*library.Repo{repoOne, repoTwo}) - }) + t.Run("test_schedules", func(t *testing.T) { testSchedules(t, db, resources) }) - t.Run("test_secrets", func(t *testing.T) { - testSecrets(t, db, []*library.Repo{repoOne, repoTwo}) - }) + t.Run("test_secrets", func(t *testing.T) { testSecrets(t, db, resources) }) - t.Run("test_services", func(t *testing.T) { - testServices(t, db, []*library.Build{buildOne, buildTwo}, []*library.Service{serviceOne, serviceTwo}) - }) + t.Run("test_services", func(t *testing.T) { testServices(t, db, resources) }) - t.Run("test_steps", func(t *testing.T) { - testSteps(t, db, []*library.Build{buildOne, buildTwo}, []*library.Step{stepOne, stepTwo}) - }) + t.Run("test_steps", func(t *testing.T) { testSteps(t, db, resources) }) - t.Run("test_users", func(t *testing.T) { - testUsers(t, db) - }) + t.Run("test_users", func(t *testing.T) { testUsers(t, db, resources) }) - t.Run("test_workers", func(t *testing.T) { - testWorkers(t, db) - }) + t.Run("test_workers", func(t *testing.T) { testWorkers(t, db, resources) }) err = db.Close() if err != nil { @@ -326,7 +132,7 @@ func TestDatabase_Integration(t *testing.T) { } } -func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*library.Repo) { +func testBuilds(t *testing.T, db Interface, resources *Resources) { // used to track the number of methods we call for builds // // we start at 2 for creating the table and indexes for builds @@ -334,7 +140,7 @@ func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*li counter := 2 // create the builds - for _, build := range builds { + for _, build := range resources.Builds { _, err := db.CreateBuild(build) if err != nil { t.Errorf("unable to create build %d: %v", build.GetID(), err) @@ -347,18 +153,18 @@ func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*li if err != nil { t.Errorf("unable to count builds: %v", err) } - if int(count) != len(builds) { - t.Errorf("CountBuilds() is %v, want %v", count, len(builds)) + if int(count) != len(resources.Builds) { + t.Errorf("CountBuilds() is %v, want %v", count, len(resources.Builds)) } counter++ // count the builds for a repo - count, err = db.CountBuildsForRepo(repos[0], nil) + count, err = db.CountBuildsForRepo(resources.Repos[0], nil) if err != nil { - t.Errorf("unable to count builds for repo %s: %v", repos[0].GetFullName(), err) + t.Errorf("unable to count builds for repo %d: %v", resources.Repos[0].GetID(), err) } - if int(count) != len(builds) { - t.Errorf("CountBuildsForRepo() is %v, want %v", count, len(builds)) + if int(count) != len(resources.Builds) { + t.Errorf("CountBuildsForRepo() is %v, want %v", count, len(resources.Builds)) } counter++ @@ -367,36 +173,37 @@ func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*li if err != nil { t.Errorf("unable to list builds: %v", err) } - if !reflect.DeepEqual(list, builds) { - t.Errorf("ListBuilds() is %v, want %v", list, builds) + if !reflect.DeepEqual(list, resources.Builds) { + t.Errorf("ListBuilds() is %v, want %v", list, resources.Builds) } counter++ // list the builds for a repo - list, count, err = db.ListBuildsForRepo(repos[0], nil, time.Now().UTC().Unix(), 0, 1, 10) + list, count, err = db.ListBuildsForRepo(resources.Repos[0], nil, time.Now().UTC().Unix(), 0, 1, 10) if err != nil { - t.Errorf("unable to list builds for repo %s: %v", repos[0].GetFullName(), err) + t.Errorf("unable to list builds for repo %d: %v", resources.Repos[0].GetID(), err) } - if !reflect.DeepEqual(list, []*library.Build{builds[1], builds[0]}) { - t.Errorf("ListBuildsForRepo() is %v, want %v", list, []*library.Build{builds[1], builds[0]}) + if !reflect.DeepEqual(list, []*library.Build{resources.Builds[1], resources.Builds[0]}) { + t.Errorf("ListBuildsForRepo() is %v, want %v", list, []*library.Build{resources.Builds[1], resources.Builds[0]}) } counter++ // lookup the last build by repo - got, err := db.LastBuildForRepo(repos[0], "main") + got, err := db.LastBuildForRepo(resources.Repos[0], "main") if err != nil { - t.Errorf("unable to get last build for repo %s: %v", repos[0].GetFullName(), err) + t.Errorf("unable to get last build for repo %d: %v", resources.Repos[0].GetID(), err) } - if !reflect.DeepEqual(got, builds[1]) { - t.Errorf("GetBuildForRepo() is %v, want %v", got, builds[1]) + if !reflect.DeepEqual(got, resources.Builds[1]) { + t.Errorf("GetBuildForRepo() is %v, want %v", got, resources.Builds[1]) } counter++ // lookup the builds by repo and number - for _, build := range builds { - got, err = db.GetBuildForRepo(repos[build.GetRepoID()-1], build.GetNumber()) + for _, build := range resources.Builds { + repo := resources.Repos[build.GetRepoID()-1] + got, err = db.GetBuildForRepo(repo, build.GetNumber()) if err != nil { - t.Errorf("unable to get build %d for repo %s: %v", build.GetID(), repos[0].GetFullName(), err) + t.Errorf("unable to get build %d for repo %d: %v", build.GetID(), repo.GetID(), err) } if !reflect.DeepEqual(got, build) { t.Errorf("GetBuildForRepo() is %v, want %v", got, build) @@ -405,7 +212,7 @@ func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*li counter++ // update the builds - for _, build := range builds { + for _, build := range resources.Builds { build.SetStatus("success") _, err = db.UpdateBuild(build) if err != nil { @@ -425,7 +232,7 @@ func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*li counter++ // delete the builds - for _, build := range builds { + for _, build := range resources.Builds { err = db.DeleteBuild(build) if err != nil { t.Errorf("unable to delete build %d: %v", build.GetID(), err) @@ -440,52 +247,18 @@ func testBuilds(t *testing.T, db Interface, builds []*library.Build, repos []*li } } -func testHooks(t *testing.T, db Interface, repos []*library.Repo) { +func testHooks(t *testing.T, db Interface, resources *Resources) { // used to track the number of methods we call for hooks // // we start at 2 for creating the table and indexes for hooks // since those are already called when the database engine starts counter := 2 - one := new(library.Hook) - one.SetID(1) - one.SetRepoID(1) - one.SetBuildID(1) - one.SetNumber(1) - one.SetSourceID("c8da1302-07d6-11ea-882f-4893bca275b8") - one.SetCreated(time.Now().UTC().Unix()) - one.SetHost("github.com") - one.SetEvent("push") - one.SetEventAction("") - one.SetBranch("master") - one.SetError("") - one.SetStatus("success") - one.SetLink("https://github.com/github/octocat/settings/hooks/1") - one.SetWebhookID(123456) - - two := new(library.Hook) - two.SetID(2) - two.SetRepoID(1) - two.SetBuildID(1) - two.SetNumber(2) - two.SetSourceID("c8da1302-07d6-11ea-882f-4893bca275b8") - two.SetCreated(time.Now().UTC().Unix()) - two.SetHost("github.com") - two.SetEvent("push") - two.SetEventAction("") - two.SetBranch("master") - two.SetError("") - two.SetStatus("success") - two.SetLink("https://github.com/github/octocat/settings/hooks/1") - two.SetWebhookID(123456) - - hooks := []*library.Hook{one, two} - // create the hooks - for _, hook := range hooks { + for _, hook := range resources.Hooks { _, err := db.CreateHook(hook) if err != nil { - t.Errorf("unable to create hook %s: %v", hook.GetSourceID(), err) + t.Errorf("unable to create hook %d: %v", hook.GetID(), err) } } counter++ @@ -495,8 +268,8 @@ func testHooks(t *testing.T, db Interface, repos []*library.Repo) { if err != nil { t.Errorf("unable to count hooks: %v", err) } - if int(count) != len(hooks) { - t.Errorf("CountHooks() is %v, want %v", count, len(hooks)) + if int(count) != len(resources.Hooks) { + t.Errorf("CountHooks() is %v, want %v", count, len(resources.Hooks)) } counter++ @@ -505,16 +278,17 @@ func testHooks(t *testing.T, db Interface, repos []*library.Repo) { if err != nil { t.Errorf("unable to list hooks: %v", err) } - if !reflect.DeepEqual(list, hooks) { - t.Errorf("ListHooks() is %v, want %v", list, hooks) + if !reflect.DeepEqual(list, resources.Hooks) { + t.Errorf("ListHooks() is %v, want %v", list, resources.Hooks) } counter++ // lookup the hooks by name - for _, hook := range hooks { - got, err := db.GetHookForRepo(repos[0], hook.GetNumber()) + for _, hook := range resources.Hooks { + repo := resources.Repos[hook.GetRepoID()-1] + got, err := db.GetHookForRepo(repo, hook.GetNumber()) if err != nil { - t.Errorf("unable to get hook %s for repo %s: %v", hook.GetSourceID(), repos[0].GetFullName(), err) + t.Errorf("unable to get hook %d for repo %d: %v", hook.GetID(), repo.GetID(), err) } if !reflect.DeepEqual(got, hook) { t.Errorf("GetHookForRepo() is %v, want %v", got, hook) @@ -523,17 +297,17 @@ func testHooks(t *testing.T, db Interface, repos []*library.Repo) { counter++ // update the hooks - for _, hook := range hooks { + for _, hook := range resources.Hooks { hook.SetStatus("success") _, err = db.UpdateHook(hook) if err != nil { - t.Errorf("unable to update hook %s: %v", hook.GetSourceID(), err) + t.Errorf("unable to update hook %d: %v", hook.GetID(), err) } // lookup the hook by ID got, err := db.GetHook(hook.GetID()) if err != nil { - t.Errorf("unable to get hook %s by ID: %v", hook.GetSourceID(), err) + t.Errorf("unable to get hook %d by ID: %v", hook.GetID(), err) } if !reflect.DeepEqual(got, hook) { t.Errorf("GetHook() is %v, want %v", got, hook) @@ -543,10 +317,10 @@ func testHooks(t *testing.T, db Interface, repos []*library.Repo) { counter++ // delete the hooks - for _, hook := range hooks { + for _, hook := range resources.Hooks { err = db.DeleteHook(hook) if err != nil { - t.Errorf("unable to delete hook %s: %v", hook.GetSourceID(), err) + t.Errorf("unable to delete hook %d: %v", hook.GetID(), err) } } counter++ @@ -558,53 +332,15 @@ func testHooks(t *testing.T, db Interface, repos []*library.Repo) { } } -func testLogs(t *testing.T, db Interface, services []*library.Service, steps []*library.Step) { +func testLogs(t *testing.T, db Interface, resources *Resources) { // used to track the number of methods we call for logs // // we start at 2 for creating the table and indexes for logs // since those are already called when the database engine starts counter := 2 - serviceOne := new(library.Log) - serviceOne.SetID(1) - serviceOne.SetBuildID(1) - serviceOne.SetRepoID(1) - serviceOne.SetServiceID(1) - serviceOne.SetStepID(0) - serviceOne.SetData([]byte("foo")) - - serviceTwo := new(library.Log) - serviceTwo.SetID(2) - serviceTwo.SetBuildID(1) - serviceTwo.SetRepoID(1) - serviceTwo.SetServiceID(2) - serviceTwo.SetStepID(0) - serviceTwo.SetData([]byte("foo")) - - serviceLogs := []*library.Log{serviceOne, serviceTwo} - - stepOne := new(library.Log) - stepOne.SetID(3) - stepOne.SetBuildID(1) - stepOne.SetRepoID(1) - stepOne.SetServiceID(0) - stepOne.SetStepID(1) - stepOne.SetData([]byte("foo")) - - stepTwo := new(library.Log) - stepTwo.SetID(4) - stepTwo.SetBuildID(1) - stepTwo.SetRepoID(1) - stepTwo.SetServiceID(0) - stepTwo.SetStepID(2) - stepTwo.SetData([]byte("foo")) - - stepLogs := []*library.Log{stepOne, stepTwo} - - logs := append(serviceLogs, stepLogs...) - // create the logs - for _, log := range logs { + for _, log := range resources.Logs { err := db.CreateLog(log) if err != nil { t.Errorf("unable to create log %d: %v", log.GetID(), err) @@ -617,8 +353,8 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* if err != nil { t.Errorf("unable to count logs: %v", err) } - if int(count) != len(logs) { - t.Errorf("CountLogs() is %v, want %v", count, len(logs)) + if int(count) != len(resources.Logs) { + t.Errorf("CountLogs() is %v, want %v", count, len(resources.Logs)) } counter++ @@ -627,16 +363,17 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* if err != nil { t.Errorf("unable to list logs: %v", err) } - if !reflect.DeepEqual(list, logs) { - t.Errorf("ListLogs() is %v, want %v", list, logs) + if !reflect.DeepEqual(list, resources.Logs) { + t.Errorf("ListLogs() is %v, want %v", list, resources.Logs) } counter++ // lookup the logs by service - for _, log := range serviceLogs { - got, err := db.GetLogForService(services[log.GetServiceID()-1]) + for _, log := range []*library.Log{resources.Logs[0], resources.Logs[1]} { + service := resources.Services[log.GetServiceID()-1] + got, err := db.GetLogForService(service) if err != nil { - t.Errorf("unable to get log %d for service %d: %v", log.GetID(), services[0].GetID(), err) + t.Errorf("unable to get log %d for service %d: %v", log.GetID(), service.GetID(), err) } if !reflect.DeepEqual(got, log) { t.Errorf("GetLogForService() is %v, want %v", got, log) @@ -645,10 +382,11 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* counter++ // lookup the logs by service - for _, log := range stepLogs { - got, err := db.GetLogForStep(steps[log.GetStepID()-1]) + for _, log := range []*library.Log{resources.Logs[2], resources.Logs[3]} { + step := resources.Steps[log.GetStepID()-1] + got, err := db.GetLogForStep(step) if err != nil { - t.Errorf("unable to get log %d for step %d: %v", log.GetID(), steps[0].GetID(), err) + t.Errorf("unable to get log %d for step %d: %v", log.GetID(), step.GetID(), err) } if !reflect.DeepEqual(got, log) { t.Errorf("GetLogForStep() is %v, want %v", got, log) @@ -657,7 +395,7 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* counter++ // update the logs - for _, log := range logs { + for _, log := range resources.Logs { log.SetData([]byte("bar")) err = db.UpdateLog(log) if err != nil { @@ -677,7 +415,7 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* counter++ // delete the logs - for _, log := range logs { + for _, log := range resources.Logs { err = db.DeleteLog(log) if err != nil { t.Errorf("unable to delete log %d: %v", log.GetID(), err) @@ -692,54 +430,18 @@ func testLogs(t *testing.T, db Interface, services []*library.Service, steps []* } } -func testPipelines(t *testing.T, db Interface, repos []*library.Repo) { +func testPipelines(t *testing.T, db Interface, resources *Resources) { // used to track the number of methods we call for pipelines // // we start at 2 for creating the table and indexes for pipelines // since those are already called when the database engine starts counter := 2 - one := new(library.Pipeline) - one.SetID(1) - one.SetRepoID(1) - one.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") - one.SetFlavor("large") - one.SetPlatform("docker") - one.SetRef("refs/heads/master") - one.SetType("yaml") - one.SetVersion("1") - one.SetExternalSecrets(false) - one.SetInternalSecrets(false) - one.SetServices(true) - one.SetStages(false) - one.SetSteps(true) - one.SetTemplates(false) - one.SetData([]byte("version: 1")) - - two := new(library.Pipeline) - two.SetID(2) - two.SetRepoID(1) - two.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135164") - two.SetFlavor("large") - two.SetPlatform("docker") - two.SetRef("refs/heads/master") - two.SetType("yaml") - two.SetVersion("1") - two.SetExternalSecrets(false) - two.SetInternalSecrets(false) - two.SetServices(true) - two.SetStages(false) - two.SetSteps(true) - two.SetTemplates(false) - two.SetData([]byte("version: 1")) - - pipelines := []*library.Pipeline{one, two} - // create the pipelines - for _, pipeline := range pipelines { + for _, pipeline := range resources.Pipelines { _, err := db.CreatePipeline(pipeline) if err != nil { - t.Errorf("unable to create pipeline %s: %v", pipeline.GetCommit(), err) + t.Errorf("unable to create pipeline %d: %v", pipeline.GetID(), err) } } counter++ @@ -749,8 +451,8 @@ func testPipelines(t *testing.T, db Interface, repos []*library.Repo) { if err != nil { t.Errorf("unable to count pipelines: %v", err) } - if int(count) != len(pipelines) { - t.Errorf("CountPipelines() is %v, want %v", count, len(pipelines)) + if int(count) != len(resources.Pipelines) { + t.Errorf("CountPipelines() is %v, want %v", count, len(resources.Pipelines)) } counter++ @@ -759,16 +461,17 @@ func testPipelines(t *testing.T, db Interface, repos []*library.Repo) { if err != nil { t.Errorf("unable to list pipelines: %v", err) } - if !reflect.DeepEqual(list, pipelines) { - t.Errorf("ListPipelines() is %v, want %v", list, pipelines) + if !reflect.DeepEqual(list, resources.Pipelines) { + t.Errorf("ListPipelines() is %v, want %v", list, resources.Pipelines) } counter++ // lookup the pipelines by name - for _, pipeline := range pipelines { - got, err := db.GetPipelineForRepo(pipeline.GetCommit(), repos[0]) + for _, pipeline := range resources.Pipelines { + repo := resources.Repos[pipeline.GetRepoID()-1] + got, err := db.GetPipelineForRepo(pipeline.GetCommit(), repo) if err != nil { - t.Errorf("unable to get pipeline %s for repo %s: %v", pipeline.GetCommit(), repos[0].GetFullName(), err) + t.Errorf("unable to get pipeline %d for repo %d: %v", pipeline.GetID(), repo.GetID(), err) } if !reflect.DeepEqual(got, pipeline) { t.Errorf("GetPipelineForRepo() is %v, want %v", got, pipeline) @@ -777,17 +480,17 @@ func testPipelines(t *testing.T, db Interface, repos []*library.Repo) { counter++ // update the pipelines - for _, pipeline := range pipelines { + for _, pipeline := range resources.Pipelines { pipeline.SetVersion("2") _, err = db.UpdatePipeline(pipeline) if err != nil { - t.Errorf("unable to update pipeline %s: %v", pipeline.GetCommit(), err) + t.Errorf("unable to update pipeline %d: %v", pipeline.GetID(), err) } // lookup the pipeline by ID got, err := db.GetPipeline(pipeline.GetID()) if err != nil { - t.Errorf("unable to get pipeline %s by ID: %v", pipeline.GetCommit(), err) + t.Errorf("unable to get pipeline %d by ID: %v", pipeline.GetID(), err) } if !reflect.DeepEqual(got, pipeline) { t.Errorf("GetPipeline() is %v, want %v", got, pipeline) @@ -797,10 +500,10 @@ func testPipelines(t *testing.T, db Interface, repos []*library.Repo) { counter++ // delete the pipelines - for _, pipeline := range pipelines { + for _, pipeline := range resources.Pipelines { err = db.DeletePipeline(pipeline) if err != nil { - t.Errorf("unable to delete pipeline %s: %v", pipeline.GetCommit(), err) + t.Errorf("unable to delete pipeline %d: %v", pipeline.GetID(), err) } } counter++ @@ -812,7 +515,7 @@ func testPipelines(t *testing.T, db Interface, repos []*library.Repo) { } } -func testRepos(t *testing.T, db Interface, repos []*library.Repo) { +func testRepos(t *testing.T, db Interface, resources *Resources) { // used to track the number of methods we call for repos // // we start at 2 for creating the table and indexes for repos @@ -820,10 +523,10 @@ func testRepos(t *testing.T, db Interface, repos []*library.Repo) { counter := 2 // create the repos - for _, repo := range repos { + for _, repo := range resources.Repos { err := db.CreateRepo(repo) if err != nil { - t.Errorf("unable to create repo %s: %v", repo.GetFullName(), err) + t.Errorf("unable to create repo %d: %v", repo.GetID(), err) } } counter++ @@ -833,8 +536,8 @@ func testRepos(t *testing.T, db Interface, repos []*library.Repo) { if err != nil { t.Errorf("unable to count repos: %v", err) } - if int(count) != len(repos) { - t.Errorf("CountRepos() is %v, want %v", count, len(repos)) + if int(count) != len(resources.Repos) { + t.Errorf("CountRepos() is %v, want %v", count, len(resources.Repos)) } counter++ @@ -843,16 +546,16 @@ func testRepos(t *testing.T, db Interface, repos []*library.Repo) { if err != nil { t.Errorf("unable to list repos: %v", err) } - if !reflect.DeepEqual(list, repos) { - t.Errorf("ListRepos() is %v, want %v", list, repos) + if !reflect.DeepEqual(list, resources.Repos) { + t.Errorf("ListRepos() is %v, want %v", list, resources.Repos) } counter++ // lookup the repos by name - for _, repo := range repos { + for _, repo := range resources.Repos { got, err := db.GetRepoForOrg(repo.GetOrg(), repo.GetName()) if err != nil { - t.Errorf("unable to get repo %s by org: %v", repo.GetFullName(), err) + t.Errorf("unable to get repo %d by org: %v", repo.GetID(), err) } if !reflect.DeepEqual(got, repo) { t.Errorf("GetRepoForOrg() is %v, want %v", got, repo) @@ -861,17 +564,17 @@ func testRepos(t *testing.T, db Interface, repos []*library.Repo) { counter++ // update the repos - for _, repo := range repos { + for _, repo := range resources.Repos { repo.SetActive(false) err = db.UpdateRepo(repo) if err != nil { - t.Errorf("unable to update repo %s: %v", repo.GetFullName(), err) + t.Errorf("unable to update repo %d: %v", repo.GetID(), err) } // lookup the repo by ID got, err := db.GetRepo(repo.GetID()) if err != nil { - t.Errorf("unable to get repo %s by ID: %v", repo.GetFullName(), err) + t.Errorf("unable to get repo %d by ID: %v", repo.GetID(), err) } if !reflect.DeepEqual(got, repo) { t.Errorf("GetRepo() is %v, want %v", got, repo) @@ -881,10 +584,10 @@ func testRepos(t *testing.T, db Interface, repos []*library.Repo) { counter++ // delete the repos - for _, repo := range repos { + for _, repo := range resources.Repos { err = db.DeleteRepo(repo) if err != nil { - t.Errorf("unable to delete repo %s: %v", repo.GetFullName(), err) + t.Errorf("unable to delete repo %d: %v", repo.GetID(), err) } } counter++ @@ -896,44 +599,18 @@ func testRepos(t *testing.T, db Interface, repos []*library.Repo) { } } -func testSchedules(t *testing.T, db Interface, repos []*library.Repo) { +func testSchedules(t *testing.T, db Interface, resources *Resources) { // used to track the number of methods we call for schedules // // we start at 2 for creating the table and indexes for schedules // since those are already called when the database engine starts counter := 2 - one := new(library.Schedule) - one.SetID(1) - one.SetRepoID(1) - one.SetActive(true) - one.SetName("nightly") - one.SetEntry("0 0 * * *") - one.SetCreatedAt(time.Now().UTC().Unix()) - one.SetCreatedBy("octocat") - one.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix()) - one.SetUpdatedBy("octokitty") - one.SetScheduledAt(time.Now().Add(time.Hour * 2).UTC().Unix()) - - two := new(library.Schedule) - two.SetID(2) - two.SetRepoID(1) - two.SetActive(true) - two.SetName("hourly") - two.SetEntry("0 * * * *") - two.SetCreatedAt(time.Now().UTC().Unix()) - two.SetCreatedBy("octocat") - two.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix()) - two.SetUpdatedBy("octokitty") - two.SetScheduledAt(time.Now().Add(time.Hour * 2).UTC().Unix()) - - schedules := []*library.Schedule{one, two} - // create the schedules - for _, schedule := range schedules { + for _, schedule := range resources.Schedules { err := db.CreateSchedule(schedule) if err != nil { - t.Errorf("unable to create schedule %s: %v", schedule.GetName(), err) + t.Errorf("unable to create schedule %d: %v", schedule.GetID(), err) } } counter++ @@ -943,8 +620,8 @@ func testSchedules(t *testing.T, db Interface, repos []*library.Repo) { if err != nil { t.Errorf("unable to count schedules: %v", err) } - if int(count) != len(schedules) { - t.Errorf("CountSchedules() is %v, want %v", count, len(schedules)) + if int(count) != len(resources.Schedules) { + t.Errorf("CountSchedules() is %v, want %v", count, len(resources.Schedules)) } counter++ @@ -953,16 +630,17 @@ func testSchedules(t *testing.T, db Interface, repos []*library.Repo) { if err != nil { t.Errorf("unable to list schedules: %v", err) } - if !reflect.DeepEqual(list, schedules) { - t.Errorf("ListSchedules() is %v, want %v", list, schedules) + if !reflect.DeepEqual(list, resources.Schedules) { + t.Errorf("ListSchedules() is %v, want %v", list, resources.Schedules) } counter++ // lookup the schedules by name - for _, schedule := range schedules { - got, err := db.GetScheduleForRepo(repos[0], schedule.GetName()) + for _, schedule := range resources.Schedules { + repo := resources.Repos[schedule.GetRepoID()-1] + got, err := db.GetScheduleForRepo(repo, schedule.GetName()) if err != nil { - t.Errorf("unable to get schedule %s for repo %s: %v", schedule.GetName(), repos[0].GetFullName(), err) + t.Errorf("unable to get schedule %d for repo %d: %v", schedule.GetID(), repo.GetID(), err) } if !reflect.DeepEqual(got, schedule) { t.Errorf("GetScheduleForRepo() is %v, want %v", got, schedule) @@ -971,17 +649,17 @@ func testSchedules(t *testing.T, db Interface, repos []*library.Repo) { counter++ // update the schedules - for _, schedule := range schedules { + for _, schedule := range resources.Schedules { schedule.SetActive(false) err = db.UpdateSchedule(schedule, false) if err != nil { - t.Errorf("unable to update schedule %s: %v", schedule.GetName(), err) + t.Errorf("unable to update schedule %d: %v", schedule.GetID(), err) } // lookup the schedule by ID got, err := db.GetSchedule(schedule.GetID()) if err != nil { - t.Errorf("unable to get schedule %s by ID: %v", schedule.GetName(), err) + t.Errorf("unable to get schedule %d by ID: %v", schedule.GetID(), err) } if !reflect.DeepEqual(got, schedule) { t.Errorf("GetSchedule() is %v, want %v", got, schedule) @@ -991,10 +669,10 @@ func testSchedules(t *testing.T, db Interface, repos []*library.Repo) { counter++ // delete the schedules - for _, schedule := range schedules { + for _, schedule := range resources.Schedules { err = db.DeleteSchedule(schedule) if err != nil { - t.Errorf("unable to delete schedule %s: %v", schedule.GetName(), err) + t.Errorf("unable to delete schedule %d: %v", schedule.GetID(), err) } } counter++ @@ -1006,52 +684,18 @@ func testSchedules(t *testing.T, db Interface, repos []*library.Repo) { } } -func testSecrets(t *testing.T, db Interface, repos []*library.Repo) { +func testSecrets(t *testing.T, db Interface, resources *Resources) { // used to track the number of methods we call for secrets // // we start at 2 for creating the table and indexes for secrets // since those are already called when the database engine starts counter := 2 - one := new(library.Secret) - one.SetID(1) - one.SetOrg("github") - one.SetRepo("octocat") - one.SetTeam("") - one.SetName("foo") - one.SetValue("bar") - one.SetType("repo") - one.SetImages([]string{"alpine"}) - one.SetEvents([]string{"push", "tag", "deployment"}) - one.SetAllowCommand(true) - one.SetCreatedAt(time.Now().UTC().Unix()) - one.SetCreatedBy("octocat") - one.SetUpdatedAt(time.Now().UTC().Unix()) - one.SetUpdatedBy("octokitty") - - two := new(library.Secret) - two.SetID(2) - two.SetOrg("github") - two.SetRepo("octocat") - two.SetTeam("") - two.SetName("bar") - two.SetValue("baz") - two.SetType("repo") - two.SetImages([]string{"alpine"}) - two.SetEvents([]string{"push", "tag", "deployment"}) - two.SetAllowCommand(true) - two.SetCreatedAt(time.Now().UTC().Unix()) - two.SetCreatedBy("octocat") - two.SetUpdatedAt(time.Now().UTC().Unix()) - two.SetUpdatedBy("octokitty") - - secrets := []*library.Secret{one, two} - // create the secrets - for _, secret := range secrets { + for _, secret := range resources.Secrets { err := db.CreateSecret(secret) if err != nil { - t.Errorf("unable to create secret %s: %v", secret.GetName(), err) + t.Errorf("unable to create secret %d: %v", secret.GetID(), err) } } counter++ @@ -1061,8 +705,8 @@ func testSecrets(t *testing.T, db Interface, repos []*library.Repo) { if err != nil { t.Errorf("unable to count secrets: %v", err) } - if int(count) != len(secrets) { - t.Errorf("CountSecrets() is %v, want %v", count, len(secrets)) + if int(count) != len(resources.Secrets) { + t.Errorf("CountSecrets() is %v, want %v", count, len(resources.Secrets)) } counter++ @@ -1071,16 +715,16 @@ func testSecrets(t *testing.T, db Interface, repos []*library.Repo) { if err != nil { t.Errorf("unable to list secrets: %v", err) } - if !reflect.DeepEqual(list, secrets) { - t.Errorf("ListSecrets() is %v, want %v", list, secrets) + if !reflect.DeepEqual(list, resources.Secrets) { + t.Errorf("ListSecrets() is %v, want %v", list, resources.Secrets) } counter++ // lookup the secrets by name - for _, secret := range secrets { - got, err := db.GetSecretForRepo(secret.GetName(), repos[0]) + for _, secret := range resources.Secrets { + got, err := db.GetSecretForRepo(secret.GetName(), resources.Repos[0]) if err != nil { - t.Errorf("unable to get secret %s for repo %s: %v", secret.GetName(), repos[0].GetFullName(), err) + t.Errorf("unable to get secret %d for repo %d: %v", secret.GetID(), resources.Repos[0].GetID(), err) } if !reflect.DeepEqual(got, secret) { t.Errorf("GetSecretForRepo() is %v, want %v", got, secret) @@ -1089,17 +733,17 @@ func testSecrets(t *testing.T, db Interface, repos []*library.Repo) { counter++ // update the secrets - for _, secret := range secrets { + for _, secret := range resources.Secrets { secret.SetAllowCommand(false) err = db.UpdateSecret(secret) if err != nil { - t.Errorf("unable to update secret %s: %v", secret.GetName(), err) + t.Errorf("unable to update secret %d: %v", secret.GetID(), err) } // lookup the secret by ID got, err := db.GetSecret(secret.GetID()) if err != nil { - t.Errorf("unable to get secret %s by ID: %v", secret.GetName(), err) + t.Errorf("unable to get secret %d by ID: %v", secret.GetID(), err) } if !reflect.DeepEqual(got, secret) { t.Errorf("GetSecret() is %v, want %v", got, secret) @@ -1109,10 +753,10 @@ func testSecrets(t *testing.T, db Interface, repos []*library.Repo) { counter++ // delete the secrets - for _, secret := range secrets { + for _, secret := range resources.Secrets { err = db.DeleteSecret(secret) if err != nil { - t.Errorf("unable to delete secret %s: %v", secret.GetName(), err) + t.Errorf("unable to delete secret %d: %v", secret.GetID(), err) } } counter++ @@ -1124,7 +768,7 @@ func testSecrets(t *testing.T, db Interface, repos []*library.Repo) { } } -func testServices(t *testing.T, db Interface, builds []*library.Build, services []*library.Service) { +func testServices(t *testing.T, db Interface, resources *Resources) { // used to track the number of methods we call for services // // we start at 2 for creating the table and indexes for services @@ -1132,10 +776,10 @@ func testServices(t *testing.T, db Interface, builds []*library.Build, services counter := 2 // create the services - for _, service := range services { + for _, service := range resources.Services { err := db.CreateService(service) if err != nil { - t.Errorf("unable to create service %s: %v", service.GetName(), err) + t.Errorf("unable to create service %d: %v", service.GetID(), err) } } counter++ @@ -1145,18 +789,18 @@ func testServices(t *testing.T, db Interface, builds []*library.Build, services if err != nil { t.Errorf("unable to count services: %v", err) } - if int(count) != len(services) { - t.Errorf("CountServices() is %v, want %v", count, len(services)) + if int(count) != len(resources.Services) { + t.Errorf("CountServices() is %v, want %v", count, len(resources.Services)) } counter++ // count the services for a build - count, err = db.CountServicesForBuild(builds[0], nil) + count, err = db.CountServicesForBuild(resources.Builds[0], nil) if err != nil { - t.Errorf("unable to count services for build %d: %v", builds[0].GetID(), err) + t.Errorf("unable to count services for build %d: %v", resources.Builds[0].GetID(), err) } - if int(count) != len(services) { - t.Errorf("CountServicesForBuild() is %v, want %v", count, len(services)) + if int(count) != len(resources.Services) { + t.Errorf("CountServicesForBuild() is %v, want %v", count, len(resources.Services)) } counter++ @@ -1165,21 +809,21 @@ func testServices(t *testing.T, db Interface, builds []*library.Build, services if err != nil { t.Errorf("unable to list services: %v", err) } - if !reflect.DeepEqual(list, services) { - t.Errorf("ListServices() is %v, want %v", list, services) + if !reflect.DeepEqual(list, resources.Services) { + t.Errorf("ListServices() is %v, want %v", list, resources.Services) } counter++ // list the services for a build - list, count, err = db.ListServicesForBuild(builds[0], nil, 1, 10) + list, count, err = db.ListServicesForBuild(resources.Builds[0], nil, 1, 10) if err != nil { - t.Errorf("unable to list services for build %d: %v", builds[0].GetID(), err) + t.Errorf("unable to list services for build %d: %v", resources.Builds[0].GetID(), err) } - if !reflect.DeepEqual(list, []*library.Service{services[1], services[0]}) { - t.Errorf("ListServicesForBuild() is %v, want %v", list, []*library.Service{services[1], services[0]}) + if !reflect.DeepEqual(list, []*library.Service{resources.Services[1], resources.Services[0]}) { + t.Errorf("ListServicesForBuild() is %v, want %v", list, []*library.Service{resources.Services[1], resources.Services[0]}) } - if int(count) != len(services) { - t.Errorf("ListServicesForBuild() is %v, want %v", count, len(services)) + if int(count) != len(resources.Services) { + t.Errorf("ListServicesForBuild() is %v, want %v", count, len(resources.Services)) } counter++ @@ -1213,10 +857,11 @@ func testServices(t *testing.T, db Interface, builds []*library.Build, services counter++ // lookup the services by name - for _, service := range services { - got, err := db.GetServiceForBuild(builds[0], service.GetNumber()) + for _, service := range resources.Services { + build := resources.Builds[service.GetBuildID()-1] + got, err := db.GetServiceForBuild(build, service.GetNumber()) if err != nil { - t.Errorf("unable to get service %s for build %d: %v", service.GetName(), builds[0].GetID(), err) + t.Errorf("unable to get service %d for build %d: %v", service.GetID(), build.GetID(), err) } if !reflect.DeepEqual(got, service) { t.Errorf("GetServiceForBuild() is %v, want %v", got, service) @@ -1225,17 +870,17 @@ func testServices(t *testing.T, db Interface, builds []*library.Build, services counter++ // update the services - for _, service := range services { + for _, service := range resources.Services { service.SetStatus("success") err = db.UpdateService(service) if err != nil { - t.Errorf("unable to update service %s: %v", service.GetName(), err) + t.Errorf("unable to update service %d: %v", service.GetID(), err) } // lookup the service by ID got, err := db.GetService(service.GetID()) if err != nil { - t.Errorf("unable to get service %s by ID: %v", service.GetName(), err) + t.Errorf("unable to get service %d by ID: %v", service.GetID(), err) } if !reflect.DeepEqual(got, service) { t.Errorf("GetService() is %v, want %v", got, service) @@ -1245,10 +890,10 @@ func testServices(t *testing.T, db Interface, builds []*library.Build, services counter++ // delete the services - for _, service := range services { + for _, service := range resources.Services { err = db.DeleteService(service) if err != nil { - t.Errorf("unable to delete service %s: %v", service.GetName(), err) + t.Errorf("unable to delete service %d: %v", service.GetID(), err) } } counter++ @@ -1260,7 +905,7 @@ func testServices(t *testing.T, db Interface, builds []*library.Build, services } } -func testSteps(t *testing.T, db Interface, builds []*library.Build, steps []*library.Step) { +func testSteps(t *testing.T, db Interface, resources *Resources) { // used to track the number of methods we call for steps // // we start at 2 for creating the table and indexes for steps @@ -1268,10 +913,10 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build, steps []*lib counter := 2 // create the steps - for _, step := range steps { + for _, step := range resources.Steps { err := db.CreateStep(step) if err != nil { - t.Errorf("unable to create step %s: %v", step.GetName(), err) + t.Errorf("unable to create step %d: %v", step.GetID(), err) } } counter++ @@ -1281,18 +926,18 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build, steps []*lib if err != nil { t.Errorf("unable to count steps: %v", err) } - if int(count) != len(steps) { - t.Errorf("CountSteps() is %v, want %v", count, len(steps)) + if int(count) != len(resources.Steps) { + t.Errorf("CountSteps() is %v, want %v", count, len(resources.Steps)) } counter++ // count the steps for a build - count, err = db.CountStepsForBuild(builds[0], nil) + count, err = db.CountStepsForBuild(resources.Builds[0], nil) if err != nil { - t.Errorf("unable to count steps for build %d: %v", builds[0].GetID(), err) + t.Errorf("unable to count steps for build %d: %v", resources.Builds[0].GetID(), err) } - if int(count) != len(steps) { - t.Errorf("CountStepsForBuild() is %v, want %v", count, len(steps)) + if int(count) != len(resources.Steps) { + t.Errorf("CountStepsForBuild() is %v, want %v", count, len(resources.Steps)) } counter++ @@ -1301,21 +946,21 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build, steps []*lib if err != nil { t.Errorf("unable to list steps: %v", err) } - if !reflect.DeepEqual(list, steps) { - t.Errorf("ListSteps() is %v, want %v", list, steps) + if !reflect.DeepEqual(list, resources.Steps) { + t.Errorf("ListSteps() is %v, want %v", list, resources.Steps) } counter++ // list the steps for a build - list, count, err = db.ListStepsForBuild(builds[0], nil, 1, 10) + list, count, err = db.ListStepsForBuild(resources.Builds[0], nil, 1, 10) if err != nil { - t.Errorf("unable to list steps for build %d: %v", builds[0].GetID(), err) + t.Errorf("unable to list steps for build %d: %v", resources.Builds[0].GetID(), err) } - if !reflect.DeepEqual(list, []*library.Step{steps[1], steps[0]}) { - t.Errorf("ListStepsForBuild() is %v, want %v", list, []*library.Step{steps[1], steps[0]}) + if !reflect.DeepEqual(list, []*library.Step{resources.Steps[1], resources.Steps[0]}) { + t.Errorf("ListStepsForBuild() is %v, want %v", list, []*library.Step{resources.Steps[1], resources.Steps[0]}) } - if int(count) != len(steps) { - t.Errorf("ListStepsForBuild() is %v, want %v", count, len(steps)) + if int(count) != len(resources.Steps) { + t.Errorf("ListStepsForBuild() is %v, want %v", count, len(resources.Steps)) } counter++ @@ -1349,10 +994,11 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build, steps []*lib counter++ // lookup the steps by name - for _, step := range steps { - got, err := db.GetStepForBuild(builds[0], step.GetNumber()) + for _, step := range resources.Steps { + build := resources.Builds[step.GetBuildID()-1] + got, err := db.GetStepForBuild(build, step.GetNumber()) if err != nil { - t.Errorf("unable to get step %s for build %d: %v", step.GetName(), builds[0].GetID(), err) + t.Errorf("unable to get step %d for build %d: %v", step.GetID(), build.GetID(), err) } if !reflect.DeepEqual(got, step) { t.Errorf("GetStepForBuild() is %v, want %v", got, step) @@ -1361,17 +1007,17 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build, steps []*lib counter++ // update the steps - for _, step := range steps { + for _, step := range resources.Steps { step.SetStatus("success") err = db.UpdateStep(step) if err != nil { - t.Errorf("unable to update step %s: %v", step.GetName(), err) + t.Errorf("unable to update step %d: %v", step.GetID(), err) } // lookup the step by ID got, err := db.GetStep(step.GetID()) if err != nil { - t.Errorf("unable to get step %s by ID: %v", step.GetName(), err) + t.Errorf("unable to get step %d by ID: %v", step.GetID(), err) } if !reflect.DeepEqual(got, step) { t.Errorf("GetStep() is %v, want %v", got, step) @@ -1381,10 +1027,10 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build, steps []*lib counter++ // delete the steps - for _, step := range steps { + for _, step := range resources.Steps { err = db.DeleteStep(step) if err != nil { - t.Errorf("unable to delete step %s: %v", step.GetName(), err) + t.Errorf("unable to delete step %d: %v", step.GetID(), err) } } counter++ @@ -1396,35 +1042,13 @@ func testSteps(t *testing.T, db Interface, builds []*library.Build, steps []*lib } } -func testUsers(t *testing.T, db Interface) { +func testUsers(t *testing.T, db Interface, resources *Resources) { // used to track the number of methods we call for users // // we start at 2 for creating the table and indexes for users // since those are already called when the database engine starts counter := 2 - one := new(library.User) - one.SetID(1) - one.SetName("octocat") - one.SetToken("superSecretToken") - one.SetRefreshToken("superSecretRefreshToken") - one.SetHash("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy") - one.SetFavorites([]string{"github/octocat"}) - one.SetActive(true) - one.SetAdmin(false) - - two := new(library.User) - two.SetID(2) - two.SetName("octokitty") - two.SetToken("superSecretToken") - two.SetRefreshToken("superSecretRefreshToken") - two.SetHash("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy") - two.SetFavorites([]string{"github/octocat"}) - two.SetActive(true) - two.SetAdmin(false) - - users := []*library.User{one, two} - liteOne := new(library.User) liteOne.SetID(1) liteOne.SetName("octocat") @@ -1448,10 +1072,10 @@ func testUsers(t *testing.T, db Interface) { liteUsers := []*library.User{liteOne, liteTwo} // create the users - for _, user := range users { + for _, user := range resources.Users { err := db.CreateUser(user) if err != nil { - t.Errorf("unable to create user %s: %v", user.GetName(), err) + t.Errorf("unable to create user %d: %v", user.GetID(), err) } } counter++ @@ -1461,8 +1085,8 @@ func testUsers(t *testing.T, db Interface) { if err != nil { t.Errorf("unable to count users: %v", err) } - if int(count) != len(users) { - t.Errorf("CountUsers() is %v, want %v", count, len(users)) + if int(count) != len(resources.Users) { + t.Errorf("CountUsers() is %v, want %v", count, len(resources.Users)) } counter++ @@ -1471,8 +1095,8 @@ func testUsers(t *testing.T, db Interface) { if err != nil { t.Errorf("unable to list users: %v", err) } - if !reflect.DeepEqual(list, users) { - t.Errorf("ListUsers() is %v, want %v", list, users) + if !reflect.DeepEqual(list, resources.Users) { + t.Errorf("ListUsers() is %v, want %v", list, resources.Users) } counter++ @@ -1488,16 +1112,16 @@ func testUsers(t *testing.T, db Interface) { } t.Errorf("ListLiteUsers() is %v, want %v", list, liteUsers) } - if int(count) != len(users) { - t.Errorf("ListLiteUsers() is %v, want %v", count, len(users)) + if int(count) != len(liteUsers) { + t.Errorf("ListLiteUsers() is %v, want %v", count, len(liteUsers)) } counter++ // lookup the users by name - for _, user := range users { + for _, user := range resources.Users { got, err := db.GetUserForName(user.GetName()) if err != nil { - t.Errorf("unable to get user %s by name: %v", user.GetName(), err) + t.Errorf("unable to get user %d by name: %v", user.GetID(), err) } if !reflect.DeepEqual(got, user) { t.Errorf("GetUserForName() is %v, want %v", got, user) @@ -1506,17 +1130,17 @@ func testUsers(t *testing.T, db Interface) { counter++ // update the users - for _, user := range users { + for _, user := range resources.Users { user.SetActive(false) err = db.UpdateUser(user) if err != nil { - t.Errorf("unable to update user %s: %v", user.GetName(), err) + t.Errorf("unable to update user %d: %v", user.GetID(), err) } // lookup the user by ID got, err := db.GetUser(user.GetID()) if err != nil { - t.Errorf("unable to get user %s by ID: %v", user.GetName(), err) + t.Errorf("unable to get user %d by ID: %v", user.GetID(), err) } if !reflect.DeepEqual(got, user) { t.Errorf("GetUser() is %v, want %v", got, user) @@ -1526,10 +1150,10 @@ func testUsers(t *testing.T, db Interface) { counter++ // delete the users - for _, user := range users { + for _, user := range resources.Users { err = db.DeleteUser(user) if err != nil { - t.Errorf("unable to delete user %s: %v", user.GetName(), err) + t.Errorf("unable to delete user %d: %v", user.GetID(), err) } } counter++ @@ -1541,48 +1165,18 @@ func testUsers(t *testing.T, db Interface) { } } -func testWorkers(t *testing.T, db Interface) { +func testWorkers(t *testing.T, db Interface, resources *Resources) { // used to track the number of methods we call for workers // // we start at 2 for creating the table and indexes for users // since those are already called when the database engine starts counter := 2 - one := new(library.Worker) - one.SetID(1) - one.SetHostname("worker-1.example.com") - one.SetAddress("https://worker-1.example.com") - one.SetRoutes([]string{"vela"}) - one.SetActive(true) - one.SetStatus("available") - one.SetLastStatusUpdateAt(time.Now().UTC().Unix()) - one.SetRunningBuildIDs([]string{"12345"}) - one.SetLastBuildStartedAt(time.Now().UTC().Unix()) - one.SetLastBuildFinishedAt(time.Now().UTC().Unix()) - one.SetLastCheckedIn(time.Now().UTC().Unix()) - one.SetBuildLimit(1) - - two := new(library.Worker) - two.SetID(2) - two.SetHostname("worker-2.example.com") - two.SetAddress("https://worker-2.example.com") - two.SetRoutes([]string{"vela"}) - two.SetActive(true) - two.SetStatus("available") - two.SetLastStatusUpdateAt(time.Now().UTC().Unix()) - two.SetRunningBuildIDs([]string{"12345"}) - two.SetLastBuildStartedAt(time.Now().UTC().Unix()) - two.SetLastBuildFinishedAt(time.Now().UTC().Unix()) - two.SetLastCheckedIn(time.Now().UTC().Unix()) - two.SetBuildLimit(1) - - workers := []*library.Worker{one, two} - // create the workers - for _, worker := range workers { + for _, worker := range resources.Workers { err := db.CreateWorker(worker) if err != nil { - t.Errorf("unable to create worker %s: %v", worker.GetHostname(), err) + t.Errorf("unable to create worker %d: %v", worker.GetID(), err) } } counter++ @@ -1592,8 +1186,8 @@ func testWorkers(t *testing.T, db Interface) { if err != nil { t.Errorf("unable to count workers: %v", err) } - if int(count) != len(workers) { - t.Errorf("CountWorkers() is %v, want %v", count, len(workers)) + if int(count) != len(resources.Workers) { + t.Errorf("CountWorkers() is %v, want %v", count, len(resources.Workers)) } counter++ @@ -1602,16 +1196,16 @@ func testWorkers(t *testing.T, db Interface) { if err != nil { t.Errorf("unable to list workers: %v", err) } - if !reflect.DeepEqual(list, workers) { - t.Errorf("ListWorkers() is %v, want %v", list, workers) + if !reflect.DeepEqual(list, resources.Workers) { + t.Errorf("ListWorkers() is %v, want %v", list, resources.Workers) } counter++ // lookup the workers by hostname - for _, worker := range workers { + for _, worker := range resources.Workers { got, err := db.GetWorkerForHostname(worker.GetHostname()) if err != nil { - t.Errorf("unable to get worker %s by hostname: %v", worker.GetHostname(), err) + t.Errorf("unable to get worker %d by hostname: %v", worker.GetID(), err) } if !reflect.DeepEqual(got, worker) { t.Errorf("GetWorkerForHostname() is %v, want %v", got, worker) @@ -1620,17 +1214,17 @@ func testWorkers(t *testing.T, db Interface) { counter++ // update the workers - for _, worker := range workers { + for _, worker := range resources.Workers { worker.SetActive(false) err = db.UpdateWorker(worker) if err != nil { - t.Errorf("unable to update worker %s: %v", worker.GetHostname(), err) + t.Errorf("unable to update worker %d: %v", worker.GetID(), err) } // lookup the worker by ID got, err := db.GetWorker(worker.GetID()) if err != nil { - t.Errorf("unable to get worker %s by ID: %v", worker.GetHostname(), err) + t.Errorf("unable to get worker %d by ID: %v", worker.GetID(), err) } if !reflect.DeepEqual(got, worker) { t.Errorf("GetWorker() is %v, want %v", got, worker) @@ -1640,10 +1234,10 @@ func testWorkers(t *testing.T, db Interface) { counter++ // delete the workers - for _, worker := range workers { + for _, worker := range resources.Workers { err = db.DeleteWorker(worker) if err != nil { - t.Errorf("unable to delete worker %s: %v", worker.GetHostname(), err) + t.Errorf("unable to delete worker %d: %v", worker.GetID(), err) } } counter++ @@ -1654,3 +1248,409 @@ func testWorkers(t *testing.T, db Interface) { t.Errorf("total number of methods called is %v, want %v", counter, methods) } } + +func newResources() *Resources { + buildOne := new(library.Build) + buildOne.SetID(1) + buildOne.SetRepoID(1) + buildOne.SetPipelineID(1) + buildOne.SetNumber(1) + buildOne.SetParent(1) + buildOne.SetEvent("push") + buildOne.SetEventAction("") + buildOne.SetStatus("running") + buildOne.SetError("") + buildOne.SetEnqueued(1563474077) + buildOne.SetCreated(1563474076) + buildOne.SetStarted(1563474078) + buildOne.SetFinished(1563474079) + buildOne.SetDeploy("") + buildOne.SetDeployPayload(raw.StringSliceMap{"foo": "test1"}) + buildOne.SetClone("https://github.com/github/octocat.git") + buildOne.SetSource("https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135163") + buildOne.SetTitle("push received from https://github.com/github/octocat") + buildOne.SetMessage("First commit...") + buildOne.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") + buildOne.SetSender("OctoKitty") + buildOne.SetAuthor("OctoKitty") + buildOne.SetEmail("OctoKitty@github.com") + buildOne.SetLink("https://example.company.com/github/octocat/1") + buildOne.SetBranch("master") + buildOne.SetRef("refs/heads/master") + buildOne.SetBaseRef("") + buildOne.SetHeadRef("changes") + buildOne.SetHost("example.company.com") + buildOne.SetRuntime("docker") + buildOne.SetDistribution("linux") + + buildTwo := new(library.Build) + buildTwo.SetID(2) + buildTwo.SetRepoID(1) + buildTwo.SetPipelineID(1) + buildTwo.SetNumber(2) + buildTwo.SetParent(1) + buildTwo.SetEvent("pull_request") + buildTwo.SetEventAction("") + buildTwo.SetStatus("running") + buildTwo.SetError("") + buildTwo.SetEnqueued(1563474077) + buildTwo.SetCreated(1563474076) + buildTwo.SetStarted(1563474078) + buildTwo.SetFinished(1563474079) + buildTwo.SetDeploy("") + buildTwo.SetDeployPayload(raw.StringSliceMap{"foo": "test1"}) + buildTwo.SetClone("https://github.com/github/octocat.git") + buildTwo.SetSource("https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135164") + buildTwo.SetTitle("pull_request received from https://github.com/github/octocat") + buildTwo.SetMessage("Second commit...") + buildTwo.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135164") + buildTwo.SetSender("OctoKitty") + buildTwo.SetAuthor("OctoKitty") + buildTwo.SetEmail("OctoKitty@github.com") + buildTwo.SetLink("https://example.company.com/github/octocat/2") + buildTwo.SetBranch("master") + buildTwo.SetRef("refs/heads/master") + buildTwo.SetBaseRef("") + buildTwo.SetHeadRef("changes") + buildTwo.SetHost("example.company.com") + buildTwo.SetRuntime("docker") + buildTwo.SetDistribution("linux") + + hookOne := new(library.Hook) + hookOne.SetID(1) + hookOne.SetRepoID(1) + hookOne.SetBuildID(1) + hookOne.SetNumber(1) + hookOne.SetSourceID("c8da1302-07d6-11ea-882f-4893bca275b8") + hookOne.SetCreated(time.Now().UTC().Unix()) + hookOne.SetHost("github.com") + hookOne.SetEvent("push") + hookOne.SetEventAction("") + hookOne.SetBranch("master") + hookOne.SetError("") + hookOne.SetStatus("success") + hookOne.SetLink("https://github.com/github/octocat/settings/hooks/1") + hookOne.SetWebhookID(123456) + + hookTwo := new(library.Hook) + hookTwo.SetID(2) + hookTwo.SetRepoID(1) + hookTwo.SetBuildID(1) + hookTwo.SetNumber(2) + hookTwo.SetSourceID("c8da1302-07d6-11ea-882f-4893bca275b8") + hookTwo.SetCreated(time.Now().UTC().Unix()) + hookTwo.SetHost("github.com") + hookTwo.SetEvent("push") + hookTwo.SetEventAction("") + hookTwo.SetBranch("master") + hookTwo.SetError("") + hookTwo.SetStatus("success") + hookTwo.SetLink("https://github.com/github/octocat/settings/hooks/1") + hookTwo.SetWebhookID(123456) + + logServiceOne := new(library.Log) + logServiceOne.SetID(1) + logServiceOne.SetBuildID(1) + logServiceOne.SetRepoID(1) + logServiceOne.SetServiceID(1) + logServiceOne.SetStepID(0) + logServiceOne.SetData([]byte("foo")) + + logServiceTwo := new(library.Log) + logServiceTwo.SetID(2) + logServiceTwo.SetBuildID(1) + logServiceTwo.SetRepoID(1) + logServiceTwo.SetServiceID(2) + logServiceTwo.SetStepID(0) + logServiceTwo.SetData([]byte("foo")) + + logStepOne := new(library.Log) + logStepOne.SetID(3) + logStepOne.SetBuildID(1) + logStepOne.SetRepoID(1) + logStepOne.SetServiceID(0) + logStepOne.SetStepID(1) + logStepOne.SetData([]byte("foo")) + + logStepTwo := new(library.Log) + logStepTwo.SetID(4) + logStepTwo.SetBuildID(1) + logStepTwo.SetRepoID(1) + logStepTwo.SetServiceID(0) + logStepTwo.SetStepID(2) + logStepTwo.SetData([]byte("foo")) + + pipelineOne := new(library.Pipeline) + pipelineOne.SetID(1) + pipelineOne.SetRepoID(1) + pipelineOne.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") + pipelineOne.SetFlavor("large") + pipelineOne.SetPlatform("docker") + pipelineOne.SetRef("refs/heads/master") + pipelineOne.SetType("yaml") + pipelineOne.SetVersion("1") + pipelineOne.SetExternalSecrets(false) + pipelineOne.SetInternalSecrets(false) + pipelineOne.SetServices(true) + pipelineOne.SetStages(false) + pipelineOne.SetSteps(true) + pipelineOne.SetTemplates(false) + pipelineOne.SetData([]byte("version: 1")) + + pipelineTwo := new(library.Pipeline) + pipelineTwo.SetID(2) + pipelineTwo.SetRepoID(1) + pipelineTwo.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135164") + pipelineTwo.SetFlavor("large") + pipelineTwo.SetPlatform("docker") + pipelineTwo.SetRef("refs/heads/master") + pipelineTwo.SetType("yaml") + pipelineTwo.SetVersion("1") + pipelineTwo.SetExternalSecrets(false) + pipelineTwo.SetInternalSecrets(false) + pipelineTwo.SetServices(true) + pipelineTwo.SetStages(false) + pipelineTwo.SetSteps(true) + pipelineTwo.SetTemplates(false) + pipelineTwo.SetData([]byte("version: 1")) + + repoOne := new(library.Repo) + repoOne.SetID(1) + repoOne.SetUserID(1) + repoOne.SetHash("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy") + repoOne.SetOrg("github") + repoOne.SetName("octocat") + repoOne.SetFullName("github/octocat") + repoOne.SetLink("https://github.com/github/octocat") + repoOne.SetClone("https://github.com/github/octocat.git") + repoOne.SetBranch("main") + repoOne.SetTopics([]string{"cloud", "security"}) + repoOne.SetBuildLimit(10) + repoOne.SetTimeout(30) + repoOne.SetCounter(0) + repoOne.SetVisibility("public") + repoOne.SetPrivate(false) + repoOne.SetTrusted(false) + repoOne.SetActive(true) + repoOne.SetAllowPull(false) + repoOne.SetAllowPush(true) + repoOne.SetAllowDeploy(false) + repoOne.SetAllowTag(false) + repoOne.SetAllowComment(false) + repoOne.SetPipelineType("") + repoOne.SetPreviousName("") + + repoTwo := new(library.Repo) + repoTwo.SetID(2) + repoTwo.SetUserID(1) + repoTwo.SetHash("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy") + repoTwo.SetOrg("github") + repoTwo.SetName("octokitty") + repoTwo.SetFullName("github/octokitty") + repoTwo.SetLink("https://github.com/github/octokitty") + repoTwo.SetClone("https://github.com/github/octokitty.git") + repoTwo.SetBranch("master") + repoTwo.SetTopics([]string{"cloud", "security"}) + repoTwo.SetBuildLimit(10) + repoTwo.SetTimeout(30) + repoTwo.SetCounter(0) + repoTwo.SetVisibility("public") + repoTwo.SetPrivate(false) + repoTwo.SetTrusted(false) + repoTwo.SetActive(true) + repoTwo.SetAllowPull(false) + repoTwo.SetAllowPush(true) + repoTwo.SetAllowDeploy(false) + repoTwo.SetAllowTag(false) + repoTwo.SetAllowComment(false) + repoTwo.SetPipelineType("") + repoTwo.SetPreviousName("") + + scheduleOne := new(library.Schedule) + scheduleOne.SetID(1) + scheduleOne.SetRepoID(1) + scheduleOne.SetActive(true) + scheduleOne.SetName("nightly") + scheduleOne.SetEntry("0 0 * * *") + scheduleOne.SetCreatedAt(time.Now().UTC().Unix()) + scheduleOne.SetCreatedBy("octocat") + scheduleOne.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix()) + scheduleOne.SetUpdatedBy("octokitty") + scheduleOne.SetScheduledAt(time.Now().Add(time.Hour * 2).UTC().Unix()) + + scheduleTwo := new(library.Schedule) + scheduleTwo.SetID(2) + scheduleTwo.SetRepoID(1) + scheduleTwo.SetActive(true) + scheduleTwo.SetName("hourly") + scheduleTwo.SetEntry("0 * * * *") + scheduleTwo.SetCreatedAt(time.Now().UTC().Unix()) + scheduleTwo.SetCreatedBy("octocat") + scheduleTwo.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix()) + scheduleTwo.SetUpdatedBy("octokitty") + scheduleTwo.SetScheduledAt(time.Now().Add(time.Hour * 2).UTC().Unix()) + + secretOne := new(library.Secret) + secretOne.SetID(1) + secretOne.SetOrg("github") + secretOne.SetRepo("octocat") + secretOne.SetTeam("") + secretOne.SetName("foo") + secretOne.SetValue("bar") + secretOne.SetType("repo") + secretOne.SetImages([]string{"alpine"}) + secretOne.SetEvents([]string{"push", "tag", "deployment"}) + secretOne.SetAllowCommand(true) + secretOne.SetCreatedAt(time.Now().UTC().Unix()) + secretOne.SetCreatedBy("octocat") + secretOne.SetUpdatedAt(time.Now().UTC().Unix()) + secretOne.SetUpdatedBy("octokitty") + + secretTwo := new(library.Secret) + secretTwo.SetID(2) + secretTwo.SetOrg("github") + secretTwo.SetRepo("octocat") + secretTwo.SetTeam("") + secretTwo.SetName("bar") + secretTwo.SetValue("baz") + secretTwo.SetType("repo") + secretTwo.SetImages([]string{"alpine"}) + secretTwo.SetEvents([]string{"push", "tag", "deployment"}) + secretTwo.SetAllowCommand(true) + secretTwo.SetCreatedAt(time.Now().UTC().Unix()) + secretTwo.SetCreatedBy("octocat") + secretTwo.SetUpdatedAt(time.Now().UTC().Unix()) + secretTwo.SetUpdatedBy("octokitty") + + serviceOne := new(library.Service) + serviceOne.SetID(1) + serviceOne.SetBuildID(1) + serviceOne.SetRepoID(1) + serviceOne.SetNumber(1) + serviceOne.SetName("init") + serviceOne.SetImage("#init") + serviceOne.SetStatus("running") + serviceOne.SetError("") + serviceOne.SetExitCode(0) + serviceOne.SetCreated(1563474076) + serviceOne.SetStarted(1563474078) + serviceOne.SetFinished(1563474079) + serviceOne.SetHost("example.company.com") + serviceOne.SetRuntime("docker") + serviceOne.SetDistribution("linux") + + serviceTwo := new(library.Service) + serviceTwo.SetID(2) + serviceTwo.SetBuildID(1) + serviceTwo.SetRepoID(1) + serviceTwo.SetNumber(2) + serviceTwo.SetName("clone") + serviceTwo.SetImage("target/vela-git:v0.3.0") + serviceTwo.SetStatus("pending") + serviceTwo.SetError("") + serviceTwo.SetExitCode(0) + serviceTwo.SetCreated(1563474086) + serviceTwo.SetStarted(1563474088) + serviceTwo.SetFinished(1563474089) + serviceTwo.SetHost("example.company.com") + serviceTwo.SetRuntime("docker") + serviceTwo.SetDistribution("linux") + + stepOne := new(library.Step) + stepOne.SetID(1) + stepOne.SetBuildID(1) + stepOne.SetRepoID(1) + stepOne.SetNumber(1) + stepOne.SetName("init") + stepOne.SetImage("#init") + stepOne.SetStage("init") + stepOne.SetStatus("running") + stepOne.SetError("") + stepOne.SetExitCode(0) + stepOne.SetCreated(1563474076) + stepOne.SetStarted(1563474078) + stepOne.SetFinished(1563474079) + stepOne.SetHost("example.company.com") + stepOne.SetRuntime("docker") + stepOne.SetDistribution("linux") + + stepTwo := new(library.Step) + stepTwo.SetID(2) + stepTwo.SetBuildID(1) + stepTwo.SetRepoID(1) + stepTwo.SetNumber(2) + stepTwo.SetName("clone") + stepTwo.SetImage("target/vela-git:v0.3.0") + stepTwo.SetStage("init") + stepTwo.SetStatus("pending") + stepTwo.SetError("") + stepTwo.SetExitCode(0) + stepTwo.SetCreated(1563474086) + stepTwo.SetStarted(1563474088) + stepTwo.SetFinished(1563474089) + stepTwo.SetHost("example.company.com") + stepTwo.SetRuntime("docker") + stepTwo.SetDistribution("linux") + + userOne := new(library.User) + userOne.SetID(1) + userOne.SetName("octocat") + userOne.SetToken("superSecretToken") + userOne.SetRefreshToken("superSecretRefreshToken") + userOne.SetHash("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy") + userOne.SetFavorites([]string{"github/octocat"}) + userOne.SetActive(true) + userOne.SetAdmin(false) + + userTwo := new(library.User) + userTwo.SetID(2) + userTwo.SetName("octokitty") + userTwo.SetToken("superSecretToken") + userTwo.SetRefreshToken("superSecretRefreshToken") + userTwo.SetHash("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy") + userTwo.SetFavorites([]string{"github/octocat"}) + userTwo.SetActive(true) + userTwo.SetAdmin(false) + + workerOne := new(library.Worker) + workerOne.SetID(1) + workerOne.SetHostname("worker-1.example.com") + workerOne.SetAddress("https://worker-1.example.com") + workerOne.SetRoutes([]string{"vela"}) + workerOne.SetActive(true) + workerOne.SetStatus("available") + workerOne.SetLastStatusUpdateAt(time.Now().UTC().Unix()) + workerOne.SetRunningBuildIDs([]string{"12345"}) + workerOne.SetLastBuildStartedAt(time.Now().UTC().Unix()) + workerOne.SetLastBuildFinishedAt(time.Now().UTC().Unix()) + workerOne.SetLastCheckedIn(time.Now().UTC().Unix()) + workerOne.SetBuildLimit(1) + + workerTwo := new(library.Worker) + workerTwo.SetID(2) + workerTwo.SetHostname("worker-2.example.com") + workerTwo.SetAddress("https://worker-2.example.com") + workerTwo.SetRoutes([]string{"vela"}) + workerTwo.SetActive(true) + workerTwo.SetStatus("available") + workerTwo.SetLastStatusUpdateAt(time.Now().UTC().Unix()) + workerTwo.SetRunningBuildIDs([]string{"12345"}) + workerTwo.SetLastBuildStartedAt(time.Now().UTC().Unix()) + workerTwo.SetLastBuildFinishedAt(time.Now().UTC().Unix()) + workerTwo.SetLastCheckedIn(time.Now().UTC().Unix()) + workerTwo.SetBuildLimit(1) + + return &Resources{ + Builds: []*library.Build{buildOne, buildTwo}, + Hooks: []*library.Hook{hookOne, hookTwo}, + Logs: []*library.Log{logServiceOne, logServiceTwo, logStepOne, logStepTwo}, + Pipelines: []*library.Pipeline{pipelineOne, pipelineTwo}, + Repos: []*library.Repo{repoOne, repoTwo}, + Schedules: []*library.Schedule{scheduleOne, scheduleTwo}, + Secrets: []*library.Secret{secretOne, secretTwo}, + Services: []*library.Service{serviceOne, serviceTwo}, + Steps: []*library.Step{stepOne, stepTwo}, + Users: []*library.User{userOne, userTwo}, + Workers: []*library.Worker{workerOne, workerTwo}, + } +} From b4f16a2905d4572a3483a1290838e34883ed3812 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Fri, 30 Jun 2023 10:13:22 -0500 Subject: [PATCH 43/64] chore: misc fixes --- database/integration_test.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 8f80f42d8..7492c9ead 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -651,7 +651,7 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { // update the schedules for _, schedule := range resources.Schedules { schedule.SetActive(false) - err = db.UpdateSchedule(schedule, false) + err = db.UpdateSchedule(schedule, true) if err != nil { t.Errorf("unable to update schedule %d: %v", schedule.GetID(), err) } @@ -1107,7 +1107,7 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { } if !reflect.DeepEqual(list, liteUsers) { pretty.Ldiff(t, list, liteUsers) - if diff := cmp.Diff(list, liteUsers); diff != "" { + if diff := cmp.Diff(liteUsers, list); diff != "" { t.Errorf("ListLiteUsers() mismatch (-want +got):\n%s", diff) } t.Errorf("ListLiteUsers() is %v, want %v", list, liteUsers) @@ -1275,8 +1275,8 @@ func newResources() *Resources { buildOne.SetAuthor("OctoKitty") buildOne.SetEmail("OctoKitty@github.com") buildOne.SetLink("https://example.company.com/github/octocat/1") - buildOne.SetBranch("master") - buildOne.SetRef("refs/heads/master") + buildOne.SetBranch("main") + buildOne.SetRef("refs/heads/main") buildOne.SetBaseRef("") buildOne.SetHeadRef("changes") buildOne.SetHost("example.company.com") @@ -1308,8 +1308,8 @@ func newResources() *Resources { buildTwo.SetAuthor("OctoKitty") buildTwo.SetEmail("OctoKitty@github.com") buildTwo.SetLink("https://example.company.com/github/octocat/2") - buildTwo.SetBranch("master") - buildTwo.SetRef("refs/heads/master") + buildTwo.SetBranch("main") + buildTwo.SetRef("refs/heads/main") buildTwo.SetBaseRef("") buildTwo.SetHeadRef("changes") buildTwo.SetHost("example.company.com") @@ -1326,7 +1326,7 @@ func newResources() *Resources { hookOne.SetHost("github.com") hookOne.SetEvent("push") hookOne.SetEventAction("") - hookOne.SetBranch("master") + hookOne.SetBranch("main") hookOne.SetError("") hookOne.SetStatus("success") hookOne.SetLink("https://github.com/github/octocat/settings/hooks/1") @@ -1342,7 +1342,7 @@ func newResources() *Resources { hookTwo.SetHost("github.com") hookTwo.SetEvent("push") hookTwo.SetEventAction("") - hookTwo.SetBranch("master") + hookTwo.SetBranch("main") hookTwo.SetError("") hookTwo.SetStatus("success") hookTwo.SetLink("https://github.com/github/octocat/settings/hooks/1") @@ -1386,7 +1386,7 @@ func newResources() *Resources { pipelineOne.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") pipelineOne.SetFlavor("large") pipelineOne.SetPlatform("docker") - pipelineOne.SetRef("refs/heads/master") + pipelineOne.SetRef("refs/heads/main") pipelineOne.SetType("yaml") pipelineOne.SetVersion("1") pipelineOne.SetExternalSecrets(false) @@ -1403,7 +1403,7 @@ func newResources() *Resources { pipelineTwo.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135164") pipelineTwo.SetFlavor("large") pipelineTwo.SetPlatform("docker") - pipelineTwo.SetRef("refs/heads/master") + pipelineTwo.SetRef("refs/heads/main") pipelineTwo.SetType("yaml") pipelineTwo.SetVersion("1") pipelineTwo.SetExternalSecrets(false) @@ -1449,7 +1449,7 @@ func newResources() *Resources { repoTwo.SetFullName("github/octokitty") repoTwo.SetLink("https://github.com/github/octokitty") repoTwo.SetClone("https://github.com/github/octokitty.git") - repoTwo.SetBranch("master") + repoTwo.SetBranch("main") repoTwo.SetTopics([]string{"cloud", "security"}) repoTwo.SetBuildLimit(10) repoTwo.SetTimeout(30) From 3f841bc77cf302503e0802f9ca11d43bdf0c2091 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Fri, 30 Jun 2023 10:17:50 -0500 Subject: [PATCH 44/64] fix(database): user integration test --- database/integration_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 7492c9ead..eb661c89c 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -1055,7 +1055,6 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { liteOne.SetToken("") liteOne.SetRefreshToken("") liteOne.SetHash("") - liteOne.SetFavorites([]string{}) liteOne.SetActive(false) liteOne.SetAdmin(false) @@ -1065,7 +1064,6 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { liteTwo.SetToken("") liteTwo.SetRefreshToken("") liteTwo.SetHash("") - liteTwo.SetFavorites([]string{}) liteTwo.SetActive(false) liteTwo.SetAdmin(false) From a02f2fd01693aebd482a79583ce36b7c34d6f181 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Fri, 30 Jun 2023 11:54:18 -0500 Subject: [PATCH 45/64] fix(database): build integration tests --- database/integration_test.go | 195 +++++++++++++++++++++++++++-------- 1 file changed, 152 insertions(+), 43 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index eb661c89c..84765c703 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -29,17 +29,18 @@ import ( ) type Resources struct { - Builds []*library.Build - Hooks []*library.Hook - Logs []*library.Log - Pipelines []*library.Pipeline - Repos []*library.Repo - Schedules []*library.Schedule - Secrets []*library.Secret - Services []*library.Service - Steps []*library.Step - Users []*library.User - Workers []*library.Worker + Builds []*library.Build + Deployments []*library.Deployment + Hooks []*library.Hook + Logs []*library.Log + Pipelines []*library.Pipeline + Repos []*library.Repo + Schedules []*library.Schedule + Secrets []*library.Secret + Services []*library.Service + Steps []*library.Step + Users []*library.User + Workers []*library.Worker } func TestDatabase_Integration(t *testing.T) { @@ -139,6 +140,20 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { // since those are already called when the database engine starts counter := 2 + buildOne := new(library.BuildQueue) + buildOne.SetCreated(1563474076) + buildOne.SetFullName("github/octokitty") + buildOne.SetNumber(1) + buildOne.SetStatus("running") + + buildTwo := new(library.BuildQueue) + buildTwo.SetCreated(1563474076) + buildTwo.SetFullName("github/octokitty") + buildTwo.SetNumber(2) + buildTwo.SetStatus("running") + + queueBuilds := []*library.BuildQueue{buildOne, buildTwo} + // create the builds for _, build := range resources.Builds { _, err := db.CreateBuild(build) @@ -158,6 +173,26 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { } counter++ + // count the builds for a deployment + count, err = db.CountBuildsForDeployment(resources.Deployments[0], nil) + if err != nil { + t.Errorf("unable to count builds for deployment %d: %v", resources.Deployments[0].GetID(), err) + } + if int(count) != len(resources.Builds) { + t.Errorf("CountBuildsForDeployment() is %v, want %v", count, len(resources.Builds)) + } + counter++ + + // count the builds for an org + count, err = db.CountBuildsForOrg(resources.Repos[0].GetOrg(), nil) + if err != nil { + t.Errorf("unable to count builds for org %s: %v", resources.Repos[0].GetOrg(), err) + } + if int(count) != len(resources.Builds) { + t.Errorf("CountBuildsForOrg() is %v, want %v", count, len(resources.Builds)) + } + counter++ + // count the builds for a repo count, err = db.CountBuildsForRepo(resources.Repos[0], nil) if err != nil { @@ -168,6 +203,16 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { } counter++ + // count the builds for a status + count, err = db.CountBuildsForStatus("running", nil) + if err != nil { + t.Errorf("unable to count builds for status %s: %v", "running", err) + } + if int(count) != len(resources.Builds) { + t.Errorf("CountBuildsForStatus() is %v, want %v", count, len(resources.Builds)) + } + counter++ + // list the builds list, err := db.ListBuilds() if err != nil { @@ -178,16 +223,55 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { } counter++ + // list the builds for a deployment + list, count, err = db.ListBuildsForDeployment(resources.Deployments[0], nil, 1, 10) + if err != nil { + t.Errorf("unable to list builds for deployment %d: %v", resources.Deployments[0].GetID(), err) + } + if int(count) != len(resources.Builds) { + t.Errorf("ListBuildsForDeployment() is %v, want %v", count, len(resources.Builds)) + } + if !reflect.DeepEqual(list, resources.Builds) { + t.Errorf("ListBuildsForDeployment() is %v, want %v", list, resources.Builds) + } + counter++ + + // list the builds for an org + list, count, err = db.ListBuildsForOrg(resources.Repos[0].GetOrg(), nil, 1, 10) + if err != nil { + t.Errorf("unable to list builds for org %s: %v", resources.Repos[0].GetOrg(), err) + } + if int(count) != len(resources.Builds) { + t.Errorf("ListBuildsForOrg() is %v, want %v", count, len(resources.Builds)) + } + if !reflect.DeepEqual(list, resources.Builds) { + t.Errorf("ListBuildsForOrg() is %v, want %v", list, resources.Builds) + } + counter++ + // list the builds for a repo list, count, err = db.ListBuildsForRepo(resources.Repos[0], nil, time.Now().UTC().Unix(), 0, 1, 10) if err != nil { t.Errorf("unable to list builds for repo %d: %v", resources.Repos[0].GetID(), err) } + if int(count) != len(resources.Builds) { + t.Errorf("ListBuildsForRepo() is %v, want %v", count, len(resources.Builds)) + } if !reflect.DeepEqual(list, []*library.Build{resources.Builds[1], resources.Builds[0]}) { t.Errorf("ListBuildsForRepo() is %v, want %v", list, []*library.Build{resources.Builds[1], resources.Builds[0]}) } counter++ + // list the pending and running builds + queueList, err := db.ListPendingAndRunningBuilds("0") + if err != nil { + t.Errorf("unable to list pending and running builds: %v", err) + } + if !reflect.DeepEqual(queueList, queueBuilds) { + t.Errorf("ListPendingAndRunningBuilds() is %v, want %v", queueList, queueBuilds) + } + counter++ + // lookup the last build by repo got, err := db.LastBuildForRepo(resources.Repos[0], "main") if err != nil { @@ -1049,25 +1133,25 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { // since those are already called when the database engine starts counter := 2 - liteOne := new(library.User) - liteOne.SetID(1) - liteOne.SetName("octocat") - liteOne.SetToken("") - liteOne.SetRefreshToken("") - liteOne.SetHash("") - liteOne.SetActive(false) - liteOne.SetAdmin(false) - - liteTwo := new(library.User) - liteTwo.SetID(2) - liteTwo.SetName("octokitty") - liteTwo.SetToken("") - liteTwo.SetRefreshToken("") - liteTwo.SetHash("") - liteTwo.SetActive(false) - liteTwo.SetAdmin(false) - - liteUsers := []*library.User{liteOne, liteTwo} + userOne := new(library.User) + userOne.SetID(1) + userOne.SetName("octocat") + userOne.SetToken("") + userOne.SetRefreshToken("") + userOne.SetHash("") + userOne.SetActive(false) + userOne.SetAdmin(false) + + userTwo := new(library.User) + userTwo.SetID(2) + userTwo.SetName("octokitty") + userTwo.SetToken("") + userTwo.SetRefreshToken("") + userTwo.SetHash("") + userTwo.SetActive(false) + userTwo.SetAdmin(false) + + liteUsers := []*library.User{userOne, userTwo} // create the users for _, user := range resources.Users { @@ -1265,7 +1349,7 @@ func newResources() *Resources { buildOne.SetDeploy("") buildOne.SetDeployPayload(raw.StringSliceMap{"foo": "test1"}) buildOne.SetClone("https://github.com/github/octocat.git") - buildOne.SetSource("https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135163") + buildOne.SetSource("https://github.com/github/octocat/deployments/1") buildOne.SetTitle("push received from https://github.com/github/octocat") buildOne.SetMessage("First commit...") buildOne.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") @@ -1298,7 +1382,7 @@ func newResources() *Resources { buildTwo.SetDeploy("") buildTwo.SetDeployPayload(raw.StringSliceMap{"foo": "test1"}) buildTwo.SetClone("https://github.com/github/octocat.git") - buildTwo.SetSource("https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135164") + buildTwo.SetSource("https://github.com/github/octocat/deployments/1") buildTwo.SetTitle("pull_request received from https://github.com/github/octocat") buildTwo.SetMessage("Second commit...") buildTwo.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135164") @@ -1314,6 +1398,30 @@ func newResources() *Resources { buildTwo.SetRuntime("docker") buildTwo.SetDistribution("linux") + deploymentOne := new(library.Deployment) + deploymentOne.SetID(1) + deploymentOne.SetRepoID(1) + deploymentOne.SetURL("https://github.com/github/octocat/deployments/1") + deploymentOne.SetUser("octocat") + deploymentOne.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") + deploymentOne.SetRef("refs/heads/master") + deploymentOne.SetTask("vela-deploy") + deploymentOne.SetTarget("production") + deploymentOne.SetDescription("Deployment request from Vela") + deploymentOne.SetPayload(map[string]string{"foo": "test1"}) + + deploymentTwo := new(library.Deployment) + deploymentTwo.SetID(1) + deploymentTwo.SetRepoID(1) + deploymentTwo.SetURL("https://github.com/github/octocat/deployments/2") + deploymentTwo.SetUser("octocat") + deploymentTwo.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135164") + deploymentTwo.SetRef("refs/heads/master") + deploymentTwo.SetTask("vela-deploy") + deploymentTwo.SetTarget("production") + deploymentTwo.SetDescription("Deployment request from Vela") + deploymentTwo.SetPayload(map[string]string{"foo": "test1"}) + hookOne := new(library.Hook) hookOne.SetID(1) hookOne.SetRepoID(1) @@ -1639,16 +1747,17 @@ func newResources() *Resources { workerTwo.SetBuildLimit(1) return &Resources{ - Builds: []*library.Build{buildOne, buildTwo}, - Hooks: []*library.Hook{hookOne, hookTwo}, - Logs: []*library.Log{logServiceOne, logServiceTwo, logStepOne, logStepTwo}, - Pipelines: []*library.Pipeline{pipelineOne, pipelineTwo}, - Repos: []*library.Repo{repoOne, repoTwo}, - Schedules: []*library.Schedule{scheduleOne, scheduleTwo}, - Secrets: []*library.Secret{secretOne, secretTwo}, - Services: []*library.Service{serviceOne, serviceTwo}, - Steps: []*library.Step{stepOne, stepTwo}, - Users: []*library.User{userOne, userTwo}, - Workers: []*library.Worker{workerOne, workerTwo}, + Builds: []*library.Build{buildOne, buildTwo}, + Deployments: []*library.Deployment{deploymentOne, deploymentTwo}, + Hooks: []*library.Hook{hookOne, hookTwo}, + Logs: []*library.Log{logServiceOne, logServiceTwo, logStepOne, logStepTwo}, + Pipelines: []*library.Pipeline{pipelineOne, pipelineTwo}, + Repos: []*library.Repo{repoOne, repoTwo}, + Schedules: []*library.Schedule{scheduleOne, scheduleTwo}, + Secrets: []*library.Secret{secretOne, secretTwo}, + Services: []*library.Service{serviceOne, serviceTwo}, + Steps: []*library.Step{stepOne, stepTwo}, + Users: []*library.User{userOne, userTwo}, + Workers: []*library.Worker{workerOne, workerTwo}, } } From b432a66b1cc808c51150c81a08913745b1200d70 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Fri, 30 Jun 2023 13:38:59 -0500 Subject: [PATCH 46/64] fix(database): build integration tests --- database/integration_test.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 84765c703..cb5a9fa8a 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -140,6 +140,14 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { // since those are already called when the database engine starts counter := 2 + // create the repos for build related functions + for _, repo := range resources.Repos { + err := db.CreateRepo(repo) + if err != nil { + t.Errorf("unable to create repo %d: %v", repo.GetID(), err) + } + } + buildOne := new(library.BuildQueue) buildOne.SetCreated(1563474076) buildOne.SetFullName("github/octokitty") @@ -231,8 +239,8 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Builds) { t.Errorf("ListBuildsForDeployment() is %v, want %v", count, len(resources.Builds)) } - if !reflect.DeepEqual(list, resources.Builds) { - t.Errorf("ListBuildsForDeployment() is %v, want %v", list, resources.Builds) + if !reflect.DeepEqual(list, []*library.Build{resources.Builds[1], resources.Builds[0]}) { + t.Errorf("ListBuildsForDeployment() is %v, want %v", list, []*library.Build{resources.Builds[1], resources.Builds[0]}) } counter++ @@ -315,6 +323,16 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { counter++ counter++ + // clean the builds + count, err = db.CleanBuilds("msg", time.Now().UTC().Unix()) + if err != nil { + t.Errorf("unable to clean builds: %v", err) + } + if int(count) != len(resources.Builds) { + t.Errorf("CleanBuilds() is %v, want %v", count, len(resources.Builds)) + } + counter++ + // delete the builds for _, build := range resources.Builds { err = db.DeleteBuild(build) @@ -324,6 +342,14 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { } counter++ + // delete the repos for build related functions + for _, repo := range resources.Repos { + err := db.DeleteRepo(repo) + if err != nil { + t.Errorf("unable to delete repo %d: %v", repo.GetID(), err) + } + } + // ensure we called all the functions we should have methods := reflect.TypeOf(new(build.BuildInterface)).Elem().NumMethod() if counter != methods { From db6e2f007d7ca189e958a708ba2e3c30e7c16e62 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Fri, 30 Jun 2023 13:56:19 -0500 Subject: [PATCH 47/64] fix(database): integration tests --- database/integration_test.go | 127 ++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 1 deletion(-) diff --git a/database/integration_test.go b/database/integration_test.go index cb5a9fa8a..d94525a13 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -286,7 +286,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to get last build for repo %d: %v", resources.Repos[0].GetID(), err) } if !reflect.DeepEqual(got, resources.Builds[1]) { - t.Errorf("GetBuildForRepo() is %v, want %v", got, resources.Builds[1]) + t.Errorf("LastBuildForRepo() is %v, want %v", got, resources.Builds[1]) } counter++ @@ -383,6 +383,16 @@ func testHooks(t *testing.T, db Interface, resources *Resources) { } counter++ + // count the hooks for a repo + count, err = db.CountHooksForRepo(resources.Repos[0]) + if err != nil { + t.Errorf("unable to count hooks for repo %d: %v", resources.Repos[0].GetID(), err) + } + if int(count) != len(resources.Builds) { + t.Errorf("CountHooksForRepo() is %v, want %v", count, len(resources.Builds)) + } + counter++ + // list the hooks list, err := db.ListHooks() if err != nil { @@ -393,6 +403,29 @@ func testHooks(t *testing.T, db Interface, resources *Resources) { } counter++ + // list the hooks for a repo + list, count, err = db.ListHooksForRepo(resources.Repos[0], 1, 10) + if err != nil { + t.Errorf("unable to list hooks for repo %d: %v", resources.Repos[0].GetID(), err) + } + if int(count) != len(resources.Hooks) { + t.Errorf("ListHooksForRepo() is %v, want %v", count, len(resources.Hooks)) + } + if !reflect.DeepEqual(list, resources.Hooks) { + t.Errorf("ListHooks() is %v, want %v", list, resources.Hooks) + } + counter++ + + // lookup the last build by repo + got, err := db.LastHookForRepo(resources.Repos[0]) + if err != nil { + t.Errorf("unable to get last hook for repo %d: %v", resources.Repos[0].GetID(), err) + } + if !reflect.DeepEqual(got, resources.Hooks[1]) { + t.Errorf("LastHookForRepo() is %v, want %v", got, resources.Hooks[1]) + } + counter++ + // lookup the hooks by name for _, hook := range resources.Hooks { repo := resources.Repos[hook.GetRepoID()-1] @@ -468,6 +501,16 @@ func testLogs(t *testing.T, db Interface, resources *Resources) { } counter++ + // count the logs for a build + count, err = db.CountLogsForBuild(resources.Builds[0]) + if err != nil { + t.Errorf("unable to count logs for build %d: %v", resources.Builds[0].GetID(), err) + } + if int(count) != len(resources.Logs) { + t.Errorf("CountLogs() is %v, want %v", count, len(resources.Logs)) + } + counter++ + // list the logs list, err := db.ListLogs() if err != nil { @@ -478,6 +521,19 @@ func testLogs(t *testing.T, db Interface, resources *Resources) { } counter++ + // list the logs for a build + list, count, err = db.ListLogsForBuild(resources.Builds[0], 1, 10) + if err != nil { + t.Errorf("unable to list logs for build %d: %v", resources.Builds[0].GetID(), err) + } + if int(count) != len(resources.Logs) { + t.Errorf("ListLogsForBuild() is %v, want %v", count, len(resources.Logs)) + } + if !reflect.DeepEqual(list, resources.Logs) { + t.Errorf("ListLogsForBuild() is %v, want %v", list, resources.Logs) + } + counter++ + // lookup the logs by service for _, log := range []*library.Log{resources.Logs[0], resources.Logs[1]} { service := resources.Services[log.GetServiceID()-1] @@ -566,6 +622,16 @@ func testPipelines(t *testing.T, db Interface, resources *Resources) { } counter++ + // count the pipelines for a repo + count, err = db.CountPipelinesForRepo(resources.Repos[0]) + if err != nil { + t.Errorf("unable to count pipelines for repo %d: %v", resources.Repos[0].GetID(), err) + } + if int(count) != len(resources.Pipelines) { + t.Errorf("CountPipelinesForRepo() is %v, want %v", count, len(resources.Pipelines)) + } + counter++ + // list the pipelines list, err := db.ListPipelines() if err != nil { @@ -576,6 +642,19 @@ func testPipelines(t *testing.T, db Interface, resources *Resources) { } counter++ + // list the pipelines for a repo + list, count, err = db.ListPipelinesForRepo(resources.Repos[0], 1, 10) + if err != nil { + t.Errorf("unable to list pipelines for repo %d: %v", resources.Repos[0].GetID(), err) + } + if int(count) != len(resources.Pipelines) { + t.Errorf("ListPipelinesForRepo() is %v, want %v", count, len(resources.Pipelines)) + } + if !reflect.DeepEqual(list, resources.Pipelines) { + t.Errorf("ListPipelines() is %v, want %v", list, resources.Pipelines) + } + counter++ + // lookup the pipelines by name for _, pipeline := range resources.Pipelines { repo := resources.Repos[pipeline.GetRepoID()-1] @@ -651,6 +730,26 @@ func testRepos(t *testing.T, db Interface, resources *Resources) { } counter++ + // count the repos for an org + count, err = db.CountReposForOrg(resources.Repos[0].GetOrg(), nil) + if err != nil { + t.Errorf("unable to count repos for org %s: %v", resources.Repos[0].GetOrg(), err) + } + if int(count) != len(resources.Repos) { + t.Errorf("CountReposForOrg() is %v, want %v", count, len(resources.Repos)) + } + counter++ + + // count the repos for a user + count, err = db.CountReposForUser(resources.Users[0], nil) + if err != nil { + t.Errorf("unable to count repos for user %d: %v", resources.Users[0].GetID(), err) + } + if int(count) != len(resources.Repos) { + t.Errorf("CountReposForUser() is %v, want %v", count, len(resources.Repos)) + } + counter++ + // list the repos list, err := db.ListRepos() if err != nil { @@ -661,6 +760,32 @@ func testRepos(t *testing.T, db Interface, resources *Resources) { } counter++ + // list the repos for an org + list, count, err = db.ListReposForOrg(resources.Repos[0].GetOrg(), "name", nil, 1, 10) + if err != nil { + t.Errorf("unable to list repos for org %s: %v", resources.Repos[0].GetOrg(), err) + } + if int(count) != len(resources.Repos) { + t.Errorf("ListReposForOrg() is %v, want %v", count, len(resources.Repos)) + } + if !reflect.DeepEqual(list, resources.Repos) { + t.Errorf("ListReposForOrg() is %v, want %v", list, resources.Repos) + } + counter++ + + // list the repos for a user + list, count, err = db.ListReposForUser(resources.Users[0], "name", nil, 1, 10) + if err != nil { + t.Errorf("unable to list repos for user %d: %v", resources.Users[0].GetID(), err) + } + if int(count) != len(resources.Repos) { + t.Errorf("ListReposForUser() is %v, want %v", count, len(resources.Repos)) + } + if !reflect.DeepEqual(list, resources.Repos) { + t.Errorf("ListReposForUser() is %v, want %v", list, resources.Repos) + } + counter++ + // lookup the repos by name for _, repo := range resources.Repos { got, err := db.GetRepoForOrg(repo.GetOrg(), repo.GetName()) From ac0d699ce9274a9485811d88c51095e3dd50ce5f Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Fri, 30 Jun 2023 15:22:49 -0500 Subject: [PATCH 48/64] fix(database): secrets integration tests --- database/integration_test.go | 170 +++++++++++++++++++++++++++-------- 1 file changed, 132 insertions(+), 38 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index d94525a13..e4ab2cc83 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -150,13 +150,13 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { buildOne := new(library.BuildQueue) buildOne.SetCreated(1563474076) - buildOne.SetFullName("github/octokitty") + buildOne.SetFullName("github/octocat") buildOne.SetNumber(1) buildOne.SetStatus("running") buildTwo := new(library.BuildQueue) buildTwo.SetCreated(1563474076) - buildTwo.SetFullName("github/octokitty") + buildTwo.SetFullName("github/octocat") buildTwo.SetNumber(2) buildTwo.SetStatus("running") @@ -411,8 +411,8 @@ func testHooks(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Hooks) { t.Errorf("ListHooksForRepo() is %v, want %v", count, len(resources.Hooks)) } - if !reflect.DeepEqual(list, resources.Hooks) { - t.Errorf("ListHooks() is %v, want %v", list, resources.Hooks) + if !reflect.DeepEqual(list, []*library.Hook{resources.Hooks[1], resources.Hooks[0]}) { + t.Errorf("ListHooksForRepo() is %v, want %v", list, []*library.Hook{resources.Hooks[1], resources.Hooks[0]}) } counter++ @@ -529,8 +529,8 @@ func testLogs(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Logs) { t.Errorf("ListLogsForBuild() is %v, want %v", count, len(resources.Logs)) } - if !reflect.DeepEqual(list, resources.Logs) { - t.Errorf("ListLogsForBuild() is %v, want %v", list, resources.Logs) + if !reflect.DeepEqual(list, []*library.Log{resources.Logs[2], resources.Logs[3], resources.Logs[0], resources.Logs[1]}) { + t.Errorf("ListLogsForBuild() is %v, want %v", list, []*library.Log{resources.Logs[2], resources.Logs[3], resources.Logs[0], resources.Logs[1]}) } counter++ @@ -897,6 +897,7 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to get schedule %d by ID: %v", schedule.GetID(), err) } if !reflect.DeepEqual(got, schedule) { + pretty.Ldiff(t, got, schedule) t.Errorf("GetSchedule() is %v, want %v", got, schedule) } } @@ -945,6 +946,39 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { } counter++ + // count the secrets for an org + count, err = db.CountSecretsForOrg(resources.Secrets[0].GetOrg(), nil) + if err != nil { + t.Errorf("unable to count secrets for org %s: %v", resources.Secrets[0].GetOrg(), err) + } + if int(count) != 1 { + t.Errorf("CountSecretsForOrg() is %v, want %v", count, 1) + } + counter++ + + // count the secrets for a repo + count, err = db.CountSecretsForRepo(resources.Repos[0], nil) + if err != nil { + t.Errorf("unable to count secrets for repo %d: %v", resources.Repos[0].GetID(), err) + } + if int(count) != 1 { + t.Errorf("CountSecretsForRepo() is %v, want %v", count, 1) + } + counter++ + + // count the secrets for a team + count, err = db.CountSecretsForTeam(resources.Secrets[2].GetOrg(), resources.Secrets[2].GetTeam(), nil) + if err != nil { + t.Errorf("unable to count secrets for team %s: %v", resources.Secrets[2].GetTeam(), err) + } + if int(count) != 1 { + t.Errorf("CountSecretsForTeam() is %v, want %v", count, 1) + } + counter++ + + // count the secrets for a list of teams + // TODO: + // list the secrets list, err := db.ListSecrets() if err != nil { @@ -955,6 +989,48 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { } counter++ + // list the secrets for an org + list, count, err = db.ListSecretsForOrg(resources.Secrets[0].GetOrg(), nil, 1, 10) + if err != nil { + t.Errorf("unable to list secrets for org %s: %v", resources.Secrets[0].GetOrg(), err) + } + if int(count) != 1 { + t.Errorf("ListSecretsForOrg() is %v, want %v", count, 1) + } + if !reflect.DeepEqual(list, resources.Secrets) { + t.Errorf("ListSecretsForOrg() is %v, want %v", list, resources.Secrets) + } + counter++ + + // list the secrets for a repo + list, count, err = db.ListSecretsForRepo(resources.Repos[0], nil, 1, 10) + if err != nil { + t.Errorf("unable to list secrets for repo %d: %v", resources.Repos[0].GetID(), err) + } + if int(count) != 1 { + t.Errorf("ListSecretsForRepo() is %v, want %v", count, 1) + } + if !reflect.DeepEqual(list, resources.Secrets) { + t.Errorf("ListSecretsForRepo() is %v, want %v", list, resources.Secrets) + } + counter++ + + // list the secrets for a team + list, count, err = db.ListSecretsForTeam(resources.Secrets[2].GetOrg(), resources.Secrets[2].GetTeam(), nil, 1, 10) + if err != nil { + t.Errorf("unable to list secrets for team %s: %v", resources.Secrets[2].GetTeam(), err) + } + if int(count) != 1 { + t.Errorf("ListSecretsForTeam() is %v, want %v", count, 1) + } + if !reflect.DeepEqual(list, resources.Secrets) { + t.Errorf("ListSecretsForTeam() is %v, want %v", list, resources.Secrets) + } + counter++ + + // list the secrets for a list of teams + // TODO: + // lookup the secrets by name for _, secret := range resources.Secrets { got, err := db.GetSecretForRepo(secret.GetName(), resources.Repos[0]) @@ -1290,6 +1366,7 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { userOne.SetToken("") userOne.SetRefreshToken("") userOne.SetHash("") + userOne.SetFavorites(nil) userOne.SetActive(false) userOne.SetAdmin(false) @@ -1299,6 +1376,7 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { userTwo.SetToken("") userTwo.SetRefreshToken("") userTwo.SetHash("") + userTwo.SetFavorites(nil) userTwo.SetActive(false) userTwo.SetAdmin(false) @@ -1747,37 +1825,53 @@ func newResources() *Resources { scheduleTwo.SetUpdatedBy("octokitty") scheduleTwo.SetScheduledAt(time.Now().Add(time.Hour * 2).UTC().Unix()) - secretOne := new(library.Secret) - secretOne.SetID(1) - secretOne.SetOrg("github") - secretOne.SetRepo("octocat") - secretOne.SetTeam("") - secretOne.SetName("foo") - secretOne.SetValue("bar") - secretOne.SetType("repo") - secretOne.SetImages([]string{"alpine"}) - secretOne.SetEvents([]string{"push", "tag", "deployment"}) - secretOne.SetAllowCommand(true) - secretOne.SetCreatedAt(time.Now().UTC().Unix()) - secretOne.SetCreatedBy("octocat") - secretOne.SetUpdatedAt(time.Now().UTC().Unix()) - secretOne.SetUpdatedBy("octokitty") - - secretTwo := new(library.Secret) - secretTwo.SetID(2) - secretTwo.SetOrg("github") - secretTwo.SetRepo("octocat") - secretTwo.SetTeam("") - secretTwo.SetName("bar") - secretTwo.SetValue("baz") - secretTwo.SetType("repo") - secretTwo.SetImages([]string{"alpine"}) - secretTwo.SetEvents([]string{"push", "tag", "deployment"}) - secretTwo.SetAllowCommand(true) - secretTwo.SetCreatedAt(time.Now().UTC().Unix()) - secretTwo.SetCreatedBy("octocat") - secretTwo.SetUpdatedAt(time.Now().UTC().Unix()) - secretTwo.SetUpdatedBy("octokitty") + secretOrg := new(library.Secret) + secretOrg.SetID(1) + secretOrg.SetOrg("github") + secretOrg.SetRepo("") + secretOrg.SetTeam("") + secretOrg.SetName("foo") + secretOrg.SetValue("bar") + secretOrg.SetType("org") + secretOrg.SetImages([]string{"alpine"}) + secretOrg.SetEvents([]string{"push", "tag", "deployment"}) + secretOrg.SetAllowCommand(true) + secretOrg.SetCreatedAt(time.Now().UTC().Unix()) + secretOrg.SetCreatedBy("octocat") + secretOrg.SetUpdatedAt(time.Now().UTC().Unix()) + secretOrg.SetUpdatedBy("octokitty") + + secretRepo := new(library.Secret) + secretRepo.SetID(2) + secretRepo.SetOrg("github") + secretRepo.SetRepo("octocat") + secretRepo.SetTeam("") + secretRepo.SetName("foo") + secretRepo.SetValue("bar") + secretRepo.SetType("repo") + secretRepo.SetImages([]string{"alpine"}) + secretRepo.SetEvents([]string{"push", "tag", "deployment"}) + secretRepo.SetAllowCommand(true) + secretRepo.SetCreatedAt(time.Now().UTC().Unix()) + secretRepo.SetCreatedBy("octocat") + secretRepo.SetUpdatedAt(time.Now().UTC().Unix()) + secretRepo.SetUpdatedBy("octokitty") + + secretShared := new(library.Secret) + secretShared.SetID(3) + secretShared.SetOrg("github") + secretShared.SetRepo("") + secretShared.SetTeam("octocat") + secretShared.SetName("foo") + secretShared.SetValue("bar") + secretShared.SetType("shared") + secretShared.SetImages([]string{"alpine"}) + secretShared.SetEvents([]string{"push", "tag", "deployment"}) + secretShared.SetAllowCommand(true) + secretShared.SetCreatedAt(time.Now().UTC().Unix()) + secretShared.SetCreatedBy("octocat") + secretShared.SetUpdatedAt(time.Now().UTC().Unix()) + secretShared.SetUpdatedBy("octokitty") serviceOne := new(library.Service) serviceOne.SetID(1) @@ -1905,7 +1999,7 @@ func newResources() *Resources { Pipelines: []*library.Pipeline{pipelineOne, pipelineTwo}, Repos: []*library.Repo{repoOne, repoTwo}, Schedules: []*library.Schedule{scheduleOne, scheduleTwo}, - Secrets: []*library.Secret{secretOne, secretTwo}, + Secrets: []*library.Secret{secretOrg, secretRepo, secretShared}, Services: []*library.Service{serviceOne, serviceTwo}, Steps: []*library.Step{stepOne, stepTwo}, Users: []*library.User{userOne, userTwo}, From ad9c57421c1be178995d003bb3dda2a76e48ee59 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Fri, 30 Jun 2023 15:55:29 -0500 Subject: [PATCH 49/64] fix(database): integration tests --- database/integration_test.go | 42 +++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index e4ab2cc83..5d7c6fcef 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -324,7 +324,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { counter++ // clean the builds - count, err = db.CleanBuilds("msg", time.Now().UTC().Unix()) + count, err = db.CleanBuilds("integration testing", 1563474090) if err != nil { t.Errorf("unable to clean builds: %v", err) } @@ -860,6 +860,16 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { } counter++ + // count the schedules for a repo + count, err = db.CountSchedulesForRepo(resources.Repos[0]) + if err != nil { + t.Errorf("unable to count schedules for repo %d: %v", resources.Repos[0].GetID(), err) + } + if int(count) != len(resources.Schedules) { + t.Errorf("CountSchedulesForRepo() is %v, want %v", count, len(resources.Schedules)) + } + counter++ + // list the schedules list, err := db.ListSchedules() if err != nil { @@ -870,6 +880,29 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { } counter++ + // list the active schedules + list, err = db.ListActiveSchedules() + if err != nil { + t.Errorf("unable to list schedules: %v", err) + } + if !reflect.DeepEqual(list, resources.Schedules) { + t.Errorf("ListActiveSchedules() is %v, want %v", list, resources.Schedules) + } + counter++ + + // list the schedules for a repo + list, count, err = db.ListSchedulesForRepo(resources.Repos[0], 1, 10) + if err != nil { + t.Errorf("unable to count schedules for repo %d: %v", resources.Repos[0].GetID(), err) + } + if int(count) != len(resources.Schedules) { + t.Errorf("ListSchedulesForRepo() is %v, want %v", count, len(resources.Schedules)) + } + if !reflect.DeepEqual(list, resources.Schedules) { + t.Errorf("ListSchedulesForRepo() is %v, want %v", list, resources.Schedules) + } + counter++ + // lookup the schedules by name for _, schedule := range resources.Schedules { repo := resources.Repos[schedule.GetRepoID()-1] @@ -885,8 +918,8 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { // update the schedules for _, schedule := range resources.Schedules { - schedule.SetActive(false) - err = db.UpdateSchedule(schedule, true) + schedule.SetScheduledAt(time.Now().UTC().Unix()) + err = db.UpdateSchedule(schedule, false) if err != nil { t.Errorf("unable to update schedule %d: %v", schedule.GetID(), err) } @@ -897,7 +930,6 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to get schedule %d by ID: %v", schedule.GetID(), err) } if !reflect.DeepEqual(got, schedule) { - pretty.Ldiff(t, got, schedule) t.Errorf("GetSchedule() is %v, want %v", got, schedule) } } @@ -1828,7 +1860,7 @@ func newResources() *Resources { secretOrg := new(library.Secret) secretOrg.SetID(1) secretOrg.SetOrg("github") - secretOrg.SetRepo("") + secretOrg.SetRepo("*") secretOrg.SetTeam("") secretOrg.SetName("foo") secretOrg.SetValue("bar") From 5a56952327062dfa5ae2acc3c2df7f04db36e052 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Fri, 30 Jun 2023 16:12:39 -0500 Subject: [PATCH 50/64] fix(database): integration tests --- database/integration_test.go | 72 ++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 5d7c6fcef..0f235ea38 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -290,6 +290,16 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { } counter++ + // clean the builds + count, err = db.CleanBuilds("integration testing", 1563474090) + if err != nil { + t.Errorf("unable to clean builds: %v", err) + } + if int(count) != len(resources.Builds) { + t.Errorf("CleanBuilds() is %v, want %v", count, len(resources.Builds)) + } + counter++ + // lookup the builds by repo and number for _, build := range resources.Builds { repo := resources.Repos[build.GetRepoID()-1] @@ -323,16 +333,6 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { counter++ counter++ - // clean the builds - count, err = db.CleanBuilds("integration testing", 1563474090) - if err != nil { - t.Errorf("unable to clean builds: %v", err) - } - if int(count) != len(resources.Builds) { - t.Errorf("CleanBuilds() is %v, want %v", count, len(resources.Builds)) - } - counter++ - // delete the builds for _, build := range resources.Builds { err = db.DeleteBuild(build) @@ -898,8 +898,8 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Schedules) { t.Errorf("ListSchedulesForRepo() is %v, want %v", count, len(resources.Schedules)) } - if !reflect.DeepEqual(list, resources.Schedules) { - t.Errorf("ListSchedulesForRepo() is %v, want %v", list, resources.Schedules) + if !reflect.DeepEqual(list, []*library.Schedule{resources.Schedules[1], resources.Schedules[0]}) { + t.Errorf("ListSchedulesForRepo() is %v, want %v", list, []*library.Schedule{resources.Schedules[1], resources.Schedules[0]}) } counter++ @@ -1029,8 +1029,8 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if int(count) != 1 { t.Errorf("ListSecretsForOrg() is %v, want %v", count, 1) } - if !reflect.DeepEqual(list, resources.Secrets) { - t.Errorf("ListSecretsForOrg() is %v, want %v", list, resources.Secrets) + if !reflect.DeepEqual(list, []*library.Secret{resources.Secrets[0]}) { + t.Errorf("ListSecretsForOrg() is %v, want %v", list, []*library.Secret{resources.Secrets[0]}) } counter++ @@ -1042,8 +1042,8 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if int(count) != 1 { t.Errorf("ListSecretsForRepo() is %v, want %v", count, 1) } - if !reflect.DeepEqual(list, resources.Secrets) { - t.Errorf("ListSecretsForRepo() is %v, want %v", list, resources.Secrets) + if !reflect.DeepEqual(list, []*library.Secret{resources.Secrets[1]}) { + t.Errorf("ListSecretsForRepo() is %v, want %v", list, []*library.Secret{resources.Secrets[1]}) } counter++ @@ -1055,23 +1055,41 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if int(count) != 1 { t.Errorf("ListSecretsForTeam() is %v, want %v", count, 1) } - if !reflect.DeepEqual(list, resources.Secrets) { - t.Errorf("ListSecretsForTeam() is %v, want %v", list, resources.Secrets) + if !reflect.DeepEqual(list, []*library.Secret{resources.Secrets[2]}) { + t.Errorf("ListSecretsForTeam() is %v, want %v", list, []*library.Secret{resources.Secrets[2]}) } counter++ // list the secrets for a list of teams // TODO: - // lookup the secrets by name - for _, secret := range resources.Secrets { - got, err := db.GetSecretForRepo(secret.GetName(), resources.Repos[0]) - if err != nil { - t.Errorf("unable to get secret %d for repo %d: %v", secret.GetID(), resources.Repos[0].GetID(), err) - } - if !reflect.DeepEqual(got, secret) { - t.Errorf("GetSecretForRepo() is %v, want %v", got, secret) - } + // lookup the secret by org + got, err := db.GetSecretForOrg(resources.Secrets[0].GetOrg(), resources.Secrets[0].GetName()) + if err != nil { + t.Errorf("unable to get secret %d for org %s: %v", resources.Secrets[0].GetID(), resources.Secrets[0].GetOrg(), err) + } + if !reflect.DeepEqual(got, resources.Secrets[0]) { + t.Errorf("GetSecretForOrg() is %v, want %v", got, resources.Secrets[0]) + } + counter++ + + // lookup the secret by repo + got, err = db.GetSecretForRepo(resources.Secrets[1].GetName(), resources.Repos[0]) + if err != nil { + t.Errorf("unable to get secret %d for repo %d: %v", resources.Secrets[1].GetID(), resources.Repos[0].GetID(), err) + } + if !reflect.DeepEqual(got, resources.Secrets[1]) { + t.Errorf("GetSecretForRepo() is %v, want %v", got, resources.Secrets[1]) + } + counter++ + + // lookup the secret by team + got, err = db.GetSecretForTeam(resources.Secrets[2].GetOrg(), resources.Secrets[2].GetTeam(), resources.Secrets[2].GetName()) + if err != nil { + t.Errorf("unable to get secret %d for team %d: %v", resources.Secrets[2].GetID(), resources.Secrets[2].GetTeam(), err) + } + if !reflect.DeepEqual(got, resources.Secrets[2]) { + t.Errorf("GetSecretForTeam() is %v, want %v", got, resources.Secrets[2]) } counter++ From f42085f54ef9b2cc50e7c47ba4a84040af8d66d3 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Mon, 3 Jul 2023 08:10:53 -0500 Subject: [PATCH 51/64] fix(database): secrets integration tests --- database/integration_test.go | 234 ++++++++++++++++++++--------------- 1 file changed, 137 insertions(+), 97 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 0f235ea38..5cfdc7c92 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -11,6 +11,8 @@ import ( "testing" "time" + "github.com/go-vela/types/constants" + "github.com/go-vela/server/database/build" "github.com/go-vela/server/database/hook" "github.com/go-vela/server/database/log" @@ -978,38 +980,52 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { } counter++ - // count the secrets for an org - count, err = db.CountSecretsForOrg(resources.Secrets[0].GetOrg(), nil) - if err != nil { - t.Errorf("unable to count secrets for org %s: %v", resources.Secrets[0].GetOrg(), err) - } - if int(count) != 1 { - t.Errorf("CountSecretsForOrg() is %v, want %v", count, 1) - } - counter++ - - // count the secrets for a repo - count, err = db.CountSecretsForRepo(resources.Repos[0], nil) - if err != nil { - t.Errorf("unable to count secrets for repo %d: %v", resources.Repos[0].GetID(), err) - } - if int(count) != 1 { - t.Errorf("CountSecretsForRepo() is %v, want %v", count, 1) - } - counter++ + for _, secret := range resources.Secrets { + switch secret.GetType() { + case constants.SecretOrg: + // count the secrets for an org + count, err = db.CountSecretsForOrg(secret.GetOrg(), nil) + if err != nil { + t.Errorf("unable to count secrets for org %s: %v", secret.GetOrg(), err) + } + if int(count) != 1 { + t.Errorf("CountSecretsForOrg() is %v, want %v", count, 1) + } + counter++ + case constants.SecretRepo: + // count the secrets for a repo + count, err = db.CountSecretsForRepo(resources.Repos[0], nil) + if err != nil { + t.Errorf("unable to count secrets for repo %d: %v", resources.Repos[0].GetID(), err) + } + if int(count) != 1 { + t.Errorf("CountSecretsForRepo() is %v, want %v", count, 1) + } + counter++ + case constants.SecretShared: + // count the secrets for a team + count, err = db.CountSecretsForTeam(secret.GetOrg(), secret.GetTeam(), nil) + if err != nil { + t.Errorf("unable to count secrets for team %s: %v", secret.GetTeam(), err) + } + if int(count) != 1 { + t.Errorf("CountSecretsForTeam() is %v, want %v", count, 1) + } + counter++ - // count the secrets for a team - count, err = db.CountSecretsForTeam(resources.Secrets[2].GetOrg(), resources.Secrets[2].GetTeam(), nil) - if err != nil { - t.Errorf("unable to count secrets for team %s: %v", resources.Secrets[2].GetTeam(), err) - } - if int(count) != 1 { - t.Errorf("CountSecretsForTeam() is %v, want %v", count, 1) + // count the secrets for a list of teams + count, err = db.CountSecretsForTeams(secret.GetOrg(), []string{secret.GetTeam()}, nil) + if err != nil { + t.Errorf("unable to count secrets for teams %s: %v", []string{secret.GetTeam()}, err) + } + if int(count) != 1 { + t.Errorf("CountSecretsForTeams() is %v, want %v", count, 1) + } + counter++ + default: + t.Errorf("unsupported type %s for secret %d", secret.GetType(), secret.GetID()) + } } - counter++ - - // count the secrets for a list of teams - // TODO: // list the secrets list, err := db.ListSecrets() @@ -1021,77 +1037,101 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { } counter++ - // list the secrets for an org - list, count, err = db.ListSecretsForOrg(resources.Secrets[0].GetOrg(), nil, 1, 10) - if err != nil { - t.Errorf("unable to list secrets for org %s: %v", resources.Secrets[0].GetOrg(), err) - } - if int(count) != 1 { - t.Errorf("ListSecretsForOrg() is %v, want %v", count, 1) - } - if !reflect.DeepEqual(list, []*library.Secret{resources.Secrets[0]}) { - t.Errorf("ListSecretsForOrg() is %v, want %v", list, []*library.Secret{resources.Secrets[0]}) - } - counter++ - - // list the secrets for a repo - list, count, err = db.ListSecretsForRepo(resources.Repos[0], nil, 1, 10) - if err != nil { - t.Errorf("unable to list secrets for repo %d: %v", resources.Repos[0].GetID(), err) - } - if int(count) != 1 { - t.Errorf("ListSecretsForRepo() is %v, want %v", count, 1) - } - if !reflect.DeepEqual(list, []*library.Secret{resources.Secrets[1]}) { - t.Errorf("ListSecretsForRepo() is %v, want %v", list, []*library.Secret{resources.Secrets[1]}) - } - counter++ - - // list the secrets for a team - list, count, err = db.ListSecretsForTeam(resources.Secrets[2].GetOrg(), resources.Secrets[2].GetTeam(), nil, 1, 10) - if err != nil { - t.Errorf("unable to list secrets for team %s: %v", resources.Secrets[2].GetTeam(), err) - } - if int(count) != 1 { - t.Errorf("ListSecretsForTeam() is %v, want %v", count, 1) - } - if !reflect.DeepEqual(list, []*library.Secret{resources.Secrets[2]}) { - t.Errorf("ListSecretsForTeam() is %v, want %v", list, []*library.Secret{resources.Secrets[2]}) - } - counter++ - - // list the secrets for a list of teams - // TODO: - - // lookup the secret by org - got, err := db.GetSecretForOrg(resources.Secrets[0].GetOrg(), resources.Secrets[0].GetName()) - if err != nil { - t.Errorf("unable to get secret %d for org %s: %v", resources.Secrets[0].GetID(), resources.Secrets[0].GetOrg(), err) - } - if !reflect.DeepEqual(got, resources.Secrets[0]) { - t.Errorf("GetSecretForOrg() is %v, want %v", got, resources.Secrets[0]) - } - counter++ + for _, secret := range resources.Secrets { + switch secret.GetType() { + case constants.SecretOrg: + // list the secrets for an org + list, count, err = db.ListSecretsForOrg(secret.GetOrg(), nil, 1, 10) + if err != nil { + t.Errorf("unable to list secrets for org %s: %v", secret.GetOrg(), err) + } + if int(count) != 1 { + t.Errorf("ListSecretsForOrg() is %v, want %v", count, 1) + } + if !reflect.DeepEqual(list, []*library.Secret{secret}) { + t.Errorf("ListSecretsForOrg() is %v, want %v", list, []*library.Secret{secret}) + } + counter++ + case constants.SecretRepo: + // list the secrets for a repo + list, count, err = db.ListSecretsForRepo(resources.Repos[0], nil, 1, 10) + if err != nil { + t.Errorf("unable to list secrets for repo %d: %v", resources.Repos[0].GetID(), err) + } + if int(count) != 1 { + t.Errorf("ListSecretsForRepo() is %v, want %v", count, 1) + } + if !reflect.DeepEqual(list, []*library.Secret{secret}) { + t.Errorf("ListSecretsForRepo() is %v, want %v", list, []*library.Secret{secret}) + } + counter++ + case constants.SecretShared: + // list the secrets for a team + list, count, err = db.ListSecretsForTeam(secret.GetOrg(), secret.GetTeam(), nil, 1, 10) + if err != nil { + t.Errorf("unable to list secrets for team %s: %v", secret.GetTeam(), err) + } + if int(count) != 1 { + t.Errorf("ListSecretsForTeam() is %v, want %v", count, 1) + } + if !reflect.DeepEqual(list, []*library.Secret{secret}) { + t.Errorf("ListSecretsForTeam() is %v, want %v", list, []*library.Secret{secret}) + } + counter++ - // lookup the secret by repo - got, err = db.GetSecretForRepo(resources.Secrets[1].GetName(), resources.Repos[0]) - if err != nil { - t.Errorf("unable to get secret %d for repo %d: %v", resources.Secrets[1].GetID(), resources.Repos[0].GetID(), err) - } - if !reflect.DeepEqual(got, resources.Secrets[1]) { - t.Errorf("GetSecretForRepo() is %v, want %v", got, resources.Secrets[1]) + // list the secrets for a list of teams + list, count, err = db.ListSecretsForTeams(secret.GetOrg(), []string{secret.GetTeam()}, nil, 1, 10) + if err != nil { + t.Errorf("unable to list secrets for teams %s: %v", []string{secret.GetTeam()}, err) + } + if int(count) != 1 { + t.Errorf("ListSecretsForTeams() is %v, want %v", count, 1) + } + if !reflect.DeepEqual(list, []*library.Secret{secret}) { + t.Errorf("ListSecretsForTeams() is %v, want %v", list, []*library.Secret{secret}) + } + counter++ + default: + t.Errorf("unsupported type %s for secret %d", secret.GetType(), secret.GetID()) + } } - counter++ - // lookup the secret by team - got, err = db.GetSecretForTeam(resources.Secrets[2].GetOrg(), resources.Secrets[2].GetTeam(), resources.Secrets[2].GetName()) - if err != nil { - t.Errorf("unable to get secret %d for team %d: %v", resources.Secrets[2].GetID(), resources.Secrets[2].GetTeam(), err) - } - if !reflect.DeepEqual(got, resources.Secrets[2]) { - t.Errorf("GetSecretForTeam() is %v, want %v", got, resources.Secrets[2]) + for _, secret := range resources.Secrets { + switch secret.GetType() { + case constants.SecretOrg: + // lookup the secret by org + got, err := db.GetSecretForOrg(secret.GetOrg(), secret.GetName()) + if err != nil { + t.Errorf("unable to get secret %d for org %s: %v", secret.GetID(), secret.GetOrg(), err) + } + if !reflect.DeepEqual(got, secret) { + t.Errorf("GetSecretForOrg() is %v, want %v", got, secret) + } + counter++ + case constants.SecretRepo: + // lookup the secret by repo + got, err := db.GetSecretForRepo(secret.GetName(), resources.Repos[0]) + if err != nil { + t.Errorf("unable to get secret %d for repo %d: %v", secret.GetID(), resources.Repos[0].GetID(), err) + } + if !reflect.DeepEqual(got, secret) { + t.Errorf("GetSecretForRepo() is %v, want %v", got, secret) + } + counter++ + case constants.SecretShared: + // lookup the secret by team + got, err := db.GetSecretForTeam(secret.GetOrg(), secret.GetTeam(), secret.GetName()) + if err != nil { + t.Errorf("unable to get secret %d for team %s: %v", secret.GetID(), secret.GetTeam(), err) + } + if !reflect.DeepEqual(got, secret) { + t.Errorf("GetSecretForTeam() is %v, want %v", got, secret) + } + counter++ + default: + t.Errorf("unsupported type %s for secret %d", secret.GetType(), secret.GetID()) + } } - counter++ // update the secrets for _, secret := range resources.Secrets { From ea00645b8c265027f9c0daef52b8511f4f26d14a Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Mon, 3 Jul 2023 08:18:17 -0500 Subject: [PATCH 52/64] test: troubleshoot build failures --- database/integration_test.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 5cfdc7c92..125f7f7a4 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -26,7 +26,6 @@ import ( "github.com/go-vela/server/database/worker" "github.com/go-vela/types/library" "github.com/go-vela/types/raw" - "github.com/google/go-cmp/cmp" "github.com/kr/pretty" ) @@ -310,6 +309,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to get build %d for repo %d: %v", build.GetID(), repo.GetID(), err) } if !reflect.DeepEqual(got, build) { + pretty.Ldiff(t, got, build) t.Errorf("GetBuildForRepo() is %v, want %v", got, build) } } @@ -1507,10 +1507,6 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to list lite users: %v", err) } if !reflect.DeepEqual(list, liteUsers) { - pretty.Ldiff(t, list, liteUsers) - if diff := cmp.Diff(liteUsers, list); diff != "" { - t.Errorf("ListLiteUsers() mismatch (-want +got):\n%s", diff) - } t.Errorf("ListLiteUsers() is %v, want %v", list, liteUsers) } if int(count) != len(liteUsers) { From aaea5aa8cddd1606708bb7c043df8bfa6d8b83b6 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Mon, 3 Jul 2023 08:24:37 -0500 Subject: [PATCH 53/64] fix(database): integration tests --- database/integration_test.go | 22 ++++++++++------------ go.mod | 1 - go.sum | 2 -- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 125f7f7a4..faea097fb 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -26,7 +26,6 @@ import ( "github.com/go-vela/server/database/worker" "github.com/go-vela/types/library" "github.com/go-vela/types/raw" - "github.com/kr/pretty" ) type Resources struct { @@ -291,16 +290,6 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { } counter++ - // clean the builds - count, err = db.CleanBuilds("integration testing", 1563474090) - if err != nil { - t.Errorf("unable to clean builds: %v", err) - } - if int(count) != len(resources.Builds) { - t.Errorf("CleanBuilds() is %v, want %v", count, len(resources.Builds)) - } - counter++ - // lookup the builds by repo and number for _, build := range resources.Builds { repo := resources.Repos[build.GetRepoID()-1] @@ -309,12 +298,21 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to get build %d for repo %d: %v", build.GetID(), repo.GetID(), err) } if !reflect.DeepEqual(got, build) { - pretty.Ldiff(t, got, build) t.Errorf("GetBuildForRepo() is %v, want %v", got, build) } } counter++ + // clean the builds + count, err = db.CleanBuilds("integration testing", 1563474090) + if err != nil { + t.Errorf("unable to clean builds: %v", err) + } + if int(count) != len(resources.Builds) { + t.Errorf("CleanBuilds() is %v, want %v", count, len(resources.Builds)) + } + counter++ + // update the builds for _, build := range resources.Builds { build.SetStatus("success") diff --git a/go.mod b/go.mod index 2b381dd22..92447e823 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,6 @@ require ( github.com/hashicorp/go-retryablehttp v0.7.4 github.com/hashicorp/vault/api v1.9.2 github.com/joho/godotenv v1.5.1 - github.com/kr/pretty v0.3.1 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.16.0 github.com/redis/go-redis/v9 v9.0.5 diff --git a/go.sum b/go.sum index 0f13f201a..cd8f3f4e7 100644 --- a/go.sum +++ b/go.sum @@ -289,7 +289,6 @@ github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8t github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -332,7 +331,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= From 88e0d5c78c08e692ac97b2dd1fa5deab38aa26f5 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Mon, 3 Jul 2023 08:46:41 -0500 Subject: [PATCH 54/64] fix(database): integration tests --- database/integration_test.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index faea097fb..a0f28a675 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -11,8 +11,6 @@ import ( "testing" "time" - "github.com/go-vela/types/constants" - "github.com/go-vela/server/database/build" "github.com/go-vela/server/database/hook" "github.com/go-vela/server/database/log" @@ -24,6 +22,7 @@ import ( "github.com/go-vela/server/database/step" "github.com/go-vela/server/database/user" "github.com/go-vela/server/database/worker" + "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/go-vela/types/raw" ) @@ -53,13 +52,11 @@ func TestDatabase_Integration(t *testing.T) { // setup tests tests := []struct { - failure bool - name string - config *config + name string + config *config }{ { - name: "success with postgres", - failure: false, + name: "success with postgres", config: &config{ Driver: "postgres", Address: "postgres://vela:notARealPassword12345@localhost:5432/vela", @@ -1922,7 +1919,7 @@ func newResources() *Resources { secretOrg.SetAllowCommand(true) secretOrg.SetCreatedAt(time.Now().UTC().Unix()) secretOrg.SetCreatedBy("octocat") - secretOrg.SetUpdatedAt(time.Now().UTC().Unix()) + secretOrg.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix()) secretOrg.SetUpdatedBy("octokitty") secretRepo := new(library.Secret) @@ -1938,7 +1935,7 @@ func newResources() *Resources { secretRepo.SetAllowCommand(true) secretRepo.SetCreatedAt(time.Now().UTC().Unix()) secretRepo.SetCreatedBy("octocat") - secretRepo.SetUpdatedAt(time.Now().UTC().Unix()) + secretRepo.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix()) secretRepo.SetUpdatedBy("octokitty") secretShared := new(library.Secret) @@ -1954,7 +1951,7 @@ func newResources() *Resources { secretShared.SetAllowCommand(true) secretShared.SetCreatedAt(time.Now().UTC().Unix()) secretShared.SetCreatedBy("octocat") - secretShared.SetUpdatedAt(time.Now().UTC().Unix()) + secretShared.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix()) secretShared.SetUpdatedBy("octokitty") serviceOne := new(library.Service) From e168b627869db26504c156a94f7dad52723bcac2 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Mon, 3 Jul 2023 08:54:12 -0500 Subject: [PATCH 55/64] fix(database): integration tests --- .github/workflows/integration-test.yml | 3 +++ database/integration_test.go | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 2b400f4fa..484595910 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -28,6 +28,9 @@ jobs: ports: - 5432:5432 + env: + POSTGRES_ADDR: postgres://vela:notARealPassword12345@localhost:5432/vela + steps: - name: clone uses: actions/checkout@v3 diff --git a/database/integration_test.go b/database/integration_test.go index a0f28a675..7c1684996 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -59,7 +59,7 @@ func TestDatabase_Integration(t *testing.T) { name: "success with postgres", config: &config{ Driver: "postgres", - Address: "postgres://vela:notARealPassword12345@localhost:5432/vela", + Address: os.Getenv("POSTGRES_ADDR"), CompressionLevel: 3, ConnectionLife: 10 * time.Second, ConnectionIdle: 5, @@ -915,8 +915,8 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { // update the schedules for _, schedule := range resources.Schedules { - schedule.SetScheduledAt(time.Now().UTC().Unix()) - err = db.UpdateSchedule(schedule, false) + schedule.SetUpdatedAt(time.Now().UTC().Unix()) + err = db.UpdateSchedule(schedule, true) if err != nil { t.Errorf("unable to update schedule %d: %v", schedule.GetID(), err) } @@ -1130,7 +1130,7 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { // update the secrets for _, secret := range resources.Secrets { - secret.SetAllowCommand(false) + secret.SetUpdatedAt(time.Now().UTC().Unix()) err = db.UpdateSecret(secret) if err != nil { t.Errorf("unable to update secret %d: %v", secret.GetID(), err) From c226c03309f488de5c123d0f1e2adea26200ffbe Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Mon, 3 Jul 2023 09:05:39 -0500 Subject: [PATCH 56/64] feat(database): add sqlite integration tests --- .github/workflows/integration-test.yml | 1 + database/integration_test.go | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 484595910..8011d641b 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -30,6 +30,7 @@ jobs: env: POSTGRES_ADDR: postgres://vela:notARealPassword12345@localhost:5432/vela + SQLITE_ADDR: file::memory:?cache=shared steps: - name: clone diff --git a/database/integration_test.go b/database/integration_test.go index 7c1684996..778c30849 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -56,7 +56,7 @@ func TestDatabase_Integration(t *testing.T) { config *config }{ { - name: "success with postgres", + name: "postgres", config: &config{ Driver: "postgres", Address: os.Getenv("POSTGRES_ADDR"), @@ -68,6 +68,19 @@ func TestDatabase_Integration(t *testing.T) { SkipCreation: false, }, }, + { + name: "sqlite3", + config: &config{ + Driver: "sqlite3", + Address: os.Getenv("SQLITE_ADDR"), + CompressionLevel: 3, + ConnectionLife: 10 * time.Second, + ConnectionIdle: 5, + ConnectionOpen: 20, + EncryptionKey: "A1B2C3D4E5G6H7I8J9K0LMNOPQRSTUVW", + SkipCreation: false, + }, + }, } // run tests From 78c8ac486df077f47a1f965489739b620acc0bf7 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Mon, 3 Jul 2023 09:13:59 -0500 Subject: [PATCH 57/64] fix(database): sqlite integration tests --- .github/workflows/integration-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 8011d641b..655ec6c0e 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -30,7 +30,7 @@ jobs: env: POSTGRES_ADDR: postgres://vela:notARealPassword12345@localhost:5432/vela - SQLITE_ADDR: file::memory:?cache=shared + SQLITE_ADDR: vela.db steps: - name: clone From 95ed34bc76fbc6527b485516e7d3a6ded128d81c Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Tue, 11 Jul 2023 14:41:10 -0500 Subject: [PATCH 58/64] fix(database/hook): unique constraints for CreateSqliteTable --- database/hook/table.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/hook/table.go b/database/hook/table.go index 9be4616c4..90419508f 100644 --- a/database/hook/table.go +++ b/database/hook/table.go @@ -51,7 +51,7 @@ hooks ( status TEXT, link TEXT, webhook_id INTEGER, - UNIQUE(repo_id, build_id) + UNIQUE(repo_id, number) ); ` ) From 387eed094caf803ced96062ea3326c498ef48f43 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Tue, 11 Jul 2023 14:55:44 -0500 Subject: [PATCH 59/64] fix(database/logs): consistency between drivers --- database/integration_test.go | 4 ++-- database/log/list_build.go | 1 + database/log/list_build_test.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 778c30849..d85442d98 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -539,8 +539,8 @@ func testLogs(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Logs) { t.Errorf("ListLogsForBuild() is %v, want %v", count, len(resources.Logs)) } - if !reflect.DeepEqual(list, []*library.Log{resources.Logs[2], resources.Logs[3], resources.Logs[0], resources.Logs[1]}) { - t.Errorf("ListLogsForBuild() is %v, want %v", list, []*library.Log{resources.Logs[2], resources.Logs[3], resources.Logs[0], resources.Logs[1]}) + if !reflect.DeepEqual(list, resources.Logs) { + t.Errorf("ListLogsForBuild() is %v, want %v", list, resources.Logs) } counter++ diff --git a/database/log/list_build.go b/database/log/list_build.go index 58ca12111..ab083a706 100644 --- a/database/log/list_build.go +++ b/database/log/list_build.go @@ -37,6 +37,7 @@ func (e *engine) ListLogsForBuild(b *library.Build, page, perPage int) ([]*libra err = e.client. Table(constants.TableLog). Where("build_id = ?", b.GetID()). + Order("service_id ASC NULLS LAST"). Order("step_id ASC"). Limit(perPage). Offset(offset). diff --git a/database/log/list_build_test.go b/database/log/list_build_test.go index fb08236e9..cf20fb50e 100644 --- a/database/log/list_build_test.go +++ b/database/log/list_build_test.go @@ -49,7 +49,7 @@ func TestLog_Engine_ListLogsForBuild(t *testing.T) { AddRow(1, 1, 1, 1, 0, []byte{}).AddRow(2, 1, 1, 0, 1, []byte{}) // ensure the mock expects the query - _mock.ExpectQuery(`SELECT * FROM "logs" WHERE build_id = $1 ORDER BY step_id ASC LIMIT 10`).WithArgs(1).WillReturnRows(_rows) + _mock.ExpectQuery(`SELECT * FROM "logs" WHERE build_id = $1 ORDER BY service_id ASC NULLS LAST,step_id ASC LIMIT 10`).WithArgs(1).WillReturnRows(_rows) _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() From ea17b6678148e3e22bcf1e7b364375903bd5fbe3 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Tue, 25 Jul 2023 09:31:46 -0500 Subject: [PATCH 60/64] fix: issues from merge --- database/integration_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index d85442d98..1fb2a4d8b 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -152,7 +152,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { // create the repos for build related functions for _, repo := range resources.Repos { - err := db.CreateRepo(repo) + _, err := db.CreateRepo(repo) if err != nil { t.Errorf("unable to create repo %d: %v", repo.GetID(), err) } @@ -723,7 +723,7 @@ func testRepos(t *testing.T, db Interface, resources *Resources) { // create the repos for _, repo := range resources.Repos { - err := db.CreateRepo(repo) + _, err := db.CreateRepo(repo) if err != nil { t.Errorf("unable to create repo %d: %v", repo.GetID(), err) } @@ -811,7 +811,7 @@ func testRepos(t *testing.T, db Interface, resources *Resources) { // update the repos for _, repo := range resources.Repos { repo.SetActive(false) - err = db.UpdateRepo(repo) + _, err = db.UpdateRepo(repo) if err != nil { t.Errorf("unable to update repo %d: %v", repo.GetID(), err) } From 3ed7f45bf9bc9d20a4e82ad74a9f03cbd32e36ab Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Tue, 25 Jul 2023 10:03:09 -0500 Subject: [PATCH 61/64] chore: add missing comment --- database/integration_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/database/integration_test.go b/database/integration_test.go index 1fb2a4d8b..40566c146 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -27,6 +27,7 @@ import ( "github.com/go-vela/types/raw" ) +// Resources represents the object containing test resources. type Resources struct { Builds []*library.Build Deployments []*library.Deployment From 221cb082505aa5f1f4c432b0372118f4bd621952 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Fri, 28 Jul 2023 13:45:06 -0500 Subject: [PATCH 62/64] chore: address review feedback --- database/integration_test.go | 624 ++++++++++++++++++++++------------- database/vela.db | Bin 0 -> 172032 bytes 2 files changed, 388 insertions(+), 236 deletions(-) create mode 100644 database/vela.db diff --git a/database/integration_test.go b/database/integration_test.go index 40566c146..420e38862 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -56,19 +56,19 @@ func TestDatabase_Integration(t *testing.T) { name string config *config }{ - { - name: "postgres", - config: &config{ - Driver: "postgres", - Address: os.Getenv("POSTGRES_ADDR"), - CompressionLevel: 3, - ConnectionLife: 10 * time.Second, - ConnectionIdle: 5, - ConnectionOpen: 20, - EncryptionKey: "A1B2C3D4E5G6H7I8J9K0LMNOPQRSTUVW", - SkipCreation: false, - }, - }, + //{ + // name: "postgres", + // config: &config{ + // Driver: "postgres", + // Address: os.Getenv("POSTGRES_ADDR"), + // CompressionLevel: 3, + // ConnectionLife: 10 * time.Second, + // ConnectionIdle: 5, + // ConnectionOpen: 20, + // EncryptionKey: "A1B2C3D4E5G6H7I8J9K0LMNOPQRSTUVW", + // SkipCreation: false, + // }, + //}, { name: "sqlite3", config: &config{ @@ -145,11 +145,22 @@ func TestDatabase_Integration(t *testing.T) { } func testBuilds(t *testing.T, db Interface, resources *Resources) { - // used to track the number of methods we call for builds - // - // we start at 2 for creating the table and indexes for builds - // since those are already called when the database engine starts - counter := 2 + // create a variable to track the number of methods called for builds + methods := make(map[string]bool) + // capture the element type of the build interface + element := reflect.TypeOf(new(build.BuildInterface)).Elem() + // iterate through all methods found in the build interface + for i := 0; i < element.NumMethod(); i++ { + // skip tracking the methods to create indexes and tables for builds + // 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 repos for build related functions for _, repo := range resources.Repos { @@ -180,7 +191,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to create build %d: %v", build.GetID(), err) } } - counter++ + methods["CreateBuild"] = true // count the builds count, err := db.CountBuilds() @@ -190,7 +201,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Builds) { t.Errorf("CountBuilds() is %v, want %v", count, len(resources.Builds)) } - counter++ + methods["CountBuilds"] = true // count the builds for a deployment count, err = db.CountBuildsForDeployment(resources.Deployments[0], nil) @@ -200,7 +211,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Builds) { t.Errorf("CountBuildsForDeployment() is %v, want %v", count, len(resources.Builds)) } - counter++ + methods["CountBuildsForDeployment"] = true // count the builds for an org count, err = db.CountBuildsForOrg(resources.Repos[0].GetOrg(), nil) @@ -210,7 +221,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Builds) { t.Errorf("CountBuildsForOrg() is %v, want %v", count, len(resources.Builds)) } - counter++ + methods["CountBuildsForOrg"] = true // count the builds for a repo count, err = db.CountBuildsForRepo(resources.Repos[0], nil) @@ -220,7 +231,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Builds) { t.Errorf("CountBuildsForRepo() is %v, want %v", count, len(resources.Builds)) } - counter++ + methods["CountBuildsForRepo"] = true // count the builds for a status count, err = db.CountBuildsForStatus("running", nil) @@ -230,7 +241,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Builds) { t.Errorf("CountBuildsForStatus() is %v, want %v", count, len(resources.Builds)) } - counter++ + methods["CountBuildsForStatus"] = true // list the builds list, err := db.ListBuilds() @@ -240,7 +251,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Builds) { t.Errorf("ListBuilds() is %v, want %v", list, resources.Builds) } - counter++ + methods["ListBuilds"] = true // list the builds for a deployment list, count, err = db.ListBuildsForDeployment(resources.Deployments[0], nil, 1, 10) @@ -253,7 +264,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, []*library.Build{resources.Builds[1], resources.Builds[0]}) { t.Errorf("ListBuildsForDeployment() is %v, want %v", list, []*library.Build{resources.Builds[1], resources.Builds[0]}) } - counter++ + methods["ListBuildsForDeployment"] = true // list the builds for an org list, count, err = db.ListBuildsForOrg(resources.Repos[0].GetOrg(), nil, 1, 10) @@ -266,7 +277,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Builds) { t.Errorf("ListBuildsForOrg() is %v, want %v", list, resources.Builds) } - counter++ + methods["ListBuildsForOrg"] = true // list the builds for a repo list, count, err = db.ListBuildsForRepo(resources.Repos[0], nil, time.Now().UTC().Unix(), 0, 1, 10) @@ -279,7 +290,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, []*library.Build{resources.Builds[1], resources.Builds[0]}) { t.Errorf("ListBuildsForRepo() is %v, want %v", list, []*library.Build{resources.Builds[1], resources.Builds[0]}) } - counter++ + methods["ListBuildsForRepo"] = true // list the pending and running builds queueList, err := db.ListPendingAndRunningBuilds("0") @@ -289,7 +300,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(queueList, queueBuilds) { t.Errorf("ListPendingAndRunningBuilds() is %v, want %v", queueList, queueBuilds) } - counter++ + methods["ListPendingAndRunningBuilds"] = true // lookup the last build by repo got, err := db.LastBuildForRepo(resources.Repos[0], "main") @@ -299,7 +310,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(got, resources.Builds[1]) { t.Errorf("LastBuildForRepo() is %v, want %v", got, resources.Builds[1]) } - counter++ + methods["LastBuildForRepo"] = true // lookup the builds by repo and number for _, build := range resources.Builds { @@ -312,7 +323,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetBuildForRepo() is %v, want %v", got, build) } } - counter++ + methods["GetBuildForRepo"] = true // clean the builds count, err = db.CleanBuilds("integration testing", 1563474090) @@ -322,7 +333,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Builds) { t.Errorf("CleanBuilds() is %v, want %v", count, len(resources.Builds)) } - counter++ + methods["CleanBuilds"] = true // update the builds for _, build := range resources.Builds { @@ -341,8 +352,8 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetBuild() is %v, want %v", got, build) } } - counter++ - counter++ + methods["UpdateBuild"] = true + methods["GetBuild"] = true // delete the builds for _, build := range resources.Builds { @@ -351,29 +362,41 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to delete build %d: %v", build.GetID(), err) } } - counter++ + methods["DeleteBuild"] = true // delete the repos for build related functions for _, repo := range resources.Repos { - err := db.DeleteRepo(repo) + err = db.DeleteRepo(repo) if err != nil { t.Errorf("unable to delete repo %d: %v", repo.GetID(), err) } } - // ensure we called all the functions we should have - methods := reflect.TypeOf(new(build.BuildInterface)).Elem().NumMethod() - if counter != methods { - t.Errorf("total number of methods called is %v, want %v", counter, methods) + // ensure we called all the methods we expected to + for method, called := range methods { + if !called { + t.Errorf("method %s was not called for builds", method) + } } } func testHooks(t *testing.T, db Interface, resources *Resources) { - // used to track the number of methods we call for hooks - // - // we start at 2 for creating the table and indexes for hooks - // since those are already called when the database engine starts - counter := 2 + // create a variable to track the number of methods called for hooks + methods := make(map[string]bool) + // capture the element type of the hook interface + element := reflect.TypeOf(new(hook.HookInterface)).Elem() + // iterate through all methods found in the hook interface + for i := 0; i < element.NumMethod(); i++ { + // skip tracking the methods to create indexes and tables for hooks + // 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 hooks for _, hook := range resources.Hooks { @@ -382,7 +405,7 @@ func testHooks(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to create hook %d: %v", hook.GetID(), err) } } - counter++ + methods["CreateHook"] = true // count the hooks count, err := db.CountHooks() @@ -392,7 +415,7 @@ func testHooks(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Hooks) { t.Errorf("CountHooks() is %v, want %v", count, len(resources.Hooks)) } - counter++ + methods["CountHooks"] = true // count the hooks for a repo count, err = db.CountHooksForRepo(resources.Repos[0]) @@ -402,7 +425,7 @@ func testHooks(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Builds) { t.Errorf("CountHooksForRepo() is %v, want %v", count, len(resources.Builds)) } - counter++ + methods["CountHooksForRepo"] = true // list the hooks list, err := db.ListHooks() @@ -412,7 +435,7 @@ func testHooks(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Hooks) { t.Errorf("ListHooks() is %v, want %v", list, resources.Hooks) } - counter++ + methods["ListHooks"] = true // list the hooks for a repo list, count, err = db.ListHooksForRepo(resources.Repos[0], 1, 10) @@ -425,7 +448,7 @@ func testHooks(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, []*library.Hook{resources.Hooks[1], resources.Hooks[0]}) { t.Errorf("ListHooksForRepo() is %v, want %v", list, []*library.Hook{resources.Hooks[1], resources.Hooks[0]}) } - counter++ + methods["ListHooksForRepo"] = true // lookup the last build by repo got, err := db.LastHookForRepo(resources.Repos[0]) @@ -435,12 +458,12 @@ func testHooks(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(got, resources.Hooks[1]) { t.Errorf("LastHookForRepo() is %v, want %v", got, resources.Hooks[1]) } - counter++ + methods["LastHookForRepo"] = true // lookup the hooks by name for _, hook := range resources.Hooks { repo := resources.Repos[hook.GetRepoID()-1] - got, err := db.GetHookForRepo(repo, hook.GetNumber()) + got, err = db.GetHookForRepo(repo, hook.GetNumber()) if err != nil { t.Errorf("unable to get hook %d for repo %d: %v", hook.GetID(), repo.GetID(), err) } @@ -448,7 +471,7 @@ func testHooks(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetHookForRepo() is %v, want %v", got, hook) } } - counter++ + methods["GetHookForRepo"] = true // update the hooks for _, hook := range resources.Hooks { @@ -459,7 +482,7 @@ func testHooks(t *testing.T, db Interface, resources *Resources) { } // lookup the hook by ID - got, err := db.GetHook(hook.GetID()) + got, err = db.GetHook(hook.GetID()) if err != nil { t.Errorf("unable to get hook %d by ID: %v", hook.GetID(), err) } @@ -467,8 +490,8 @@ func testHooks(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetHook() is %v, want %v", got, hook) } } - counter++ - counter++ + methods["UpdateHook"] = true + methods["GetHook"] = true // delete the hooks for _, hook := range resources.Hooks { @@ -477,21 +500,33 @@ func testHooks(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to delete hook %d: %v", hook.GetID(), err) } } - counter++ + methods["DeleteHook"] = true - // ensure we called all the functions we should have - methods := reflect.TypeOf(new(hook.HookInterface)).Elem().NumMethod() - if counter != methods { - t.Errorf("total number of methods called is %v, want %v", counter, methods) + // ensure we called all the methods we expected to + for method, called := range methods { + if !called { + t.Errorf("method %s was not called for hooks", method) + } } } func testLogs(t *testing.T, db Interface, resources *Resources) { - // used to track the number of methods we call for logs - // - // we start at 2 for creating the table and indexes for logs - // since those are already called when the database engine starts - counter := 2 + // create a variable to track the number of methods called for logs + methods := make(map[string]bool) + // capture the element type of the log interface + element := reflect.TypeOf(new(log.LogInterface)).Elem() + // iterate through all methods found in the log interface + for i := 0; i < element.NumMethod(); i++ { + // skip tracking the methods to create indexes and tables for logs + // 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 logs for _, log := range resources.Logs { @@ -500,7 +535,7 @@ func testLogs(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to create log %d: %v", log.GetID(), err) } } - counter++ + methods["CreateLog"] = true // count the logs count, err := db.CountLogs() @@ -510,7 +545,7 @@ func testLogs(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Logs) { t.Errorf("CountLogs() is %v, want %v", count, len(resources.Logs)) } - counter++ + methods["CountLogs"] = true // count the logs for a build count, err = db.CountLogsForBuild(resources.Builds[0]) @@ -520,7 +555,7 @@ func testLogs(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Logs) { t.Errorf("CountLogs() is %v, want %v", count, len(resources.Logs)) } - counter++ + methods["CountLogsForBuild"] = true // list the logs list, err := db.ListLogs() @@ -530,7 +565,7 @@ func testLogs(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Logs) { t.Errorf("ListLogs() is %v, want %v", list, resources.Logs) } - counter++ + methods["ListLogs"] = true // list the logs for a build list, count, err = db.ListLogsForBuild(resources.Builds[0], 1, 10) @@ -543,7 +578,7 @@ func testLogs(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Logs) { t.Errorf("ListLogsForBuild() is %v, want %v", list, resources.Logs) } - counter++ + methods["ListLogsForBuild"] = true // lookup the logs by service for _, log := range []*library.Log{resources.Logs[0], resources.Logs[1]} { @@ -556,7 +591,7 @@ func testLogs(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetLogForService() is %v, want %v", got, log) } } - counter++ + methods["GetLogForService"] = true // lookup the logs by service for _, log := range []*library.Log{resources.Logs[2], resources.Logs[3]} { @@ -569,7 +604,7 @@ func testLogs(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetLogForStep() is %v, want %v", got, log) } } - counter++ + methods["GetLogForStep"] = true // update the logs for _, log := range resources.Logs { @@ -588,8 +623,8 @@ func testLogs(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetLog() is %v, want %v", got, log) } } - counter++ - counter++ + methods["UpdateLog"] = true + methods["GetLog"] = true // delete the logs for _, log := range resources.Logs { @@ -598,21 +633,33 @@ func testLogs(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to delete log %d: %v", log.GetID(), err) } } - counter++ + methods["DeleteLog"] = true - // ensure we called all the functions we should have - methods := reflect.TypeOf(new(log.LogInterface)).Elem().NumMethod() - if counter != methods { - t.Errorf("total number of methods called is %v, want %v", counter, methods) + // ensure we called all the methods we expected to + for method, called := range methods { + if !called { + t.Errorf("method %s was not called for logs", method) + } } } func testPipelines(t *testing.T, db Interface, resources *Resources) { - // used to track the number of methods we call for pipelines - // - // we start at 2 for creating the table and indexes for pipelines - // since those are already called when the database engine starts - counter := 2 + // 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(pipeline.PipelineInterface)).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 _, pipeline := range resources.Pipelines { @@ -621,7 +668,7 @@ func testPipelines(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to create pipeline %d: %v", pipeline.GetID(), err) } } - counter++ + methods["CreatePipeline"] = true // count the pipelines count, err := db.CountPipelines() @@ -631,7 +678,7 @@ func testPipelines(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Pipelines) { t.Errorf("CountPipelines() is %v, want %v", count, len(resources.Pipelines)) } - counter++ + methods["CountPipelines"] = true // count the pipelines for a repo count, err = db.CountPipelinesForRepo(resources.Repos[0]) @@ -641,7 +688,7 @@ func testPipelines(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Pipelines) { t.Errorf("CountPipelinesForRepo() is %v, want %v", count, len(resources.Pipelines)) } - counter++ + methods["CountPipelinesForRepo"] = true // list the pipelines list, err := db.ListPipelines() @@ -651,7 +698,7 @@ func testPipelines(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Pipelines) { t.Errorf("ListPipelines() is %v, want %v", list, resources.Pipelines) } - counter++ + methods["ListPipelines"] = true // list the pipelines for a repo list, count, err = db.ListPipelinesForRepo(resources.Repos[0], 1, 10) @@ -664,7 +711,7 @@ func testPipelines(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Pipelines) { t.Errorf("ListPipelines() is %v, want %v", list, resources.Pipelines) } - counter++ + methods["ListPipelinesForRepo"] = true // lookup the pipelines by name for _, pipeline := range resources.Pipelines { @@ -677,7 +724,7 @@ func testPipelines(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetPipelineForRepo() is %v, want %v", got, pipeline) } } - counter++ + methods["GetPipelineForRepo"] = true // update the pipelines for _, pipeline := range resources.Pipelines { @@ -696,8 +743,8 @@ func testPipelines(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetPipeline() is %v, want %v", got, pipeline) } } - counter++ - counter++ + methods["UpdatePipeline"] = true + methods["GetPipeline"] = true // delete the pipelines for _, pipeline := range resources.Pipelines { @@ -706,21 +753,33 @@ func testPipelines(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to delete pipeline %d: %v", pipeline.GetID(), err) } } - counter++ + methods["DeletePipeline"] = true - // ensure we called all the functions we should have - methods := reflect.TypeOf(new(pipeline.PipelineInterface)).Elem().NumMethod() - if counter != methods { - t.Errorf("total number of methods called is %v, want %v", counter, methods) + // 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 testRepos(t *testing.T, db Interface, resources *Resources) { - // used to track the number of methods we call for repos - // - // we start at 2 for creating the table and indexes for repos - // since those are already called when the database engine starts - counter := 2 + // create a variable to track the number of methods called for repos + methods := make(map[string]bool) + // capture the element type of the repo interface + element := reflect.TypeOf(new(repo.RepoInterface)).Elem() + // iterate through all methods found in the repo interface + for i := 0; i < element.NumMethod(); i++ { + // skip tracking the methods to create indexes and tables for repos + // 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 repos for _, repo := range resources.Repos { @@ -729,7 +788,7 @@ func testRepos(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to create repo %d: %v", repo.GetID(), err) } } - counter++ + methods["CreateRepo"] = true // count the repos count, err := db.CountRepos() @@ -739,7 +798,7 @@ func testRepos(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Repos) { t.Errorf("CountRepos() is %v, want %v", count, len(resources.Repos)) } - counter++ + methods["CountRepos"] = true // count the repos for an org count, err = db.CountReposForOrg(resources.Repos[0].GetOrg(), nil) @@ -749,7 +808,7 @@ func testRepos(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Repos) { t.Errorf("CountReposForOrg() is %v, want %v", count, len(resources.Repos)) } - counter++ + methods["CountReposForOrg"] = true // count the repos for a user count, err = db.CountReposForUser(resources.Users[0], nil) @@ -759,7 +818,7 @@ func testRepos(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Repos) { t.Errorf("CountReposForUser() is %v, want %v", count, len(resources.Repos)) } - counter++ + methods["CountReposForUser"] = true // list the repos list, err := db.ListRepos() @@ -769,7 +828,7 @@ func testRepos(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Repos) { t.Errorf("ListRepos() is %v, want %v", list, resources.Repos) } - counter++ + methods["ListRepos"] = true // list the repos for an org list, count, err = db.ListReposForOrg(resources.Repos[0].GetOrg(), "name", nil, 1, 10) @@ -782,7 +841,7 @@ func testRepos(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Repos) { t.Errorf("ListReposForOrg() is %v, want %v", list, resources.Repos) } - counter++ + methods["ListReposForOrg"] = true // list the repos for a user list, count, err = db.ListReposForUser(resources.Users[0], "name", nil, 1, 10) @@ -795,7 +854,7 @@ func testRepos(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Repos) { t.Errorf("ListReposForUser() is %v, want %v", list, resources.Repos) } - counter++ + methods["ListReposForUser"] = true // lookup the repos by name for _, repo := range resources.Repos { @@ -807,7 +866,7 @@ func testRepos(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetRepoForOrg() is %v, want %v", got, repo) } } - counter++ + methods["GetRepoForOrg"] = true // update the repos for _, repo := range resources.Repos { @@ -826,8 +885,8 @@ func testRepos(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetRepo() is %v, want %v", got, repo) } } - counter++ - counter++ + methods["UpdateRepo"] = true + methods["GetRepo"] = true // delete the repos for _, repo := range resources.Repos { @@ -836,21 +895,33 @@ func testRepos(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to delete repo %d: %v", repo.GetID(), err) } } - counter++ + methods["DeleteRepo"] = true - // ensure we called all the functions we should have - methods := reflect.TypeOf(new(repo.RepoInterface)).Elem().NumMethod() - if counter != methods { - t.Errorf("total number of methods called is %v, want %v", counter, methods) + // ensure we called all the methods we expected to + for method, called := range methods { + if !called { + t.Errorf("method %s was not called for repos", method) + } } } func testSchedules(t *testing.T, db Interface, resources *Resources) { - // used to track the number of methods we call for schedules - // - // we start at 2 for creating the table and indexes for schedules - // since those are already called when the database engine starts - counter := 2 + // create a variable to track the number of methods called for schedules + methods := make(map[string]bool) + // capture the element type of the schedule interface + element := reflect.TypeOf(new(schedule.ScheduleInterface)).Elem() + // iterate through all methods found in the schedule interface + for i := 0; i < element.NumMethod(); i++ { + // skip tracking the methods to create indexes and tables for schedules + // 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 schedules for _, schedule := range resources.Schedules { @@ -859,7 +930,7 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to create schedule %d: %v", schedule.GetID(), err) } } - counter++ + methods["CreateSchedule"] = true // count the schedules count, err := db.CountSchedules() @@ -869,7 +940,7 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Schedules) { t.Errorf("CountSchedules() is %v, want %v", count, len(resources.Schedules)) } - counter++ + methods["CountSchedules"] = true // count the schedules for a repo count, err = db.CountSchedulesForRepo(resources.Repos[0]) @@ -879,7 +950,7 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Schedules) { t.Errorf("CountSchedulesForRepo() is %v, want %v", count, len(resources.Schedules)) } - counter++ + methods["CountSchedulesForRepo"] = true // list the schedules list, err := db.ListSchedules() @@ -889,7 +960,7 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Schedules) { t.Errorf("ListSchedules() is %v, want %v", list, resources.Schedules) } - counter++ + methods["ListSchedules"] = true // list the active schedules list, err = db.ListActiveSchedules() @@ -899,7 +970,7 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Schedules) { t.Errorf("ListActiveSchedules() is %v, want %v", list, resources.Schedules) } - counter++ + methods["ListActiveSchedules"] = true // list the schedules for a repo list, count, err = db.ListSchedulesForRepo(resources.Repos[0], 1, 10) @@ -912,7 +983,7 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, []*library.Schedule{resources.Schedules[1], resources.Schedules[0]}) { t.Errorf("ListSchedulesForRepo() is %v, want %v", list, []*library.Schedule{resources.Schedules[1], resources.Schedules[0]}) } - counter++ + methods["ListSchedulesForRepo"] = true // lookup the schedules by name for _, schedule := range resources.Schedules { @@ -925,7 +996,7 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetScheduleForRepo() is %v, want %v", got, schedule) } } - counter++ + methods["GetScheduleForRepo"] = true // update the schedules for _, schedule := range resources.Schedules { @@ -944,8 +1015,8 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetSchedule() is %v, want %v", got, schedule) } } - counter++ - counter++ + methods["UpdateSchedule"] = true + methods["GetSchedule"] = true // delete the schedules for _, schedule := range resources.Schedules { @@ -954,21 +1025,33 @@ func testSchedules(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to delete schedule %d: %v", schedule.GetID(), err) } } - counter++ + methods["DeleteSchedule"] = true - // ensure we called all the functions we should have - methods := reflect.TypeOf(new(schedule.ScheduleInterface)).Elem().NumMethod() - if counter != methods { - t.Errorf("total number of methods called is %v, want %v", counter, methods) + // ensure we called all the methods we expected to + for method, called := range methods { + if !called { + t.Errorf("method %s was not called for schedules", method) + } } } func testSecrets(t *testing.T, db Interface, resources *Resources) { - // used to track the number of methods we call for secrets - // - // we start at 2 for creating the table and indexes for secrets - // since those are already called when the database engine starts - counter := 2 + // create a variable to track the number of methods called for secrets + methods := make(map[string]bool) + // capture the element type of the secret interface + element := reflect.TypeOf(new(secret.SecretInterface)).Elem() + // iterate through all methods found in the secret interface + for i := 0; i < element.NumMethod(); i++ { + // skip tracking the methods to create indexes and tables for secrets + // 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 secrets for _, secret := range resources.Secrets { @@ -977,7 +1060,7 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to create secret %d: %v", secret.GetID(), err) } } - counter++ + methods["CreateSecret"] = true // count the secrets count, err := db.CountSecrets() @@ -987,7 +1070,7 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Secrets) { t.Errorf("CountSecrets() is %v, want %v", count, len(resources.Secrets)) } - counter++ + methods["CountSecrets"] = true for _, secret := range resources.Secrets { switch secret.GetType() { @@ -1000,7 +1083,7 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if int(count) != 1 { t.Errorf("CountSecretsForOrg() is %v, want %v", count, 1) } - counter++ + methods["CountSecretsForOrg"] = true case constants.SecretRepo: // count the secrets for a repo count, err = db.CountSecretsForRepo(resources.Repos[0], nil) @@ -1010,7 +1093,7 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if int(count) != 1 { t.Errorf("CountSecretsForRepo() is %v, want %v", count, 1) } - counter++ + methods["CountSecretsForRepo"] = true case constants.SecretShared: // count the secrets for a team count, err = db.CountSecretsForTeam(secret.GetOrg(), secret.GetTeam(), nil) @@ -1020,7 +1103,7 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if int(count) != 1 { t.Errorf("CountSecretsForTeam() is %v, want %v", count, 1) } - counter++ + methods["CountSecretsForTeam"] = true // count the secrets for a list of teams count, err = db.CountSecretsForTeams(secret.GetOrg(), []string{secret.GetTeam()}, nil) @@ -1030,7 +1113,7 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if int(count) != 1 { t.Errorf("CountSecretsForTeams() is %v, want %v", count, 1) } - counter++ + methods["CountSecretsForTeams"] = true default: t.Errorf("unsupported type %s for secret %d", secret.GetType(), secret.GetID()) } @@ -1044,7 +1127,7 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Secrets) { t.Errorf("ListSecrets() is %v, want %v", list, resources.Secrets) } - counter++ + methods["ListSecrets"] = true for _, secret := range resources.Secrets { switch secret.GetType() { @@ -1060,7 +1143,7 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, []*library.Secret{secret}) { t.Errorf("ListSecretsForOrg() is %v, want %v", list, []*library.Secret{secret}) } - counter++ + methods["ListSecretsForOrg"] = true case constants.SecretRepo: // list the secrets for a repo list, count, err = db.ListSecretsForRepo(resources.Repos[0], nil, 1, 10) @@ -1073,7 +1156,7 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, []*library.Secret{secret}) { t.Errorf("ListSecretsForRepo() is %v, want %v", list, []*library.Secret{secret}) } - counter++ + methods["ListSecretsForRepo"] = true case constants.SecretShared: // list the secrets for a team list, count, err = db.ListSecretsForTeam(secret.GetOrg(), secret.GetTeam(), nil, 1, 10) @@ -1086,7 +1169,7 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, []*library.Secret{secret}) { t.Errorf("ListSecretsForTeam() is %v, want %v", list, []*library.Secret{secret}) } - counter++ + methods["ListSecretsForTeam"] = true // list the secrets for a list of teams list, count, err = db.ListSecretsForTeams(secret.GetOrg(), []string{secret.GetTeam()}, nil, 1, 10) @@ -1099,7 +1182,7 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, []*library.Secret{secret}) { t.Errorf("ListSecretsForTeams() is %v, want %v", list, []*library.Secret{secret}) } - counter++ + methods["ListSecretsForTeams"] = true default: t.Errorf("unsupported type %s for secret %d", secret.GetType(), secret.GetID()) } @@ -1116,7 +1199,7 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(got, secret) { t.Errorf("GetSecretForOrg() is %v, want %v", got, secret) } - counter++ + methods["GetSecretForOrg"] = true case constants.SecretRepo: // lookup the secret by repo got, err := db.GetSecretForRepo(secret.GetName(), resources.Repos[0]) @@ -1126,7 +1209,7 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(got, secret) { t.Errorf("GetSecretForRepo() is %v, want %v", got, secret) } - counter++ + methods["GetSecretForRepo"] = true case constants.SecretShared: // lookup the secret by team got, err := db.GetSecretForTeam(secret.GetOrg(), secret.GetTeam(), secret.GetName()) @@ -1136,7 +1219,7 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(got, secret) { t.Errorf("GetSecretForTeam() is %v, want %v", got, secret) } - counter++ + methods["GetSecretForTeam"] = true default: t.Errorf("unsupported type %s for secret %d", secret.GetType(), secret.GetID()) } @@ -1159,8 +1242,8 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetSecret() is %v, want %v", got, secret) } } - counter++ - counter++ + methods["UpdateSecret"] = true + methods["GetSecret"] = true // delete the secrets for _, secret := range resources.Secrets { @@ -1169,21 +1252,33 @@ func testSecrets(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to delete secret %d: %v", secret.GetID(), err) } } - counter++ + methods["DeleteSecret"] = true - // ensure we called all the functions we should have - methods := reflect.TypeOf(new(secret.SecretInterface)).Elem().NumMethod() - if counter != methods { - t.Errorf("total number of methods called is %v, want %v", counter, methods) + // ensure we called all the methods we expected to + for method, called := range methods { + if !called { + t.Errorf("method %s was not called for secrets", method) + } } } func testServices(t *testing.T, db Interface, resources *Resources) { - // used to track the number of methods we call for services - // - // we start at 2 for creating the table and indexes for services - // since those are already called when the database engine starts - counter := 2 + // create a variable to track the number of methods called for services + methods := make(map[string]bool) + // capture the element type of the service interface + element := reflect.TypeOf(new(service.ServiceInterface)).Elem() + // iterate through all methods found in the service interface + for i := 0; i < element.NumMethod(); i++ { + // skip tracking the methods to create indexes and tables for services + // 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 services for _, service := range resources.Services { @@ -1192,7 +1287,7 @@ func testServices(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to create service %d: %v", service.GetID(), err) } } - counter++ + methods["CreateService"] = true // count the services count, err := db.CountServices() @@ -1202,7 +1297,7 @@ func testServices(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Services) { t.Errorf("CountServices() is %v, want %v", count, len(resources.Services)) } - counter++ + methods["CountServices"] = true // count the services for a build count, err = db.CountServicesForBuild(resources.Builds[0], nil) @@ -1212,7 +1307,7 @@ func testServices(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Services) { t.Errorf("CountServicesForBuild() is %v, want %v", count, len(resources.Services)) } - counter++ + methods["CountServicesForBuild"] = true // list the services list, err := db.ListServices() @@ -1222,7 +1317,7 @@ func testServices(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Services) { t.Errorf("ListServices() is %v, want %v", list, resources.Services) } - counter++ + methods["ListServices"] = true // list the services for a build list, count, err = db.ListServicesForBuild(resources.Builds[0], nil, 1, 10) @@ -1235,7 +1330,7 @@ func testServices(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Services) { t.Errorf("ListServicesForBuild() is %v, want %v", count, len(resources.Services)) } - counter++ + methods["ListServicesForBuild"] = true expected := map[string]float64{ "#init": 1, @@ -1248,7 +1343,7 @@ func testServices(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(images, expected) { t.Errorf("ListServiceImageCount() is %v, want %v", images, expected) } - counter++ + methods["ListServiceImageCount"] = true expected = map[string]float64{ "pending": 1, @@ -1264,7 +1359,7 @@ func testServices(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(statuses, expected) { t.Errorf("ListServiceStatusCount() is %v, want %v", statuses, expected) } - counter++ + methods["ListServiceStatusCount"] = true // lookup the services by name for _, service := range resources.Services { @@ -1277,7 +1372,17 @@ func testServices(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetServiceForBuild() is %v, want %v", got, service) } } - counter++ + methods["GetServiceForBuild"] = true + + // clean the services + count, err = db.CleanServices("integration testing", 1563474090) + if err != nil { + t.Errorf("unable to clean services: %v", err) + } + if int(count) != len(resources.Services) { + t.Errorf("CleanServices() is %v, want %v", count, len(resources.Services)) + } + methods["CleanServices"] = true // update the services for _, service := range resources.Services { @@ -1296,8 +1401,8 @@ func testServices(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetService() is %v, want %v", got, service) } } - counter++ - counter++ + methods["UpdateService"] = true + methods["GetService"] = true // delete the services for _, service := range resources.Services { @@ -1306,21 +1411,33 @@ func testServices(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to delete service %d: %v", service.GetID(), err) } } - counter++ + methods["DeleteService"] = true - // ensure we called all the functions we should have - methods := reflect.TypeOf(new(service.ServiceInterface)).Elem().NumMethod() - if counter != methods { - t.Errorf("total number of methods called is %v, want %v", counter, methods) + // ensure we called all the methods we expected to + for method, called := range methods { + if !called { + t.Errorf("method %s was not called for services", method) + } } } func testSteps(t *testing.T, db Interface, resources *Resources) { - // used to track the number of methods we call for steps - // - // we start at 2 for creating the table and indexes for steps - // since those are already called when the database engine starts - counter := 2 + // create a variable to track the number of methods called for steps + methods := make(map[string]bool) + // capture the element type of the step interface + element := reflect.TypeOf(new(step.StepInterface)).Elem() + // iterate through all methods found in the step interface + for i := 0; i < element.NumMethod(); i++ { + // skip tracking the methods to create indexes and tables for steps + // 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 steps for _, step := range resources.Steps { @@ -1329,7 +1446,7 @@ func testSteps(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to create step %d: %v", step.GetID(), err) } } - counter++ + methods["CreateStep"] = true // count the steps count, err := db.CountSteps() @@ -1339,7 +1456,7 @@ func testSteps(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Steps) { t.Errorf("CountSteps() is %v, want %v", count, len(resources.Steps)) } - counter++ + methods["CountSteps"] = true // count the steps for a build count, err = db.CountStepsForBuild(resources.Builds[0], nil) @@ -1349,7 +1466,7 @@ func testSteps(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Steps) { t.Errorf("CountStepsForBuild() is %v, want %v", count, len(resources.Steps)) } - counter++ + methods["CountStepsForBuild"] = true // list the steps list, err := db.ListSteps() @@ -1359,7 +1476,7 @@ func testSteps(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Steps) { t.Errorf("ListSteps() is %v, want %v", list, resources.Steps) } - counter++ + methods["ListSteps"] = true // list the steps for a build list, count, err = db.ListStepsForBuild(resources.Builds[0], nil, 1, 10) @@ -1372,7 +1489,7 @@ func testSteps(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Steps) { t.Errorf("ListStepsForBuild() is %v, want %v", count, len(resources.Steps)) } - counter++ + methods["ListStepsForBuild"] = true expected := map[string]float64{ "#init": 1, @@ -1385,7 +1502,7 @@ func testSteps(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(images, expected) { t.Errorf("ListStepImageCount() is %v, want %v", images, expected) } - counter++ + methods["ListStepImageCount"] = true expected = map[string]float64{ "pending": 1, @@ -1401,7 +1518,7 @@ func testSteps(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(statuses, expected) { t.Errorf("ListStepStatusCount() is %v, want %v", statuses, expected) } - counter++ + methods["ListStepStatusCount"] = true // lookup the steps by name for _, step := range resources.Steps { @@ -1414,7 +1531,17 @@ func testSteps(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetStepForBuild() is %v, want %v", got, step) } } - counter++ + methods["GetStepForBuild"] = true + + // clean the steps + count, err = db.CleanSteps("integration testing", 1563474090) + if err != nil { + t.Errorf("unable to clean steps: %v", err) + } + if int(count) != len(resources.Steps) { + t.Errorf("CleanSteps() is %v, want %v", count, len(resources.Steps)) + } + methods["CleanSteps"] = true // update the steps for _, step := range resources.Steps { @@ -1433,8 +1560,8 @@ func testSteps(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetStep() is %v, want %v", got, step) } } - counter++ - counter++ + methods["UpdateStep"] = true + methods["GetStep"] = true // delete the steps for _, step := range resources.Steps { @@ -1443,21 +1570,33 @@ func testSteps(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to delete step %d: %v", step.GetID(), err) } } - counter++ + methods["DeleteStep"] = true - // ensure we called all the functions we should have - methods := reflect.TypeOf(new(step.StepInterface)).Elem().NumMethod() - if counter != methods { - t.Errorf("total number of methods called is %v, want %v", counter, methods) + // ensure we called all the methods we expected to + for method, called := range methods { + if !called { + t.Errorf("method %s was not called for steps", method) + } } } func testUsers(t *testing.T, db Interface, resources *Resources) { - // used to track the number of methods we call for users - // - // we start at 2 for creating the table and indexes for users - // since those are already called when the database engine starts - counter := 2 + // create a variable to track the number of methods called for users + methods := make(map[string]bool) + // capture the element type of the user interface + element := reflect.TypeOf(new(user.UserInterface)).Elem() + // iterate through all methods found in the user interface + for i := 0; i < element.NumMethod(); i++ { + // skip tracking the methods to create indexes and tables for users + // 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 + } userOne := new(library.User) userOne.SetID(1) @@ -1488,7 +1627,7 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to create user %d: %v", user.GetID(), err) } } - counter++ + methods["CreateUser"] = true // count the users count, err := db.CountUsers() @@ -1498,7 +1637,7 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Users) { t.Errorf("CountUsers() is %v, want %v", count, len(resources.Users)) } - counter++ + methods["CountUsers"] = true // list the users list, err := db.ListUsers() @@ -1508,7 +1647,7 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Users) { t.Errorf("ListUsers() is %v, want %v", list, resources.Users) } - counter++ + methods["ListUsers"] = true // lite list the users list, count, err = db.ListLiteUsers(1, 10) @@ -1521,7 +1660,7 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { if int(count) != len(liteUsers) { t.Errorf("ListLiteUsers() is %v, want %v", count, len(liteUsers)) } - counter++ + methods["ListLiteUsers"] = true // lookup the users by name for _, user := range resources.Users { @@ -1533,7 +1672,7 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetUserForName() is %v, want %v", got, user) } } - counter++ + methods["GetUserForName"] = true // update the users for _, user := range resources.Users { @@ -1552,8 +1691,8 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetUser() is %v, want %v", got, user) } } - counter++ - counter++ + methods["UpdateUser"] = true + methods["GetUser"] = true // delete the users for _, user := range resources.Users { @@ -1562,21 +1701,33 @@ func testUsers(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to delete user %d: %v", user.GetID(), err) } } - counter++ + methods["DeleteUser"] = true - // ensure we called all the functions we should have - methods := reflect.TypeOf(new(user.UserInterface)).Elem().NumMethod() - if counter != methods { - t.Errorf("total number of methods called is %v, want %v", counter, methods) + // ensure we called all the methods we expected to + for method, called := range methods { + if !called { + t.Errorf("method %s was not called for users", method) + } } } func testWorkers(t *testing.T, db Interface, resources *Resources) { - // used to track the number of methods we call for workers - // - // we start at 2 for creating the table and indexes for users - // since those are already called when the database engine starts - counter := 2 + // create a variable to track the number of methods called for workers + methods := make(map[string]bool) + // capture the element type of the worker interface + element := reflect.TypeOf(new(worker.WorkerInterface)).Elem() + // iterate through all methods found in the worker interface + for i := 0; i < element.NumMethod(); i++ { + // skip tracking the methods to create indexes and tables for workers + // 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 workers for _, worker := range resources.Workers { @@ -1585,7 +1736,7 @@ func testWorkers(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to create worker %d: %v", worker.GetID(), err) } } - counter++ + methods["CreateWorker"] = true // count the workers count, err := db.CountWorkers() @@ -1595,7 +1746,7 @@ func testWorkers(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Workers) { t.Errorf("CountWorkers() is %v, want %v", count, len(resources.Workers)) } - counter++ + methods["CountWorkers"] = true // list the workers list, err := db.ListWorkers() @@ -1605,7 +1756,7 @@ func testWorkers(t *testing.T, db Interface, resources *Resources) { if !reflect.DeepEqual(list, resources.Workers) { t.Errorf("ListWorkers() is %v, want %v", list, resources.Workers) } - counter++ + methods["ListWorkers"] = true // lookup the workers by hostname for _, worker := range resources.Workers { @@ -1617,7 +1768,7 @@ func testWorkers(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetWorkerForHostname() is %v, want %v", got, worker) } } - counter++ + methods["GetWorkerForHostname"] = true // update the workers for _, worker := range resources.Workers { @@ -1636,8 +1787,8 @@ func testWorkers(t *testing.T, db Interface, resources *Resources) { t.Errorf("GetWorker() is %v, want %v", got, worker) } } - counter++ - counter++ + methods["UpdateWorker"] = true + methods["GetWorker"] = true // delete the workers for _, worker := range resources.Workers { @@ -1646,12 +1797,13 @@ func testWorkers(t *testing.T, db Interface, resources *Resources) { t.Errorf("unable to delete worker %d: %v", worker.GetID(), err) } } - counter++ + methods["DeleteWorker"] = true - // ensure we called all the functions we should have - methods := reflect.TypeOf(new(worker.WorkerInterface)).Elem().NumMethod() - if counter != methods { - t.Errorf("total number of methods called is %v, want %v", counter, methods) + // ensure we called all the methods we expected to + for method, called := range methods { + if !called { + t.Errorf("method %s was not called for workers", method) + } } } diff --git a/database/vela.db b/database/vela.db new file mode 100644 index 0000000000000000000000000000000000000000..69a41f0a3f7904d508495b129fbb566f43fdbd05 GIT binary patch literal 172032 zcmeI5TWlNIdBO#pjebaIk#Vf9Iv1nPANa{juU~DLfwrT5ru_P}XW=IanF)u^S z3?8|*qzI4(*kXajHX9%h z={YlJZWN`p>`m5}KLwF9-?_}0-}ilI&TVE^mS!bQ4CZ8|ENHPj-ssv>Kn9O_=FAeNr~)_$2376PFXq!Nuj| zTzq*mcrCFRjIXUOB8fRLZ7GQd!bSh+Te7 zDvNTB%IL?IXXIK%6BR@3kZ((>l$MB+>okaEUR9)Rfq1O(nOazwO~mI32TiG|nrO1N z}UUm@rL!E(=VN93k>)1JG$MQ z2USxvkl217UwZ zF2N3LD4l-W)^nCJmb9~07{iw<3EQ%1R5Z{uppu}`>b^0)BIYcSzQN+_dUA#^`L?L2 zl3cMvm|WZ?wp+iB#JC&*PU9mMU$v8vqS*GQ ziRCIeQ#+v@lod3=E;dayyD&vuh#4GXeLiTCC59J1eo)10={FU&HcwnV))qM1&F6Ik zEXjE_mDcM8DNA?!F1vFDQ=6lL;DDJRba$t#J<#3F-!tl58cP3&bAXH=wU{n!&Fm7v5cJ#mle1oP%AJ5!2u&lXtu3MZaQ-#Vtdov^a!rpbV+ET zm9*G;_@Z8MutPI5F!tJ-WyfMT^JAjWf_HC*O#McNt<5rIF`OAPQE0KHEigF9Z|XMB znxU$=RTC?u1~*!z=B}4zZ8QoS0taY2?L3JZdM(bk2YPz=FW=PjG>T<>dt5mfvL@G2 zW*-MOEM3mzyoQ>!Hggf%)?5zdN+Bo?r*K@3UC!cmA=6zfsml>8spxbWTUsG}Yo^0G z4(M`ZXAw#6isj+XfSgp3RMJ&o9&Mkk*}8MPx*<(fg?dRAvZk}U+sLNWsA5W<=i)Iy!RR&j; zWl0;FLM(^0po*kjXtt7=v>*!ECQ@fLYUfMZ`J@lfaK>3l)f6dR)2mV|E{#YuSgsne zZ6)nn{SA8B0x$OLcd0ZSClxk+Ta1qMvnP+zjpH15?E10mPkHAWrw;-k00JNY0w4ea zAOHe7fqT#L&vQQV>E;4aFZpmM){C{ln|*y_V)r1|8|?{j)f(wh(T*D(AGP#LxI64*{k1mixUXwJfzIWrZ_9>Z17k5c7rX29VVRLHn*lhj!`Qxuibz0;OjdO2M!gH6?<)-q&RLUn3^Y=84k ze@>SBU+AYw3im@LhT=>Ed@z+rmD(7LoS!`(8(v#btdB) zs`gPT$u7lV{bxnY$d&A&9cXl~-&m3dbD+qBI1trVC#~T~|KIg+<9UyVoJ*^Z&i{A$cRBz6`G4#GrT;(tKlcBV|NH*G z_5Zd1RU*a*1V8`;KmY_l00ck)1V8`;KmY_l;2{Wfb+z>JJF-F+vZx+kXG?&mcRiC$ zAKBDzYxErHXgR~1_eFZT+DQU-OJ&Q^ww6BLy2smdw3Y0d_pqp*4sT00Pw#c}`dUbC z`W;W6PESh@&+e%4@kC5-hEYA%{Qo=tcOK$&kQ4+!00ck)1V8`;KmY_l00ck)1VG@? zA<)s{<>{?Rbn?H0Zdm>Q_xkguKmY_l00ck)1V8`;KmY_l00ck)1U>`;-WDHE z#{j%m|Nra$uYU;nA`1`z0T2KI5C8!X009sH0T2KI5CDP05Qw%EdGiUH_A@mb9uw+* z0x0d!M-Q3C>i@s%fA=uOLtGF50T2KI5C8!X009sH0T2KI5CDNkhd^gbuaCW3ffTBp zyrP6Ycz{VfmAv)-zjuz|{{KfuZ72x{fB*=900@8p2!H?xfB*=9z{3%^+vf4p7Za{| zpYP_nx!$c7PbQWX!qJh)(8xq~d?*|ig`rq1k{cS0O-9ohAu=(Rj?uSv+LQ3~O`G(6 zd#o4z!87ivsL}U;lDAvRa*@2MlmG9}lGFGieW$2hkdLMu*8D%-|Mzf~h14Jb0w4ea zAOHd&00JNY0w4eaAn=G0aK8V~>i^^Ue~*}!P#h2d0T2KI5C8!X009sH0T2KI5O`<; z*7N_&_5c2F7=I6)Gco`H5C8!X009sH0T2KI5C8!X009sDj!g>osf`?+)1hR*%$r$7J438ea4Pj z{eQgwZx40|KmY_l00ck)1V8`;KmY_l00cnbF(?KQ^}Q_7EyD{qoWCNVqBStUfIoV#%CrK zd24iDRwAYFbzx*!7}rX*>w~epmJ=(h^H&zGuhzxH)bdDiO&nYqnH^2KXk-Mh(xBa^vKk4{Z`;Atqb=>=w=ce~f{#RU{fAawf{K`ys zd!Vn6|H8T^q)VcjDTvt``L#BlnO;uBR};b2_|$A7Xo-UZojxfWv_HxD)x_n*a&U1u zITv5v3|>oY2IFh13(0ws!CYc~^?avK5vy{_OvMrqv5?WEZINX)wXiUoh|d#oMJSuX zU~o0DL30o*no>6p%48Wu6f`lL5;PKE=W2@6G(L-3t7e-;HO0=T=9%jG+PSXHCzsX| z1ME!B2WcTgouQ6zwf;WQ$8%C8EAFaWB}o%gLQRwP{gj!PnhIN+frZm;flz=i>rrTa zYD!k}DVm|a*Ui8u=VuZdL3f1Cg?U2~93W{}DZWrY*&YZ4_%AK#s?<~HU#DCuq@qJa zRrhGxWPG5iYpSSNsy0&)1r`LgVCv6O3poc{X6nkNep8sMl}b7yJwDTFNvag>^rlsm zM*;Gj?OKz*uq_Qa2sEmGWyU573iY6+C*dgDR zR4FYHd(f?xWnNXJZDNNkvTgC2Qd5Z~?~%J4BxuJMN+o$GRV7SllD%>Rb)!5hR!cG| zPNQ5C3@tRu$)jG%#P1yOt5Q`Y(8ZKiuZpH>s*1QR$u-qb4?9!lE|%JetGslgEil~2 z@91`K=A@>mSrUV>1SehQZ;8!#)B`MG(DcVp_;_1je?PPmq{7zbiF*~lUIV^9sJo37 zU~L?CxsN5@>lZ`^%peYQ4R)qX%XT8-9cL+PNjqzWF^svAuq~U$MFUMkDhXOnR?3a> z$y;qLk-ov=>-utrF!{EqsFGZhqUBPK zR4OqtM}X4^iRD-AB%~;|9cp5^O3u_yXa|w{T(FBxQ_U_+5t5Ddv`Lm2;MHSofwSFY z2_CJhOLAUK8O|5kuJcdlS+b5sxHiUz$rx!Gu9x>^ zD&}#FGqh_Pw+Y#DMxIr?4mn}ltTuMjbEBjBAZbE2Ognc%@$AvIz-PMmyW-JPPDSYV zv9m`$Fk+ZSJbJB@=q14PQjq1MRVnB@T`tAA!l`0(fn5>Y>+H}khOZKfBkdYJRR8k1 zRKrp==;qK~Y?F3r%obN_<#dy)gGwfnG9uFq^EuXTX;gVZR?Vx9<^JL}t(V!ybXh7( z(JKb=XC`x9_RM&SV%I24Mp$Vz(+8Q%b#Y~~9WhP88RfQ5veD;^lP0zj^0fsn2KKWR zT?eVK{?j?zPK=<38G#N{O&P^9b~;>E;EF)4zz_rnj3lAiwkEmh%#DccO>@&DxN_4a zp@mk`V(a0Hdd0yG%{pV#rdM(bk2YPz=FW=PjG>T<>dt5mfvL+YB zLpzgo6(u!~d9`IOV%wU_p zZFUh|j_fQV$z8FVd5$9Hq>7}H4jA)jJ1euv=5}>MnyL!*k}PCRXD1KVb2NNSsZrCI zb%iO_B&}pNLrEBO?=tEBk;}9hnMutnsJjfRNUoxG%Y?-xU7vyj6_bkO$$xrF)yRTL zT@{Q~23M73NgLWVEQhq9ilkj=HhGw|APU(gQfD=4=Sv#zq+#E1##u?#6e(TPt5Pd2 zjYu?Dt{SmzCGA`N4SL!FFZS$L{TYsv3LC#Iqz_LX`p9wC{6F6R_W;8hNCE;N00JNY z0w4eaAOHd&00JNY0*^ES`~80%om@Bf1FrK0-)}qqzC-Rf+4^?-f3^Rh^_A9Vz5nX@ znfI@_|MdLBv3Iy19DC!)UmPnR(H|H<5_|-o&?gQW-=$N*WaeA{`SiVHP#>3nZOa&= zq?11S%+DuWqlw03P~#c{bExbP(`)wdj6S}?#u1&Paqf{sJATvoXQ}KM7&FJq$Y_u~ zTILYiW9g>QJ%VTsi|tBUDkEo&;U~KQ?(sug?jAn0+;%IlE{I^;wxlp|P%ou7waPS;sm6RwEiKz08XNnc6Ys>AKG< zthuI3UlrzvYs&StUS=s+9cNkDd3|*iTUTXIfIGseg;=YZb2=YnS%vNu zKc!!iULVpMY%C`G8E{>atXvva(b$&?))qam*=`oWPNi=#mtw_g2sEp2g{;W57l&Dq z%(Tws#a5u>vO*fvj`o`s<9d8~`bvCxU~Gi0fhq~A##W-F45!yGLv}Npw5TgmC2uVz zV;40$7dsoHEzR2T4cX|&F(Q}^dK$w%jvj$j;F%&>^DI@!6;J=z5sbv<(pBqp>)Vj^va{BNRjsq zij~kS$NKet;k`S$z3FlEuTQybjiudVY3$?1x)!8c+g)CX}ZD(xa(lkqa)WBE79s$cxq~O zdOnsf%9rKwrMa0ak;3Bj;ib9FVt6Ee@#39+p;RUJgZ96Cr@vZL3;pN&$&@JhHttZM zcaQeJY(C+x@nLsl3^KrV_w;gBf#}#|V{yjA@>(^vuC7H!uM6uphHsZP>+>s->)OUz zGMvv%mLg+mB{zHd+Rj54hx;OTs>g2^hfI(dr8!5i2!(QaB3I8}U8_wchp#TqE^XY3 zUsC6;-d2W7NiD8iy&ap#SK@O^4_OXt{r^Av$=_pbawt3qfB*=900@8p2!H?xfB*=9 z00=yJ1fFRlqbsL)=co!9H=y_RkMy46n~iPI=l-4cpYpi|8m#{Rzxc`DlZOds1Ogxc z0w4eaAOHd&00JNY0w4eak2ircWB`El^qm6$?CpST9AJP957^@XL`Vk!PH~O_03x&c z|3CJVzsH*hN)G}c00JNY0w4eaAOHd&00JNY0#7u7ldWVefNLaxt^*k8b#(vP&;T6* zIPP~W0kHc2|K=xuPc$W*90-5_2!H?xfB*=900@8p2!H?xJmv&?$N)gEYXE@t_vtu5 zkaLU!&;bBHXAb~a{r_M1$=_p+0mTOa5C8!X009sH0T2KI5C8!X0D-53zzJ_pk82=+ zjsQH@FaU7O?*E(5|M!2}|Lvy)5l#~XKmY_l00ck)1V8`;KmY_l;3*>T5`UcY`F!1h zK$P=(z0sb4RFSk#&@cV%=~6`#^NOHJa)rF6S=GoZ7jKUI@D1|+4f=)waaSl;OX3Cc z^5Cj))y%7xYs^cnWisTInPyV*`%PEUN}XnrmC0Kcm6BAc?GhE7@cH<_q*<<;9$HW$ zurl{#N^(Wi1SKzO!`os>7$WZtcwu|wLiECjeZ23IV||bOfB)d)S@Zwz`QLkr)Q?jI z0T2KI5C8!X009sH0T2KI5CDNEop|Hc!4;y6JN009sH0T2KI z5C8!X009sHfhV89=lK)Hgnzd=vu@A$KhUiIf|a2)GjA;+pd0p7yuNDS5L5qV3DX{0 zWHR;NZ5`pDxqtUTG5`PM+ceG)1V8`;KmY_l00ck)1V8`;KmY^|Akb|7|L8A|{_=n% z2m%2R009sH0T2KI5C8!X009tqqzSy@_Z;E+?sng8y?Zm<(Lo;yUz9YhK39p0vy<`L z%H^4j4MCJ9O4sU%%VWjbNPc>~K7J#YoZi@tE)+-WYGE;d?Y6WrTieL0%HV1?TN<96 z$qOS>%eUsQ3#+rE(=$tjTWiWleRE-JW2;zDuB0bsmE}r)F1cG6+1QCrk1H$T!QHeJ znUro#2swG~VmhmYH{|G*iRGR3-PMsyZnwHPF(}?zsmrm#)!a^Qe(RdDeMugfjmC3o zdR|JeC95Mhh6fie?{2PL(xMw9;mhiDd}~%I?}|I|&8h6|_2HGp!DO|#TA$lp&EB3+ zmo8qs(@$=VFVxb*>~Z-0FLNBZS-;msBqL~}x!BgF@XYOEZ6`Z_YdkkH6Pr;M(+knH zdT}r|I&*pH_EssjRxW2Eh0Vn1bR=?ZF&SIAK02z*#di`(A$EJGHkqHzU$0)t#?;Y? z8_~pK`L?{Y5Sfhc%*Uji%B9Hk>f*}g_}ET*W&X-UX{H=jXCvF%t@ZWd#pPsGQg-Uu z`Kfre9Jwr4%hT#cF*Yh}YZGF2y*#~eD_OZ!9McACTjfielNrh8HED@ z5C8!X009sH0T2KI5C8!X009vAAOc5Q`gm*fhu-<$#YRM|{(sqD{-8_{4gw$m0w4ea zAOHd&00JNY0w4eaAaEZ9lHR-B{D-mjg7)B(z7J#7g7y5r3;qlDaR!J20w4eaAOHd& z00JNY0w4eaAOHeS0fD^dC^wck)6wVcBQFi~?Z^swZ{JYlg5w=~1x>4}FANVi3%k=# zU)R_Fval^kB_UlB>8k|q^oJwS(XsxQ>5lnNSW0^j6h7cUuCV(*kTw7RbN|nu0tMm} zK>!3m00ck)1V8`;KmY_l00cnbNg(iS%NXBmh($ literal 0 HcmV?d00001 From 6b67568a5e146c701a9bc8077d2525a764223ef2 Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Fri, 28 Jul 2023 13:47:11 -0500 Subject: [PATCH 63/64] chore: remove unneeded file --- database/vela.db | Bin 172032 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 database/vela.db diff --git a/database/vela.db b/database/vela.db deleted file mode 100644 index 69a41f0a3f7904d508495b129fbb566f43fdbd05..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 172032 zcmeI5TWlNIdBO#pjebaIk#Vf9Iv1nPANa{juU~DLfwrT5ru_P}XW=IanF)u^S z3?8|*qzI4(*kXajHX9%h z={YlJZWN`p>`m5}KLwF9-?_}0-}ilI&TVE^mS!bQ4CZ8|ENHPj-ssv>Kn9O_=FAeNr~)_$2376PFXq!Nuj| zTzq*mcrCFRjIXUOB8fRLZ7GQd!bSh+Te7 zDvNTB%IL?IXXIK%6BR@3kZ((>l$MB+>okaEUR9)Rfq1O(nOazwO~mI32TiG|nrO1N z}UUm@rL!E(=VN93k>)1JG$MQ z2USxvkl217UwZ zF2N3LD4l-W)^nCJmb9~07{iw<3EQ%1R5Z{uppu}`>b^0)BIYcSzQN+_dUA#^`L?L2 zl3cMvm|WZ?wp+iB#JC&*PU9mMU$v8vqS*GQ ziRCIeQ#+v@lod3=E;dayyD&vuh#4GXeLiTCC59J1eo)10={FU&HcwnV))qM1&F6Ik zEXjE_mDcM8DNA?!F1vFDQ=6lL;DDJRba$t#J<#3F-!tl58cP3&bAXH=wU{n!&Fm7v5cJ#mle1oP%AJ5!2u&lXtu3MZaQ-#Vtdov^a!rpbV+ET zm9*G;_@Z8MutPI5F!tJ-WyfMT^JAjWf_HC*O#McNt<5rIF`OAPQE0KHEigF9Z|XMB znxU$=RTC?u1~*!z=B}4zZ8QoS0taY2?L3JZdM(bk2YPz=FW=PjG>T<>dt5mfvL@G2 zW*-MOEM3mzyoQ>!Hggf%)?5zdN+Bo?r*K@3UC!cmA=6zfsml>8spxbWTUsG}Yo^0G z4(M`ZXAw#6isj+XfSgp3RMJ&o9&Mkk*}8MPx*<(fg?dRAvZk}U+sLNWsA5W<=i)Iy!RR&j; zWl0;FLM(^0po*kjXtt7=v>*!ECQ@fLYUfMZ`J@lfaK>3l)f6dR)2mV|E{#YuSgsne zZ6)nn{SA8B0x$OLcd0ZSClxk+Ta1qMvnP+zjpH15?E10mPkHAWrw;-k00JNY0w4ea zAOHe7fqT#L&vQQV>E;4aFZpmM){C{ln|*y_V)r1|8|?{j)f(wh(T*D(AGP#LxI64*{k1mixUXwJfzIWrZ_9>Z17k5c7rX29VVRLHn*lhj!`Qxuibz0;OjdO2M!gH6?<)-q&RLUn3^Y=84k ze@>SBU+AYw3im@LhT=>Ed@z+rmD(7LoS!`(8(v#btdB) zs`gPT$u7lV{bxnY$d&A&9cXl~-&m3dbD+qBI1trVC#~T~|KIg+<9UyVoJ*^Z&i{A$cRBz6`G4#GrT;(tKlcBV|NH*G z_5Zd1RU*a*1V8`;KmY_l00ck)1V8`;KmY_l;2{Wfb+z>JJF-F+vZx+kXG?&mcRiC$ zAKBDzYxErHXgR~1_eFZT+DQU-OJ&Q^ww6BLy2smdw3Y0d_pqp*4sT00Pw#c}`dUbC z`W;W6PESh@&+e%4@kC5-hEYA%{Qo=tcOK$&kQ4+!00ck)1V8`;KmY_l00ck)1VG@? zA<)s{<>{?Rbn?H0Zdm>Q_xkguKmY_l00ck)1V8`;KmY_l00ck)1U>`;-WDHE z#{j%m|Nra$uYU;nA`1`z0T2KI5C8!X009sH0T2KI5CDP05Qw%EdGiUH_A@mb9uw+* z0x0d!M-Q3C>i@s%fA=uOLtGF50T2KI5C8!X009sH0T2KI5CDNkhd^gbuaCW3ffTBp zyrP6Ycz{VfmAv)-zjuz|{{KfuZ72x{fB*=900@8p2!H?xfB*=9z{3%^+vf4p7Za{| zpYP_nx!$c7PbQWX!qJh)(8xq~d?*|ig`rq1k{cS0O-9ohAu=(Rj?uSv+LQ3~O`G(6 zd#o4z!87ivsL}U;lDAvRa*@2MlmG9}lGFGieW$2hkdLMu*8D%-|Mzf~h14Jb0w4ea zAOHd&00JNY0w4eaAn=G0aK8V~>i^^Ue~*}!P#h2d0T2KI5C8!X009sH0T2KI5O`<; z*7N_&_5c2F7=I6)Gco`H5C8!X009sH0T2KI5C8!X009sDj!g>osf`?+)1hR*%$r$7J438ea4Pj z{eQgwZx40|KmY_l00ck)1V8`;KmY_l00cnbF(?KQ^}Q_7EyD{qoWCNVqBStUfIoV#%CrK zd24iDRwAYFbzx*!7}rX*>w~epmJ=(h^H&zGuhzxH)bdDiO&nYqnH^2KXk-Mh(xBa^vKk4{Z`;Atqb=>=w=ce~f{#RU{fAawf{K`ys zd!Vn6|H8T^q)VcjDTvt``L#BlnO;uBR};b2_|$A7Xo-UZojxfWv_HxD)x_n*a&U1u zITv5v3|>oY2IFh13(0ws!CYc~^?avK5vy{_OvMrqv5?WEZINX)wXiUoh|d#oMJSuX zU~o0DL30o*no>6p%48Wu6f`lL5;PKE=W2@6G(L-3t7e-;HO0=T=9%jG+PSXHCzsX| z1ME!B2WcTgouQ6zwf;WQ$8%C8EAFaWB}o%gLQRwP{gj!PnhIN+frZm;flz=i>rrTa zYD!k}DVm|a*Ui8u=VuZdL3f1Cg?U2~93W{}DZWrY*&YZ4_%AK#s?<~HU#DCuq@qJa zRrhGxWPG5iYpSSNsy0&)1r`LgVCv6O3poc{X6nkNep8sMl}b7yJwDTFNvag>^rlsm zM*;Gj?OKz*uq_Qa2sEmGWyU573iY6+C*dgDR zR4FYHd(f?xWnNXJZDNNkvTgC2Qd5Z~?~%J4BxuJMN+o$GRV7SllD%>Rb)!5hR!cG| zPNQ5C3@tRu$)jG%#P1yOt5Q`Y(8ZKiuZpH>s*1QR$u-qb4?9!lE|%JetGslgEil~2 z@91`K=A@>mSrUV>1SehQZ;8!#)B`MG(DcVp_;_1je?PPmq{7zbiF*~lUIV^9sJo37 zU~L?CxsN5@>lZ`^%peYQ4R)qX%XT8-9cL+PNjqzWF^svAuq~U$MFUMkDhXOnR?3a> z$y;qLk-ov=>-utrF!{EqsFGZhqUBPK zR4OqtM}X4^iRD-AB%~;|9cp5^O3u_yXa|w{T(FBxQ_U_+5t5Ddv`Lm2;MHSofwSFY z2_CJhOLAUK8O|5kuJcdlS+b5sxHiUz$rx!Gu9x>^ zD&}#FGqh_Pw+Y#DMxIr?4mn}ltTuMjbEBjBAZbE2Ognc%@$AvIz-PMmyW-JPPDSYV zv9m`$Fk+ZSJbJB@=q14PQjq1MRVnB@T`tAA!l`0(fn5>Y>+H}khOZKfBkdYJRR8k1 zRKrp==;qK~Y?F3r%obN_<#dy)gGwfnG9uFq^EuXTX;gVZR?Vx9<^JL}t(V!ybXh7( z(JKb=XC`x9_RM&SV%I24Mp$Vz(+8Q%b#Y~~9WhP88RfQ5veD;^lP0zj^0fsn2KKWR zT?eVK{?j?zPK=<38G#N{O&P^9b~;>E;EF)4zz_rnj3lAiwkEmh%#DccO>@&DxN_4a zp@mk`V(a0Hdd0yG%{pV#rdM(bk2YPz=FW=PjG>T<>dt5mfvL+YB zLpzgo6(u!~d9`IOV%wU_p zZFUh|j_fQV$z8FVd5$9Hq>7}H4jA)jJ1euv=5}>MnyL!*k}PCRXD1KVb2NNSsZrCI zb%iO_B&}pNLrEBO?=tEBk;}9hnMutnsJjfRNUoxG%Y?-xU7vyj6_bkO$$xrF)yRTL zT@{Q~23M73NgLWVEQhq9ilkj=HhGw|APU(gQfD=4=Sv#zq+#E1##u?#6e(TPt5Pd2 zjYu?Dt{SmzCGA`N4SL!FFZS$L{TYsv3LC#Iqz_LX`p9wC{6F6R_W;8hNCE;N00JNY z0w4eaAOHd&00JNY0*^ES`~80%om@Bf1FrK0-)}qqzC-Rf+4^?-f3^Rh^_A9Vz5nX@ znfI@_|MdLBv3Iy19DC!)UmPnR(H|H<5_|-o&?gQW-=$N*WaeA{`SiVHP#>3nZOa&= zq?11S%+DuWqlw03P~#c{bExbP(`)wdj6S}?#u1&Paqf{sJATvoXQ}KM7&FJq$Y_u~ zTILYiW9g>QJ%VTsi|tBUDkEo&;U~KQ?(sug?jAn0+;%IlE{I^;wxlp|P%ou7waPS;sm6RwEiKz08XNnc6Ys>AKG< zthuI3UlrzvYs&StUS=s+9cNkDd3|*iTUTXIfIGseg;=YZb2=YnS%vNu zKc!!iULVpMY%C`G8E{>atXvva(b$&?))qam*=`oWPNi=#mtw_g2sEp2g{;W57l&Dq z%(Tws#a5u>vO*fvj`o`s<9d8~`bvCxU~Gi0fhq~A##W-F45!yGLv}Npw5TgmC2uVz zV;40$7dsoHEzR2T4cX|&F(Q}^dK$w%jvj$j;F%&>^DI@!6;J=z5sbv<(pBqp>)Vj^va{BNRjsq zij~kS$NKet;k`S$z3FlEuTQybjiudVY3$?1x)!8c+g)CX}ZD(xa(lkqa)WBE79s$cxq~O zdOnsf%9rKwrMa0ak;3Bj;ib9FVt6Ee@#39+p;RUJgZ96Cr@vZL3;pN&$&@JhHttZM zcaQeJY(C+x@nLsl3^KrV_w;gBf#}#|V{yjA@>(^vuC7H!uM6uphHsZP>+>s->)OUz zGMvv%mLg+mB{zHd+Rj54hx;OTs>g2^hfI(dr8!5i2!(QaB3I8}U8_wchp#TqE^XY3 zUsC6;-d2W7NiD8iy&ap#SK@O^4_OXt{r^Av$=_pbawt3qfB*=900@8p2!H?xfB*=9 z00=yJ1fFRlqbsL)=co!9H=y_RkMy46n~iPI=l-4cpYpi|8m#{Rzxc`DlZOds1Ogxc z0w4eaAOHd&00JNY0w4eak2ircWB`El^qm6$?CpST9AJP957^@XL`Vk!PH~O_03x&c z|3CJVzsH*hN)G}c00JNY0w4eaAOHd&00JNY0#7u7ldWVefNLaxt^*k8b#(vP&;T6* zIPP~W0kHc2|K=xuPc$W*90-5_2!H?xfB*=900@8p2!H?xJmv&?$N)gEYXE@t_vtu5 zkaLU!&;bBHXAb~a{r_M1$=_p+0mTOa5C8!X009sH0T2KI5C8!X0D-53zzJ_pk82=+ zjsQH@FaU7O?*E(5|M!2}|Lvy)5l#~XKmY_l00ck)1V8`;KmY_l;3*>T5`UcY`F!1h zK$P=(z0sb4RFSk#&@cV%=~6`#^NOHJa)rF6S=GoZ7jKUI@D1|+4f=)waaSl;OX3Cc z^5Cj))y%7xYs^cnWisTInPyV*`%PEUN}XnrmC0Kcm6BAc?GhE7@cH<_q*<<;9$HW$ zurl{#N^(Wi1SKzO!`os>7$WZtcwu|wLiECjeZ23IV||bOfB)d)S@Zwz`QLkr)Q?jI z0T2KI5C8!X009sH0T2KI5CDNEop|Hc!4;y6JN009sH0T2KI z5C8!X009sHfhV89=lK)Hgnzd=vu@A$KhUiIf|a2)GjA;+pd0p7yuNDS5L5qV3DX{0 zWHR;NZ5`pDxqtUTG5`PM+ceG)1V8`;KmY_l00ck)1V8`;KmY^|Akb|7|L8A|{_=n% z2m%2R009sH0T2KI5C8!X009tqqzSy@_Z;E+?sng8y?Zm<(Lo;yUz9YhK39p0vy<`L z%H^4j4MCJ9O4sU%%VWjbNPc>~K7J#YoZi@tE)+-WYGE;d?Y6WrTieL0%HV1?TN<96 z$qOS>%eUsQ3#+rE(=$tjTWiWleRE-JW2;zDuB0bsmE}r)F1cG6+1QCrk1H$T!QHeJ znUro#2swG~VmhmYH{|G*iRGR3-PMsyZnwHPF(}?zsmrm#)!a^Qe(RdDeMugfjmC3o zdR|JeC95Mhh6fie?{2PL(xMw9;mhiDd}~%I?}|I|&8h6|_2HGp!DO|#TA$lp&EB3+ zmo8qs(@$=VFVxb*>~Z-0FLNBZS-;msBqL~}x!BgF@XYOEZ6`Z_YdkkH6Pr;M(+knH zdT}r|I&*pH_EssjRxW2Eh0Vn1bR=?ZF&SIAK02z*#di`(A$EJGHkqHzU$0)t#?;Y? z8_~pK`L?{Y5Sfhc%*Uji%B9Hk>f*}g_}ET*W&X-UX{H=jXCvF%t@ZWd#pPsGQg-Uu z`Kfre9Jwr4%hT#cF*Yh}YZGF2y*#~eD_OZ!9McACTjfielNrh8HED@ z5C8!X009sH0T2KI5C8!X009vAAOc5Q`gm*fhu-<$#YRM|{(sqD{-8_{4gw$m0w4ea zAOHd&00JNY0w4eaAaEZ9lHR-B{D-mjg7)B(z7J#7g7y5r3;qlDaR!J20w4eaAOHd& z00JNY0w4eaAOHeS0fD^dC^wck)6wVcBQFi~?Z^swZ{JYlg5w=~1x>4}FANVi3%k=# zU)R_Fval^kB_UlB>8k|q^oJwS(XsxQ>5lnNSW0^j6h7cUuCV(*kTw7RbN|nu0tMm} zK>!3m00ck)1V8`;KmY_l00cnbNg(iS%NXBmh($ From 061ff80ca0b8a42d5b812e8d585a0bf5b8b86d6d Mon Sep 17 00:00:00 2001 From: JordanBrockopp Date: Fri, 28 Jul 2023 13:49:37 -0500 Subject: [PATCH 64/64] chore: undo comments --- database/integration_test.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/database/integration_test.go b/database/integration_test.go index 420e38862..2cebb815a 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -56,19 +56,19 @@ func TestDatabase_Integration(t *testing.T) { name string config *config }{ - //{ - // name: "postgres", - // config: &config{ - // Driver: "postgres", - // Address: os.Getenv("POSTGRES_ADDR"), - // CompressionLevel: 3, - // ConnectionLife: 10 * time.Second, - // ConnectionIdle: 5, - // ConnectionOpen: 20, - // EncryptionKey: "A1B2C3D4E5G6H7I8J9K0LMNOPQRSTUVW", - // SkipCreation: false, - // }, - //}, + { + name: "postgres", + config: &config{ + Driver: "postgres", + Address: os.Getenv("POSTGRES_ADDR"), + CompressionLevel: 3, + ConnectionLife: 10 * time.Second, + ConnectionIdle: 5, + ConnectionOpen: 20, + EncryptionKey: "A1B2C3D4E5G6H7I8J9K0LMNOPQRSTUVW", + SkipCreation: false, + }, + }, { name: "sqlite3", config: &config{