Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 9 additions & 32 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,21 @@ on:
- master
pull_request:

env:
GO_VERSION: 1.20.x

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Checkout code
uses: nhatthm/gh-actions/checkout@master

- id: vars
run: |
make $GITHUB_OUTPUT
- name: Setup
uses: nhatthm/gh-actions/find-go-version@master

- name: lint
uses: golangci/golangci-lint-action@v3
- name: Install Go
uses: nhatthm/gh-actions/setup-go@master
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: ${{ steps.vars.outputs.GOLANGCI_LINT_VERSION }}

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
# skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true
go-version: ${{ env.GO_LATEST_VERSION }}

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
- name: Lint
uses: nhatthm/gh-actions/golangci-lint@master
58 changes: 30 additions & 28 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: test

on:
Expand All @@ -7,54 +8,55 @@ on:
pull_request:

env:
GO111MODULE: on
GO_LATEST_VERSION: 1.20.x
GO111MODULE: "on"

jobs:
setup:
runs-on: ubuntu-latest
outputs:
go-latest-version: ${{ steps.find-go-version.outputs.go-latest-version }}
go-supported-versions: ${{ steps.find-go-version.outputs.go-supported-versions }}
steps:
- name: Checkout code
uses: nhatthm/gh-actions/checkout@master

- id: find-go-version
name: Find Go version
uses: nhatthm/gh-actions/find-go-version@master

test:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest ]
go-version: [ 1.18.x, 1.19.x, 1.20.x ]
go-version: ${{ fromJson(needs.setup.outputs.go-supported-versions) }}
runs-on: ${{ matrix.os }}
needs: [setup]
env:
GO_LATEST_VERSION: ${{ needs.setup.outputs.go-latest-version }}
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v4
uses: nhatthm/gh-actions/checkout@master

- name: Go cache
uses: actions/cache@v3
- name: Install Go
uses: nhatthm/gh-actions/setup-go@master
with:
# In order:
# * Module download cache
# * Build cache (Linux)
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ matrix.go-version }}-cache-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-cache
go-version: ${{ matrix.go-version }}

- name: Test
id: test
run: |
make test

- name: Upload code coverage (unit)
if: matrix.go-version == env.GO_LATEST_VERSION
uses: codecov/codecov-action@v3
uses: nhatthm/gh-actions/codecov@master
with:
file: ./unit.coverprofile
flags: unittests-${{ runner.os }}

# - name: Upload code coverage (features)
# if: matrix.go-version == env.GO_LATEST_VERSION
# uses: codecov/codecov-action@v3
# with:
# file: ./features.coverprofile
# flags: featurestests-${{ runner.os }}
#- name: Upload code coverage (features)
# if: matrix.go-version == env.GO_LATEST_VERSION
# uses: nhatthm/gh-actions/codecov@master
# with:
# file: ./features.coverprofile
# flags: featurestests-${{ runner.os }}
9 changes: 9 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ linters-settings:
linters:
enable-all: true
disable:
- deadcode
- depguard
- exhaustivestruct
- exhaustruct
- forbidigo
Expand All @@ -33,13 +35,20 @@ linters:
- ireturn
- lll
- maligned
- nonamedreturns
- nosnakecase
- nolintlint # https://github.com/golangci/golangci-lint/issues/3063
- paralleltest
- scopelint
- structcheck
- tagliatelle
- testpackage
- varcheck
- varnamelen
- wrapcheck

issues:
max-same-issues: 20
exclude-use-default: false
exclude-rules:
- linters:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ VENDOR_DIR = vendor

GITHUB_OUTPUT ?= /dev/null

GOLANGCI_LINT_VERSION ?= v1.51.1
GOLANGCI_LINT_VERSION ?= v1.55.2

GO ?= go
GOLANGCI_LINT ?= $(shell go env GOPATH)/bin/golangci-lint-$(GOLANGCI_LINT_VERSION)
Expand Down
20 changes: 10 additions & 10 deletions config/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ plugins:
assert.Equal(t, tc.expectedConfig, cfg)

if tc.expectedError == "" {
assert.NoError(t, err)
require.NoError(t, err)
} else {
assert.EqualError(t, err, tc.expectedError)
require.EqualError(t, err, tc.expectedError)
}
})
}
Expand Down Expand Up @@ -189,9 +189,9 @@ func TestFileConfigurator_SetPlugin_Error(t *testing.T) {
err := c.SetPlugin(plugin.Plugin{Name: "my-plugin"})

if tc.expectedError == "" {
assert.NoError(t, err)
require.NoError(t, err)
} else {
assert.EqualError(t, err, tc.expectedError)
require.EqualError(t, err, tc.expectedError)
}
})
}
Expand Down Expand Up @@ -301,9 +301,9 @@ func TestFileConfigurator_RemovePlugin_Error(t *testing.T) {
err := c.RemovePlugin("my-plugin")

if tc.expectedError == "" {
assert.NoError(t, err)
require.NoError(t, err)
} else {
assert.EqualError(t, err, tc.expectedError)
require.EqualError(t, err, tc.expectedError)
}
})
}
Expand Down Expand Up @@ -410,9 +410,9 @@ func TestFileConfigurator_EnablePlugin_Error(t *testing.T) {
err := c.EnablePlugin(tc.pluginName)

if tc.expectedError == "" {
assert.NoError(t, err)
require.NoError(t, err)
} else {
assert.EqualError(t, err, tc.expectedError)
require.EqualError(t, err, tc.expectedError)
}
})
}
Expand Down Expand Up @@ -531,9 +531,9 @@ func TestFileConfigurator_DisablePlugin_Error(t *testing.T) {
err := c.DisablePlugin(tc.pluginName)

if tc.expectedError == "" {
assert.NoError(t, err)
require.NoError(t, err)
} else {
assert.EqualError(t, err, tc.expectedError)
require.EqualError(t, err, tc.expectedError)
}
})
}
Expand Down
25 changes: 13 additions & 12 deletions config/mem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/nhatthm/plugin-registry/config"
"github.com/nhatthm/plugin-registry/mock/configurator"
"github.com/nhatthm/plugin-registry/plugin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestNewMemConfigurator(t *testing.T) {
Expand Down Expand Up @@ -45,10 +46,10 @@ func TestNewMemConfigurator(t *testing.T) {

if tc.expectedError == "" {
assert.NotNil(t, c)
assert.NoError(t, err)
require.NoError(t, err)
} else {
assert.Nil(t, c)
assert.EqualError(t, err, tc.expectedError)
require.EqualError(t, err, tc.expectedError)
}
})
}
Expand Down Expand Up @@ -173,9 +174,9 @@ func TestMemConfigurator_SetPlugin(t *testing.T) {
assert.Equal(t, tc.expectedConfig, actualCfg)

if tc.expectedError == "" {
assert.NoError(t, err)
require.NoError(t, err)
} else {
assert.EqualError(t, err, tc.expectedError)
require.EqualError(t, err, tc.expectedError)
}
})
}
Expand Down Expand Up @@ -256,9 +257,9 @@ func TestMemConfigurator_RemovePlugin(t *testing.T) {
assert.Equal(t, tc.expectedConfig, actualCfg)

if tc.expectedError == "" {
assert.NoError(t, err)
require.NoError(t, err)
} else {
assert.EqualError(t, err, tc.expectedError)
require.EqualError(t, err, tc.expectedError)
}
})
}
Expand Down Expand Up @@ -378,9 +379,9 @@ func TestMemConfigurator_EnablePlugin(t *testing.T) {
assert.Equal(t, tc.expectedConfig, actualCfg)

if tc.expectedError == "" {
assert.NoError(t, err)
require.NoError(t, err)
} else {
assert.EqualError(t, err, tc.expectedError)
require.EqualError(t, err, tc.expectedError)
}
})
}
Expand Down Expand Up @@ -500,9 +501,9 @@ func TestMemConfigurator_DisablePlugin(t *testing.T) {
assert.Equal(t, tc.expectedConfig, actualCfg)

if tc.expectedError == "" {
assert.NoError(t, err)
require.NoError(t, err)
} else {
assert.EqualError(t, err, tc.expectedError)
require.EqualError(t, err, tc.expectedError)
}
})
}
Expand Down
8 changes: 4 additions & 4 deletions disable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"errors"
"testing"

configuratorMock "github.com/nhatthm/plugin-registry/mock/configurator"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

configuratorMock "github.com/nhatthm/plugin-registry/mock/configurator"
)

func TestRegistry_Disable(t *testing.T) {
Expand Down Expand Up @@ -45,9 +45,9 @@ func TestRegistry_Disable(t *testing.T) {
err = r.Disable("my-plugin")

if tc.expectedError == "" {
assert.NoError(t, err)
require.NoError(t, err)
} else {
assert.EqualError(t, err, tc.expectedError)
require.EqualError(t, err, tc.expectedError)
}
})
}
Expand Down
8 changes: 4 additions & 4 deletions enable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"errors"
"testing"

configuratorMock "github.com/nhatthm/plugin-registry/mock/configurator"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

configuratorMock "github.com/nhatthm/plugin-registry/mock/configurator"
)

func TestRegistry_Enable(t *testing.T) {
Expand Down Expand Up @@ -45,9 +45,9 @@ func TestRegistry_Enable(t *testing.T) {
err = r.Enable("my-plugin")

if tc.expectedError == "" {
assert.NoError(t, err)
require.NoError(t, err)
} else {
assert.EqualError(t, err, tc.expectedError)
require.EqualError(t, err, tc.expectedError)
}
})
}
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/stretchr/objx v0.5.1 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
Loading