mirror of
https://github.com/xataio/pgroll.git
synced 2024-09-11 05:45:48 +03:00
Add linter to tests (#9)
Found some lint warnings, let's have them in CI
This commit is contained in:
parent
838f8d4c46
commit
6c4748916c
1
.github/settings.yml
vendored
1
.github/settings.yml
vendored
@ -74,6 +74,7 @@ branches:
|
||||
# Required. The list of status checks to require in order to merge into this branch
|
||||
contexts:
|
||||
- test
|
||||
- lint
|
||||
|
||||
# Required. Require at least one approving review on a pull request, before merging. Set to null to disable.
|
||||
required_pull_request_reviews:
|
||||
|
42
.github/workflows/build.yml
vendored
Normal file
42
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
name: Build
|
||||
on: [push]
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.20'
|
||||
|
||||
- name: Run tests
|
||||
run: go test ./...
|
||||
|
||||
lint:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.20'
|
||||
cache: false
|
||||
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
# Require: The version of golangci-lint to use.
|
||||
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
|
||||
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
|
||||
version: v1.53
|
||||
|
||||
# Optional: golangci-lint command line arguments.
|
||||
#
|
||||
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
|
||||
# The location of the configuration file can be changed by using `--config=`
|
||||
args: --timeout=30m --out-format=colored-line-number --config=.golangci.yml
|
16
.github/workflows/test.yaml
vendored
16
.github/workflows/test.yaml
vendored
@ -1,16 +0,0 @@
|
||||
name: Run tests
|
||||
on: [push]
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.20'
|
||||
|
||||
- name: Run tests
|
||||
run: go test ./...
|
80
.golangci.yml
Normal file
80
.golangci.yml
Normal file
@ -0,0 +1,80 @@
|
||||
goVersion: &goVersion "1.20"
|
||||
|
||||
run:
|
||||
go: *goVersion
|
||||
timeout: 5m
|
||||
|
||||
linters:
|
||||
disable-all: true
|
||||
# Enable specific linter
|
||||
# https://golangci-lint.run/usage/linters/#enabled-by-default-linters
|
||||
enable:
|
||||
- errorlint
|
||||
- exportloopref
|
||||
- forcetypeassert
|
||||
- goconst
|
||||
- gocritic
|
||||
- gofumpt
|
||||
- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- makezero
|
||||
- misspell
|
||||
- nakedret
|
||||
- nolintlint
|
||||
- prealloc
|
||||
- prealloc
|
||||
- staticcheck
|
||||
- stylecheck
|
||||
- unused
|
||||
|
||||
linters-settings:
|
||||
errorlint:
|
||||
errorf: true
|
||||
|
||||
gomodguard:
|
||||
blocked:
|
||||
# List of blocked modules.
|
||||
modules:
|
||||
# Blocked module.
|
||||
- github.com/pkg/errors:
|
||||
# Recommended modules that should be used instead. (Optional)
|
||||
recommendations:
|
||||
- errors
|
||||
- fmt
|
||||
reason: "This package is deprecated, use `fmt.Errorf` with `%w` instead"
|
||||
|
||||
goconst:
|
||||
ignore-tests: true
|
||||
numbers: true
|
||||
|
||||
gocritic:
|
||||
disabled-checks:
|
||||
- exitAfterDefer
|
||||
- ifElseChain
|
||||
- commentFormatting
|
||||
|
||||
gofumpt:
|
||||
lang-version: *goVersion
|
||||
module-path: "pg-roll"
|
||||
extra-rules: false
|
||||
|
||||
staticcheck:
|
||||
go: *goVersion
|
||||
checks: ["all"]
|
||||
|
||||
stylecheck:
|
||||
go: *goVersion
|
||||
checks: ["all", "-ST1000", "-ST1005"]
|
||||
|
||||
unused:
|
||||
go: *goVersion
|
||||
|
||||
makezero:
|
||||
always: false
|
||||
|
||||
gosec:
|
||||
exclude-generated: true
|
||||
severity: low
|
||||
includes: []
|
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"gopls": {
|
||||
"formatting.gofumpt": true,
|
||||
"formatting.local": "pg-roll"
|
||||
}
|
||||
}
|
@ -29,12 +29,12 @@ var analyzeCmd = &cobra.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
schemaJson, err := json.MarshalIndent(s, "", " ")
|
||||
schemaJSON, err := json.MarshalIndent(s, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(schemaJson))
|
||||
fmt.Println(string(schemaJSON))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
@ -3,9 +3,10 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"pg-roll/pkg/migrations"
|
||||
"strings"
|
||||
|
||||
"pg-roll/pkg/migrations"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -3,9 +3,10 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"pg-roll/pkg/migrations"
|
||||
"strings"
|
||||
|
||||
"pg-roll/pkg/migrations"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
18
cmd/root.go
18
cmd/root.go
@ -4,22 +4,18 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
PGURL string
|
||||
)
|
||||
var PGURL string
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().StringVar(&PGURL, "postgres_url", "postgres://postgres:postgres@localhost?sslmode=disable", "Postgres URL")
|
||||
}
|
||||
|
||||
var (
|
||||
rootCmd = &cobra.Command{
|
||||
Use: "pg-roll",
|
||||
Short: "TODO: Add short description",
|
||||
Long: `TODO: Add long description`,
|
||||
SilenceUsage: true,
|
||||
}
|
||||
)
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "pg-roll",
|
||||
Short: "TODO: Add short description",
|
||||
Long: `TODO: Add long description`,
|
||||
SilenceUsage: true,
|
||||
}
|
||||
|
||||
// Execute executes the root command.
|
||||
func Execute() error {
|
||||
|
@ -3,9 +3,10 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"pg-roll/pkg/migrations"
|
||||
"strings"
|
||||
|
||||
"pg-roll/pkg/migrations"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
6
main.go
6
main.go
@ -1,9 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"pg-roll/cmd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cmd.Execute()
|
||||
if err := cmd.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,10 @@ package migrations
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"pg-roll/pkg/schema"
|
||||
"strings"
|
||||
|
||||
"pg-roll/pkg/schema"
|
||||
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
|
@ -3,6 +3,7 @@ package migrations
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"pg-roll/pkg/schema"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"pg-roll/pkg/schema"
|
||||
|
||||
"github.com/lib/pq"
|
||||
|
@ -74,13 +74,13 @@ func TestRecordsCanBeInsertedIntoAndReadFromNewViewAfterMigrationStart(t *testin
|
||||
defer insertStmt.Close()
|
||||
|
||||
type user struct {
|
||||
Id int
|
||||
ID int
|
||||
Name string
|
||||
}
|
||||
inserted := []user{{Id: 1, Name: "Alice"}, {Id: 2, Name: "Bob"}}
|
||||
inserted := []user{{ID: 1, Name: "Alice"}, {ID: 2, Name: "Bob"}}
|
||||
|
||||
for _, v := range inserted {
|
||||
_, err = insertStmt.Exec(v.Id, v.Name)
|
||||
_, err = insertStmt.Exec(v.ID, v.Name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -99,7 +99,7 @@ func TestRecordsCanBeInsertedIntoAndReadFromNewViewAfterMigrationStart(t *testin
|
||||
var retrieved []user
|
||||
for rows.Next() {
|
||||
var user user
|
||||
if err := rows.Scan(&user.Id, &user.Name); err != nil {
|
||||
if err := rows.Scan(&user.ID, &user.Name); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
retrieved = append(retrieved, user)
|
||||
|
Loading…
Reference in New Issue
Block a user