Skip to content

Commit 81a1d01

Browse files
authored
ci: add golangci-lint workflow and fix lint errors (#34)
1 parent 76b2eac commit 81a1d01

File tree

9 files changed

+66
-13
lines changed

9 files changed

+66
-13
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.go text eol=lf

.github/workflows/golangci-lint.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
permissions:
9+
contents: read
10+
# Optional: allow read access to pull request. Use with `only-new-issues` option.
11+
pull-requests: read
12+
13+
jobs:
14+
golangci:
15+
name: lint
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
- uses: actions/setup-go@v4
20+
with:
21+
go-version: '1.21'
22+
cache: false
23+
- name: golangci-lint
24+
uses: golangci/golangci-lint-action@v3
25+
with:
26+
# Require: The version of golangci-lint to use.
27+
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
28+
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
29+
version: v1.54
30+
31+
# Optional: working directory, useful for monorepos
32+
# working-directory: somedir
33+
34+
# Optional: golangci-lint command line arguments.
35+
#
36+
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
37+
# The location of the configuration file can be changed by using `--config=`
38+
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
39+
40+
# Optional: show only new issues if it's a pull request. The default value is `false`.
41+
only-new-issues: true
42+
43+
# Optional: if set to true, then all caching functionality will be completely disabled,
44+
# takes precedence over all other caching options.
45+
# skip-cache: true
46+
47+
# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
48+
# skip-pkg-cache: true
49+
50+
# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
51+
# skip-build-cache: true
52+
53+
# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
54+
# install-mode: "goinstall"

internal/pkg/db/memdb_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestGetServiceByID(t *testing.T) {
5555
assert.Equal(t, svc, service, "check the service")
5656

5757
// Test Case 2: get service by id (not found)
58-
service, err = db.GetServiceByID("not-found")
58+
_, err = db.GetServiceByID("not-found")
5959
assert.Equal(t, NotFound, err, "check the error")
6060

6161
// Test Case 3: Service don't have id
@@ -83,7 +83,7 @@ func TestGetRouteByID(t *testing.T) {
8383
assert.Equal(t, route, route1, "check the route")
8484

8585
// Test Case 2: get route by id (not found)
86-
route1, err = db.GetRouteByID("not-found")
86+
_, err = db.GetRouteByID("not-found")
8787
assert.Equal(t, NotFound, err, "check the error")
8888

8989
// Test Case 3: Route don't have id

internal/pkg/differ/differ.go

-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ type Differ struct {
6161
localDB *db.DB
6262
localConfig *types.Configuration
6363
remoteConfig *types.Configuration
64-
65-
evenChan *data.Event
6664
}
6765

6866
// NewDiffer creates a new Differ object.

internal/pkg/validator/validator.go

-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ import (
77
"github.com/api7/adc/pkg/api/apisix"
88
"github.com/api7/adc/pkg/api/apisix/types"
99
"github.com/api7/adc/pkg/common"
10-
"github.com/api7/adc/pkg/data"
1110
)
1211

1312
type Validator struct {
1413
localConfig *types.Configuration
1514
cluster apisix.Cluster
16-
17-
evenChan *data.Event
1815
}
1916

2017
func NewValidator(local *types.Configuration, cluster apisix.Cluster) (*Validator, error) {

test/cli/scaffold/scaffold.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ func NewScaffold() *Scaffold {
4747
})
4848

4949
ginkgo.AfterEach(func() {
50-
for route, _ := range s.routes {
50+
for route := range s.routes {
5151
s.DeleteRoute(route)
5252
}
53-
for svc, _ := range s.services {
53+
for svc := range s.services {
5454
s.DeleteService(svc)
5555
}
56-
for consumer, _ := range s.consumers {
56+
for consumer := range s.consumers {
5757
s.DeleteConsumer(consumer)
5858
}
59-
for globalRule, _ := range s.globalRules {
59+
for globalRule := range s.globalRules {
6060
s.DeleteGlobalRule(globalRule)
6161
}
62-
for pluginConfig, _ := range s.pluginConfigs {
62+
for pluginConfig := range s.pluginConfigs {
6363
s.DeletePluginConfig(pluginConfig)
6464
}
65-
for consumerGroup, _ := range s.consumerGroups {
65+
for consumerGroup := range s.consumerGroups {
6666
s.DeleteConsumerGroup(consumerGroup)
6767
}
6868
for pluginMetadata, _ := range s.pluginMetadatas {

test/cli/suites-consumer/sdk.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var _ = ginkgo.Describe("adc APISIX consumer SDK tests", func() {
3131
Username: "consumer1",
3232
}
3333
_, err = s.CreateConsumer(baseConsumer1)
34+
gomega.Expect(err).To(gomega.BeNil(), "error while creating consumer")
3435

3536
// get consumer 1
3637
consumer, err = s.GetConsumer("consumer1")

test/cli/suites/dump.go

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ version: ""
7171
err = s.DeleteService("svc1")
7272
gomega.Expect(err).To(gomega.BeNil(), "check service delete")
7373
err = s.DeleteService("svc2")
74+
gomega.Expect(err).To(gomega.BeNil(), "check service delete")
7475
})
7576
})
7677
})

test/cli/suites/sdk.go

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var _ = ginkgo.Describe("adc APISIX SDK tests", func() {
5555
ServiceID: "svc1",
5656
}
5757
_, err = s.CreateRoute(baseRoute1)
58+
gomega.Expect(err).To(gomega.BeNil(), "check route creation")
5859

5960
// get route 1
6061
route, err = s.GetRoute("route1")

0 commit comments

Comments
 (0)