Skip to content

Commit ae2ca99

Browse files
committed
test: add test for ignoreSig configuration
1 parent 68d4f02 commit ae2ca99

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ require (
66
github.com/spf13/viper v1.7.1
77
github.com/stretchr/testify v1.6.1
88
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d
9+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
910
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ignoreSigs:
2+
- json.Marshal(
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
)
6+
7+
func main() {
8+
do()
9+
}
10+
11+
func do() error {
12+
_, err := json.Marshal(struct{}{})
13+
if err != nil {
14+
return err
15+
}
16+
17+
return nil
18+
}

wrapcheck/wrapcheck.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type WrapcheckConfig struct {
3838
// Note: Setting this value will intentionally override the default ignored
3939
// sigs. To achieve the same behaviour as default, you should add the default
4040
// list to your config.
41-
IgnoreSigs []string `mapstructure:"ignoreSigs"`
41+
IgnoreSigs []string `mapstructure:"ignoreSigs" yaml:"ignoreSigs"`
4242
}
4343

4444
func NewDefaultConfig() WrapcheckConfig {

wrapcheck/wrapcheck_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package wrapcheck
22

33
import (
44
"io/ioutil"
5+
"os"
56
"path"
67
"path/filepath"
78
"testing"
89

910
"github.com/stretchr/testify/assert"
1011
"golang.org/x/tools/go/analysis/analysistest"
12+
"gopkg.in/yaml.v3"
1113
)
1214

1315
func TestAnalyzer(t *testing.T) {
@@ -24,10 +26,21 @@ func TestAnalyzer(t *testing.T) {
2426
t.Fatalf("cannot run on non-directory: %s", f.Name())
2527
}
2628

27-
p, err := filepath.Abs(path.Join("./testdata", f.Name()))
29+
dirPath, err := filepath.Abs(path.Join("./testdata", f.Name()))
2830
assert.NoError(t, err)
29-
analysistest.Run(t, p, NewAnalyzer(NewDefaultConfig()))
31+
32+
configPath := path.Join(dirPath, ".wrapcheck.yaml")
33+
if _, err := os.Stat(configPath); os.IsNotExist(err) {
34+
analysistest.Run(t, dirPath, NewAnalyzer(NewDefaultConfig()))
35+
} else {
36+
configFile, err := os.ReadFile(configPath)
37+
assert.NoError(t, err)
38+
39+
var config WrapcheckConfig
40+
assert.NoError(t, yaml.Unmarshal(configFile, &config))
41+
42+
analysistest.Run(t, dirPath, NewAnalyzer(config))
43+
}
3044
})
3145
}
32-
3346
}

0 commit comments

Comments
 (0)