Skip to content

Commit

Permalink
Add coverage statistics in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
georgepsarakis committed Dec 17, 2023
1 parent 6f35869 commit c274f09
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ jobs:
go-version: '1.21.x'
- name: Install dependencies
run: go get .
- name: Set up gotestfmt
run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
- name: Build
run: go build -v ./...
- name: Unit Tests
run: go test -v ./...
run: go test -v -json -race -coverprofile=cover.out ./... | gotestfmt
- name: CLI Integration Tests
run: go test -v main_test.go
run: go test -v -json -race main_test.go | gotestfmt
3 changes: 1 addition & 2 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package loader

import (
"bytes"
"errors"
"fmt"
pg_query "github.com/pganalyze/pg_query_go/v4"
migrate "github.com/rubenv/sql-migrate"
Expand Down Expand Up @@ -76,7 +75,7 @@ func ReadStatementsFromFiles(paths ...string) ([]MigrationFile, error) {
return nil, err
}
if fileInfo.IsDir() {
return nil, errors.New(fmt.Sprintf("expected file and %s is a directory", p))
return nil, fmt.Errorf("expected file and %s is a directory", p)
}
sql, err := os.ReadFile(p)
if err != nil {
Expand Down
20 changes: 6 additions & 14 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,7 @@ func TestExecutable_ListRulesCommand(t *testing.T) {
}

const expectedFailureOutput = `
Rule high-availability-avoid-table-rename violation found for statement:
ALTER TABLE "movies" RENAME TO "movies_old";
Explanation: Renaming a table can cause errors in previous application versions.
Rule high-availability-avoid-required-column violation found for statement:
ALTER TABLE "recipe" ADD COLUMN "public" boolean NOT NULL, ADD COLUMN "private" boolean;
Explanation: Newly added columns must either define a default value or be nullable.
Rule high-availability-alter-column-not-null-exclusive-lock violation found for statement:
ALTER TABLE movies ALTER COLUMN "public" SET NOT NULL;
Explanation: Setting a column as NOT NULL acquires an exclusive lock on the table until the constraint is validated on all table rows.
Rule high-availability-avoid-non-concurrent-index-creation violation found for statement:
Rule high-availability-avoid-non-concurrent-index-creation violation found for statement:
CREATE INDEX ON films (created_at);
Explanation: Non-concurrent index creation will not allow writes while the index is being built.
Expand All @@ -48,7 +36,7 @@ const expectedFailureOutput = `
Explanation: Non-concurrent index creation will not allow writes while the index is being built.
Rule transactions-concurrent-index-operation-cannot-be-executed-in-transaction violation found for statement:
CREATE INDEX CONCURRENTLY "email_idx" ON "app_user" ("email");
CREATE INDEX CONCURRENTLY "email_idx" ON "companies" ("email");
Explanation: Concurrent index operations cannot be executed inside a transaction.
Rule transactions-no-nested-transactions violation found for statement:
Expand All @@ -59,6 +47,10 @@ const expectedFailureOutput = `
COMMIT;
Explanation: Nested transactions are not supported in PostgreSQL.
Rule high-availability-avoid-table-rename violation found for statement:
ALTER TABLE "movies" RENAME TO "movies_old";
Explanation: Renaming a table can cause errors in previous application versions.
Rule high-availability-avoid-non-concurrent-index-drop violation found for statement:
DROP INDEX IF EXISTS title_idx;
Explanation: Non-concurrent index drop will not allow writes while the index is being built.
Expand Down

0 comments on commit c274f09

Please sign in to comment.