Skip to content

Commit 95b955b

Browse files
authored
Merge pull request #22 from golift/dn2_again
trying to fix golangci-lint GitHub action
2 parents dfb9a3d + b049d14 commit 95b955b

File tree

9 files changed

+73
-65
lines changed

9 files changed

+73
-65
lines changed

.github/workflows/codetests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: golangci-lint
3737
uses: golangci/golangci-lint-action@v3
3838
with:
39-
version: 'v1.53'
39+
version: 'v1.55'
4040
# Runs golangci-lint on linux against linux and windows.
4141
golangci-linux:
4242
strategy:
@@ -54,4 +54,4 @@ jobs:
5454
- name: golangci-lint
5555
uses: golangci/golangci-lint-action@v3
5656
with:
57-
version: 'v1.53'
57+
version: 'v1.55'

.golangci.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ linters:
2222
- structcheck
2323
- deadcode
2424
- ifshort
25-
- rowserrcheck
26-
- sqlclosecheck
27-
- wastedassign
2825
- exhaustive
26+
- depguard
27+
- tagalign
2928

3029
run:
3130
timeout: 3m

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
MIT LICENSE.
2-
Copyright (c) 2019-2023 Go Lift - Building Strong Go Tools
2+
Copyright (c) 2019-2024 Go Lift - Building Strong Go Tools
33

44
Permission is hereby granted, free of charge, to any person obtaining
55
a copy of this software and associated documentation files (the

config_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
1112
"golift.io/cnfg"
1213
)
1314

@@ -71,7 +72,7 @@ func TestUnmarshalText(t *testing.T) {
7172
d := cnfg.Duration{Duration: time.Minute + time.Second}
7273
b, err := d.MarshalText()
7374

74-
assert.Nil(t, err, "this method must not return an error")
75+
require.NoError(t, err, "this method must not return an error")
7576
assert.Equal(t, []byte("1m1s"), b)
7677
}
7778

@@ -81,7 +82,7 @@ func TestUnmarshalJSON(t *testing.T) {
8182
d := cnfg.Duration{Duration: time.Minute + time.Hour}
8283
b, err := d.MarshalJSON()
8384

84-
assert.Nil(t, err, "this method must not return an error")
85+
require.NoError(t, err, "this method must not return an error")
8586
assert.Equal(t, []byte(`"1h1m0s"`), b)
8687
}
8788

env.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func MarshalENV(i interface{}, prefix string) (Pairs, error) {
4646
return (&ENV{Pfx: prefix, Tag: ENVTag}).Marshal(i)
4747
}
4848

49-
// Marshal converts deconstructs a data structure into environment variable pairs.
49+
// Marshal deconstructs a data structure into environment variable pairs.
5050
func (e *ENV) Marshal(i interface{}) (Pairs, error) {
5151
value := reflect.ValueOf(i)
5252
if value.Kind() != reflect.Ptr || value.Elem().Kind() != reflect.Struct {

env_test.go

+32-29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
1213
"golift.io/cnfg"
1314
)
1415

@@ -32,46 +33,48 @@ type testSubConfig struct {
3233
}
3334

3435
// A few tests hit this.
35-
func testUnmarshalFileValues(assert *assert.Assertions, config *testStruct, err error, from string) {
36+
func testUnmarshalFileValues(t *testing.T, assert *assert.Assertions, config *testStruct, err error, from string) {
37+
t.Helper()
38+
3639
from += " "
3740

38-
assert.Nil(err, "there should not be an error reading the test file")
41+
require.NoError(t, err, "there should not be an error reading the test file")
3942
// PointerSlice
40-
assert.Equal(1, len(config.PointerSlice), from+"pointerslice is too short")
43+
assert.Len(config.PointerSlice, 1, from+"pointerslice is too short")
4144
assert.EqualValues(true, config.PointerSlice[0].Bool, from+"the boolean was true")
4245
assert.EqualValues(123.4567, *config.PointerSlice[0].FloatP, from+"the float64 was set to 123.4567")
4346
assert.EqualValues(0, config.PointerSlice[0].Int, from+"int was not set so should be zero")
4447
assert.Nil(config.PointerSlice[0].StringP, from+"the string pointer was not set so should remain nil")
4548

4649
// StructSlice
47-
assert.Equal(1, len(config.StructSlice), from+"pointerslice is too short")
50+
assert.Len(config.StructSlice, 1, from+"pointerslice is too short")
4851
assert.EqualValues(false, config.StructSlice[0].Bool, from+"the boolean was missing and should be false")
49-
assert.Nil(config.StructSlice[0].FloatP, from+"the float64 was missing and should be nil")
52+
assert.Nil(config.StructSlice[0].FloatP, from+"the float64 was missing and should be nil 1")
5053
assert.EqualValues(123, config.StructSlice[0].Int, from+"int was set to 123")
5154
assert.EqualValues("foo", *config.StructSlice[0].StringP, from+"the string was set to foo")
5255

5356
// Struct
5457
assert.EqualValues(false, config.Struct.Bool, from+"the boolean was false and should be false")
55-
assert.Nil(config.Struct.FloatP, from+"the float64 was missing and should be nil")
58+
assert.Nil(config.Struct.FloatP, from+"the float64 was missing and should be nil 2")
5659
assert.EqualValues(0, config.Struct.Int, from+"int was not set and must be 0")
5760
assert.Nil(config.Struct.StringP, from+"the string was missing and should be nil")
5861

5962
// PointerStruct
6063
assert.NotNil(config.PointerStruct, from+"the pointer struct has values and must not be nil")
6164
assert.EqualValues(false, config.PointerStruct.Bool, from+"the boolean was missing and should be false")
62-
assert.Nil(config.PointerStruct.FloatP, from+"the float64 was missing and should be nil")
65+
assert.Nil(config.PointerStruct.FloatP, from+"the float64 was missing and should be nil 3")
6366
assert.EqualValues(0, config.PointerStruct.Int, from+"int was not set and must be 0")
6467
assert.EqualValues("foo2", *config.PointerStruct.StringP, from+"the string was set to foo2")
6568

6669
// PointerSlice2
67-
assert.Equal(0, len(config.PointerSlice2), from+"pointerslice2 is too long")
70+
assert.Empty(config.PointerSlice2, from+"pointerslice2 is too long")
6871
// StructSlice2
69-
assert.Equal(0, len(config.StructSlice2), from+"structslice2 is too long")
72+
assert.Empty(config.StructSlice2, from+"structslice2 is too long")
7073
// Struct2
71-
assert.EqualValues(false, config.Struct2.Bool, from+"this must be zero value")
72-
assert.Nil(config.Struct2.FloatP, from+"this must be zero value")
73-
assert.EqualValues(0, config.Struct2.Int, from+"this must be zero value")
74-
assert.Nil(config.Struct2.StringP, from+"this must be zero value")
74+
assert.EqualValues(false, config.Struct2.Bool, from+"this must be zero value 1")
75+
assert.Nil(config.Struct2.FloatP, from+"this must be zero value 2")
76+
assert.EqualValues(0, config.Struct2.Int, from+"this must be zero value 3")
77+
assert.Nil(config.Struct2.StringP, from+"this must be zero value 4")
7578
// PointerStruct2
7679
assert.Nil(config.PointerStruct2, from+"pointer struct 2 must be nil")
7780
}
@@ -96,19 +99,19 @@ func TestBrokenENV(t *testing.T) { //nolint:paralleltest // cannot parallel env
9699
c := &testBroken{}
97100
worked, err := cnfg.UnmarshalENV(c, "TEST")
98101

99-
assert.NotNil(err, "an error must be returned for an unsupported type")
102+
require.Error(t, err, "an error must be returned for an unsupported type")
100103
assert.False(worked)
101104

102105
config := &testBroken2{}
103106
worked, err = cnfg.UnmarshalENV(config, "TEST")
104107

105-
assert.NotNil(err, "an error must be returned for an unsupported map type")
108+
require.Error(t, err, "an error must be returned for an unsupported map type")
106109
assert.False(worked)
107110

108111
config2 := &testBroken3{}
109112
worked, err = cnfg.UnmarshalENV(config2, "TEST")
110113

111-
assert.NotNil(err, "an error must be returned for an unsupported map type")
114+
require.Error(t, err, "an error must be returned for an unsupported map type")
112115
assert.False(worked)
113116
}
114117

@@ -133,7 +136,7 @@ func TestUnmarshalENVerrors(t *testing.T) { //nolint:paralleltest // cannot para
133136
config := tester{}
134137
worked, err := cnfg.UnmarshalENV(&config, "YO")
135138

136-
assert.Nil(err, "maps are supported and must not produce an error")
139+
require.NoError(t, err, "maps are supported and must not produce an error")
137140
assert.Empty(os.Getenv("YO_WORKS_foo2string"), "delenv must delete the environment variable")
138141
assert.Empty(os.Getenv("YO_WORKS_foostring"), "delenv must delete the environment variable")
139142
assert.True(worked)
@@ -161,7 +164,7 @@ func TestUnmarshalENVerrors(t *testing.T) { //nolint:paralleltest // cannot para
161164
config2 := tester2{HasStuff: []map[string]string{{"freesoda": "at-pops"}, {"a": "v"}}}
162165
worked, err = cnfg.UnmarshalENV(&config2, "MORE")
163166

164-
assert.Nil(err, "map slices are supported and must not produce an error")
167+
require.NoError(t, err, "map slices are supported and must not produce an error")
165168
assert.True(worked)
166169

167170
f := *config2.NotBroken2[0]
@@ -179,7 +182,7 @@ func TestUnmarshalENV(t *testing.T) { //nolint:paralleltest // cannot parallel e
179182
c := &testStruct{}
180183
ok, err := cnfg.UnmarshalENV(c, "PRE")
181184

182-
assert.Nil(err, "there must not be an error when parsing no variables")
185+
require.NoError(t, err, "there must not be an error when parsing no variables")
183186
assert.False(ok, "there are no environment variables set, so ok should be false")
184187
testThingENV(t, assert)
185188
testOscureENV(t, assert)
@@ -188,7 +191,7 @@ func TestUnmarshalENV(t *testing.T) { //nolint:paralleltest // cannot parallel e
188191
f := true
189192
g := &f
190193
_, err = cnfg.UnmarshalENV(g, "OOO")
191-
assert.NotNil(err, "unmarshaling a non-struct pointer must produce an error")
194+
require.Error(t, err, "unmarshaling a non-struct pointer must produce an error")
192195
}
193196

194197
func testThingENV(t *testing.T, assert *assert.Assertions) {
@@ -207,11 +210,11 @@ func testThingENV(t *testing.T, assert *assert.Assertions) {
207210

208211
ok, err := cnfg.UnmarshalENV(config, "PRE")
209212
assert.True(ok, "ok must be true since things must be parsed")
210-
testUnmarshalFileValues(assert, config, err, "testThingENV")
213+
testUnmarshalFileValues(t, assert, config, err, "testThingENV")
211214
// do it again, and we should get the same result
212215
ok, err = cnfg.UnmarshalENV(config, "PRE")
213216
assert.True(ok, "ok must be true since things must be parsed")
214-
testUnmarshalFileValues(assert, config, err, "testThingENV")
217+
testUnmarshalFileValues(t, assert, config, err, "testThingENV")
215218
}
216219

217220
func testOscureENV(t *testing.T, assert *assert.Assertions) {
@@ -238,13 +241,13 @@ func testOscureENV(t *testing.T, assert *assert.Assertions) {
238241
testit := func() {
239242
ok, err := cnfg.UnmarshalENV(config, "OB")
240243
assert.True(ok, "ok must be true since things must be parsed")
241-
assert.Nil(err)
244+
require.NoError(t, err)
242245

243-
assert.EqualValues(2, len(config.FloatSlice))
246+
assert.Len(config.FloatSlice, 2)
244247
assert.EqualValues(-5, config.FloatSlice[0])
245248
assert.EqualValues(8, config.FloatSlice[1])
246249

247-
assert.EqualValues(2, len(config.UintSliceP))
250+
assert.Len(config.UintSliceP, 2)
248251
assert.EqualValues(12, *config.UintSliceP[0])
249252
assert.EqualValues(22, *config.UintSliceP[1])
250253

@@ -254,9 +257,9 @@ func testOscureENV(t *testing.T, assert *assert.Assertions) {
254257
weirdo := *config.Weirdo
255258
wut := *config.Wut
256259

257-
assert.EqualValues(1, len(weirdo))
260+
assert.Len(weirdo, 1)
258261
assert.EqualValues(-1, weirdo[0])
259-
assert.EqualValues(1, len(wut))
262+
assert.Len(wut, 1)
260263
assert.True(wut[0].Bool)
261264
}
262265

@@ -289,7 +292,7 @@ func testSpecialENV(t *testing.T, assert *assert.Assertions) {
289292
worked, err := (&cnfg.ENV{Pfx: "TEST"}).Unmarshal(config)
290293

291294
assert.True(worked, "ok must be true since things must be parsed")
292-
assert.Nil(err)
295+
require.NoError(t, err)
293296
assert.Equal(time.Minute, config.Dur)
294297
assert.Equal(time.Second, config.CDur.Duration)
295298
assert.Equal("golift.io", config.Sub.URL.Host, "the url wasn't parsed properly")
@@ -302,5 +305,5 @@ func testSpecialENV(t *testing.T, assert *assert.Assertions) {
302305
worked, err = (&cnfg.ENV{Pfx: "TEST"}).Unmarshal(config)
303306

304307
assert.False(worked, "cannot parse an invalid time")
305-
assert.NotNil(err, "cannot parse an invalid time")
308+
require.Error(t, err, "cannot parse an invalid time")
306309
}

map_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
910
"golift.io/cnfg"
1011
)
1112

@@ -26,18 +27,18 @@ func TestUnmarshalMap(t *testing.T) {
2627
config := mapTester{}
2728
worked, err := cnfg.UnmarshalMap(pairs, &config)
2829

29-
assert.Nil(err)
30+
require.NoError(t, err)
3031
assert.True(worked)
3132
assert.EqualValues("bar", config.Foo)
3233

3334
worked, err = cnfg.UnmarshalMap(pairs, config)
3435

3536
assert.False(worked)
36-
assert.NotNil(err, "must have an error when attempting unmarshal to non-pointer")
37+
require.Error(t, err, "must have an error when attempting unmarshal to non-pointer")
3738

3839
worked, err = (&cnfg.ENV{}).UnmarshalMap(pairs, &config)
3940
assert.True(worked)
40-
assert.Nil(err)
41+
require.NoError(t, err)
4142
}
4243

4344
func ExampleUnmarshalMap() {

parse_test.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ import (
66
"testing"
77

88
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
910
)
1011

1112
func TestParseInt(t *testing.T) {
1213
t.Parallel()
1314

1415
assert := assert.New(t)
1516

16-
for _, t := range []interface{}{int(0), int8(8), int16(16), int32(32), int64(64)} {
17-
i, err := parseInt(t, fmt.Sprintf("%d", t))
17+
for _, val := range []interface{}{int(0), int8(8), int16(16), int32(32), int64(64)} {
18+
i, err := parseInt(val, fmt.Sprintf("%d", val))
1819

19-
assert.EqualValues(t, i)
20-
assert.NoError(err)
20+
require.NoError(t, err)
21+
assert.EqualValues(val, i)
2122
}
2223
}
2324

@@ -34,7 +35,7 @@ func TestParseByteSlice(t *testing.T) { //nolint:paralleltest
3435
ok, err := UnmarshalENV(testStruct, "D")
3536

3637
assert.True(ok)
37-
assert.NoError(err)
38+
require.NoError(t, err)
3839
assert.Equal("byte slice incoming", string(testStruct.F))
3940
}
4041

@@ -50,11 +51,10 @@ func TestParseUint(t *testing.T) {
5051
embeddedInt := &test{}
5152
theField := reflect.ValueOf(embeddedInt).Elem().Field(0)
5253

53-
for _, t := range []interface{}{uint(0), uint16(16), uint32(32), uint64(64)} {
54-
err := parseUint(theField, t, "1")
55-
54+
for _, val := range []interface{}{uint(0), uint16(16), uint32(32), uint64(64)} {
55+
err := parseUint(theField, val, "1")
56+
require.NoError(t, err)
5657
assert.EqualValues(1, embeddedInt.F)
57-
assert.NoError(err)
5858
}
5959

6060
type test2 struct {
@@ -65,14 +65,14 @@ func TestParseUint(t *testing.T) {
6565
theField = reflect.ValueOf(testStruct).Elem().Field(0)
6666

6767
err := parseUint(theField, uint8(0), "11")
68-
assert.NotNil(err, "must return an error when more than one byte is provided")
68+
require.Error(t, err, "must return an error when more than one byte is provided")
6969

7070
err = parseUint(theField, uint8(0), "f")
71-
assert.Nil(err, "must not return an error when only one byte is provided")
71+
require.NoError(t, err, "must not return an error when only one byte is provided")
7272
assert.Equal(byte('f'), testStruct.F)
7373

7474
err = parseUint(theField, uint8(0), "")
75-
assert.Nil(err, "must not return an error when only no bytes are provided")
75+
require.NoError(t, err, "must not return an error when only no bytes are provided")
7676
assert.Equal(uint8(0), testStruct.F)
7777
}
7878

@@ -85,6 +85,6 @@ func TestParseInterfaceError(t *testing.T) {
8585
type F uint64
8686

8787
ok, err := (&parser{}).Interface(reflect.ValueOf(F(0)), "", "", false)
88+
require.NoError(t, err, "unaddressable value must return nil")
8889
assert.False(ok, "unaddressable value must return false")
89-
assert.Nil(err, "unaddressable value must return nil")
9090
}

0 commit comments

Comments
 (0)