Skip to content

Commit 297e8c5

Browse files
committed
test: adapted tests to the move as a standalone module
* test code in fixtures comes as its own module: main module dependencies don't get polluted * tests exercise different ways to resolve package: * fully qualified module * relative path * with build tags Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent 410182e commit 297e8c5

22 files changed

Lines changed: 240 additions & 65 deletions

.golangci.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
version: "2"
2+
linters:
3+
# Project stance regarding linting - see also https://github.com/go-swagger/go-swagger/issues/3237:
4+
#
5+
# * we enable all linters by default
6+
# * we disable explicitly linters which:
7+
# * do not correspond to our own views of go best practices (e.g. recvcheck, nonamedreturns)
8+
# * impose a lot of (cosmetic) changes for no real value AND do not provide an auto-fix (e.g. godox, nlreturn)
9+
# * impose a lot of not-cosmetic changes with no high value AND do not provide an auto-fix (e.g. err113)
10+
# * introduce breaking changes (normally, we should disable them sparingly with code hints, no globally)
11+
# * we overall agree with but are temporarily disabled: these issues would be addressed progressively
12+
#
13+
# This project has been living around for about 10 years now.
14+
# It adopted golangci-lint as one of its early adopters.
15+
# Since then, we've seen a lot of back and forth on how we should write good go code.
16+
# So we pick every month's new doxa with a pinch of salt.
17+
default: all
18+
disable:
19+
- dupl # temporary => should be disabled sparingly
20+
- err113 # temporary
21+
- exhaustruct # temporary
22+
- funlen # temporary
23+
- gochecknoglobals # agree, but breaking
24+
- gochecknoinits # agree, but breaking
25+
- godox # temporary
26+
- ireturn # temporary
27+
- lll # unclear added value
28+
- nestif # temporary
29+
- nonamedreturns # unclear added value
30+
- nlreturn # unclear added value
31+
- noinlineerr # unclear added value
32+
- paralleltest # unclear added value
33+
- recvcheck # disagree
34+
- tagliatelle # false positives, want to impose camel case everywhere => should be disabled sparingly only
35+
- testpackage # disagree: we like test packages, just not for everything like the linter suggests
36+
- thelper
37+
- tparallel
38+
- varnamelen
39+
- whitespace
40+
- wrapcheck
41+
- wsl
42+
- wsl_v5
43+
settings:
44+
depguard:
45+
rules:
46+
main:
47+
list-mode: lax
48+
deny:
49+
- pkg: github.com/pkg/errors
50+
desc: Use errors or fmt instead of github.com/pkg/errors
51+
dupl:
52+
threshold: 200
53+
goconst:
54+
min-len: 2
55+
min-occurrences: 3
56+
cyclop:
57+
max-complexity: 32
58+
gocyclo:
59+
min-complexity: 32
60+
gocognit:
61+
min-complexity: 32
62+
govet:
63+
enable-all: true
64+
disable:
65+
- fieldalignment
66+
exhaustive:
67+
default-signifies-exhaustive: true
68+
default-case-required: true
69+
lll:
70+
line-length: 180
71+
exclusions:
72+
warn-unused: false
73+
generated: lax # enable linting on generated code (in examples, in generated code under test)
74+
presets:
75+
- comments
76+
- common-false-positives
77+
- legacy
78+
- std-error-handling
79+
paths:
80+
- fixtures/
81+
rules:
82+
- path: 'generator/generated/'
83+
linters:
84+
- gofumpt # we don't run gofumpt on generated code (used during testing)
85+
- path: _test.go
86+
linters:
87+
- unparam
88+
formatters:
89+
enable:
90+
- gofmt
91+
- goimports
92+
- gofumpt
93+
settings:
94+
# local prefixes regroup imports from these packages
95+
goimports:
96+
local-prefixes:
97+
- github.com/go-openapi
98+
- github.com/go-swagger/go-swagger # this is for imports in generated examples
99+
exclusions:
100+
generated: lax
101+
paths:
102+
- fixtures/
103+
issues:
104+
# Maximum issues count per one linter.
105+
# Set to 0 to disable.
106+
# Default: 50
107+
max-issues-per-linter: 0
108+
# Maximum count of issues with the same text.
109+
# Set to 0 to disable.
110+
# Default: 3
111+
max-same-issues: 0
112+
new: false

application_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ func TestApplication_LoadCode(t *testing.T) {
6262

6363
func TestAppScanner_NewSpec(t *testing.T) {
6464
doc, err := Run(&Options{
65-
Packages: []string{"github.com/go-swagger/go-swagger/fixtures/goparsing/petstore/..."},
65+
Packages: []string{"./goparsing/petstore/..."},
66+
WorkDir: "fixtures",
6667
})
6768
require.NoError(t, err)
6869
require.NotNil(t, doc)
@@ -72,7 +73,8 @@ func TestAppScanner_NewSpec(t *testing.T) {
7273

7374
func TestAppScanner_Definitions(t *testing.T) {
7475
doc, err := Run(&Options{
75-
Packages: []string{"github.com/go-swagger/go-swagger/fixtures/goparsing/bookings/..."},
76+
Packages: []string{"./goparsing/bookings/..."},
77+
WorkDir: "fixtures",
7678
ScanModels: true,
7779
})
7880
require.NoError(t, err)
@@ -97,7 +99,8 @@ func loadPetstorePkgsCtx(t *testing.T) *scanCtx {
9799
return petstoreCtx
98100
}
99101
sctx, err := newScanCtx(&Options{
100-
Packages: []string{"github.com/go-swagger/go-swagger/fixtures/goparsing/petstore/..."},
102+
Packages: []string{"./goparsing/petstore/..."},
103+
WorkDir: "fixtures",
101104
})
102105
require.NoError(t, err)
103106
petstoreCtx = sctx
@@ -114,10 +117,11 @@ func loadClassificationPkgsCtx(t *testing.T, extra ...string) *scanCtx {
114117

115118
sctx, err := newScanCtx(&Options{
116119
Packages: append([]string{
117-
"github.com/go-swagger/go-swagger/fixtures/goparsing/classification",
118-
"github.com/go-swagger/go-swagger/fixtures/goparsing/classification/models",
119-
"github.com/go-swagger/go-swagger/fixtures/goparsing/classification/operations",
120+
"./goparsing/classification",
121+
"./goparsing/classification/models",
122+
"./goparsing/classification/operations",
120123
}, extra...),
124+
WorkDir: "fixtures",
121125
})
122126
require.NoError(t, err)
123127
classificationCtx = sctx

fixtures/go.mod

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module github.com/go-openapi/codescan/fixtures
2+
3+
go 1.25.0
4+
5+
require (
6+
github.com/go-openapi/runtime v0.29.3
7+
github.com/go-openapi/strfmt v0.26.1
8+
github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013
9+
)
10+
11+
require (
12+
github.com/go-openapi/errors v0.22.7 // indirect
13+
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
14+
github.com/google/uuid v1.6.0 // indirect
15+
github.com/oklog/ulid/v2 v2.1.1 // indirect
16+
golang.org/x/net v0.52.0 // indirect
17+
golang.org/x/text v0.35.0 // indirect
18+
)

fixtures/go.sum

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
github.com/go-openapi/errors v0.22.7 h1:JLFBGC0Apwdzw3484MmBqspjPbwa2SHvpDm0u5aGhUA=
2+
github.com/go-openapi/errors v0.22.7/go.mod h1://QW6SD9OsWtH6gHllUCddOXDL0tk0ZGNYHwsw4sW3w=
3+
github.com/go-openapi/runtime v0.29.3 h1:h5twGaEqxtQg40ePiYm9vFFH1q06Czd7Ot6ufdK0w/Y=
4+
github.com/go-openapi/runtime v0.29.3/go.mod h1:8A1W0/L5eyNJvKciqZtvIVQvYO66NlB7INMSZ9bw/oI=
5+
github.com/go-openapi/strfmt v0.26.1 h1:7zGCHji7zSYDC2tCXIusoxYQz/48jAf2q+sF6wXTG+c=
6+
github.com/go-openapi/strfmt v0.26.1/go.mod h1:Zslk5VZPOISLwmWTMBIS7oiVFem1o1EI6zULY8Uer7Y=
7+
github.com/go-openapi/testify/v2 v2.4.1 h1:zB34HDKj4tHwyUQHrUkpV0Q0iXQ6dUCOQtIqn8hE6Iw=
8+
github.com/go-openapi/testify/v2 v2.4.1/go.mod h1:HCPmvFFnheKK2BuwSA0TbbdxJ3I16pjwMkYkP4Ywn54=
9+
github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013 h1:l9rI6sNaZgNC0LnF3MiE+qTmyBA/tZAg1rtyrGbUMK0=
10+
github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013/go.mod h1:b65mBPzqzZWxOZGxSWrqs4GInLIn+u99Q9q7p+GKni0=
11+
github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro=
12+
github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
13+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
14+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
15+
github.com/oklog/ulid/v2 v2.1.1 h1:suPZ4ARWLOJLegGFiZZ1dFAkqzhMjL3J1TzI+5wHz8s=
16+
github.com/oklog/ulid/v2 v2.1.1/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
17+
github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
18+
golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0=
19+
golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw=
20+
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
21+
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=

fixtures/goparsing/classification/models/extranomodel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"time"
2020

2121
"github.com/go-openapi/strfmt"
22-
"github.com/go-swagger/go-swagger/fixtures/goparsing/classification/transitive/mods"
22+
"github.com/go-openapi/codescan/fixtures/goparsing/classification/transitive/mods"
2323
)
2424

2525
// A Something struct is used by other structs

fixtures/goparsing/classification/models/nomodel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"time"
2020

2121
"github.com/go-openapi/strfmt"
22-
"github.com/go-swagger/go-swagger/fixtures/goparsing/classification/transitive/mods"
22+
"github.com/go-openapi/codescan/fixtures/goparsing/classification/transitive/mods"
2323
)
2424

2525
// NoModel is a struct without an annotation.

fixtures/goparsing/classification/models/order.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
package models
1616

17-
import "github.com/go-swagger/go-swagger/fixtures/goparsing/classification/transitive/mods"
17+
import "github.com/go-openapi/codescan/fixtures/goparsing/classification/transitive/mods"
1818

1919
// # StoreOrder represents an order in this application.
2020
//

fixtures/goparsing/classification/operations/noparams.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"bytes"
1919

2020
"github.com/go-openapi/strfmt"
21-
"github.com/go-swagger/go-swagger/fixtures/goparsing/classification/models"
22-
"github.com/go-swagger/go-swagger/fixtures/goparsing/classification/transitive/mods"
21+
"github.com/go-openapi/codescan/fixtures/goparsing/classification/models"
22+
"github.com/go-openapi/codescan/fixtures/goparsing/classification/transitive/mods"
2323
)
2424

2525
// MyFileParams contains the uploaded file data

fixtures/goparsing/classification/operations/responses.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package operations
1616

1717
import (
1818
"github.com/go-openapi/strfmt"
19-
"github.com/go-swagger/go-swagger/fixtures/goparsing/classification/transitive/mods"
19+
"github.com/go-openapi/codescan/fixtures/goparsing/classification/transitive/mods"
2020
)
2121

2222
// A GenericError is an error that is used when no other error is appropriate

fixtures/goparsing/petstore/models/pet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package models
1717
import (
1818
"time"
1919

20-
"github.com/go-swagger/go-swagger/fixtures/goparsing/petstore/enums"
20+
"github.com/go-openapi/codescan/fixtures/goparsing/petstore/enums"
2121
)
2222

2323
// A Pet is the main product in the store.

0 commit comments

Comments
 (0)