Skip to content

Commit b762871

Browse files
authored
Dev -> master (#44)
* Fix linter warnings (#43)
1 parent 95dc06a commit b762871

7 files changed

+35
-5
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[![Go Report Card](https://goreportcard.com/badge/github.com/BoRuDar/configuration/v4)](https://goreportcard.com/report/github.com/BoRuDar/configuration/v4)
22
[![codecov](https://codecov.io/gh/BoRuDar/configuration/branch/master/graph/badge.svg)](https://codecov.io/gh/BoRuDar/configuration)
3+
[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/6295/badge)](https://www.bestpractices.dev/projects/6295)
34
[![GoDoc](https://godoc.org/github.com/BoRuDar/configuration?status.png)](https://godoc.org/github.com/BoRuDar/configuration/v4)
45
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)
5-
[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/6295/badge)](https://www.bestpractices.dev/projects/6295)
66

77

88
# Configuration
@@ -13,7 +13,7 @@ Available features:
1313
- setting values from command line *flags* - `NewFlagProvider(&cfg)`
1414
- setting values from a JSON *file* - `NewJSONFileProvider("./testdata/input.json")`
1515

16-
Supported types:
16+
## Supported types:
1717
- `string`, `*string`, `[]string`, `[]*string`
1818
- `bool`, `*bool`, `[]bool`, `[]*bool`
1919
- `int`, `int8`, `int16`, `int32`, `int64` + slices of these types
@@ -24,6 +24,7 @@ Supported types:
2424
- `*float32`, `*float64` + slices of these types
2525
- `time.Duration` from strings like `12ms`, `2s` etc.
2626
- embedded structs and pointers to structs
27+
- any custom type which satisfies `FieldSetter` [interface](#FieldSetter-interface)
2728

2829

2930
# Why?

configurator_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"time"
88
)
99

10+
// nolint:paralleltest
11+
// t.Setenv doesn't work with t.Parallel()
1012
func TestConfigurator(t *testing.T) {
1113
// setting command line flag
1214
os.Args = []string{"smth", "-name=flag_value"}
@@ -83,6 +85,8 @@ func TestConfigurator(t *testing.T) {
8385
}
8486

8587
func TestConfigurator_Errors(t *testing.T) {
88+
t.Parallel()
89+
8690
tests := map[string]struct {
8791
input any
8892
providers []Provider
@@ -102,6 +106,8 @@ func TestConfigurator_Errors(t *testing.T) {
102106
for name, test := range tests {
103107
test := test
104108
t.Run(name, func(t *testing.T) {
109+
t.Parallel()
110+
105111
err := New(test.input, test.providers...).InitValues()
106112
if err == nil {
107113
t.Fatal("expected error but got nil")
@@ -111,6 +117,8 @@ func TestConfigurator_Errors(t *testing.T) {
111117
}
112118

113119
func TestEmbeddedFlags(t *testing.T) {
120+
t.Parallel()
121+
114122
type (
115123
Client struct {
116124
ServerAddress string `flag:"addr|127.0.0.1:443|server address"`
@@ -130,6 +138,7 @@ func TestEmbeddedFlags(t *testing.T) {
130138
assert(t, cfg.Client.ServerAddress, "addr_value")
131139
}
132140

141+
// nolint:paralleltest
133142
func TestFallBackToDefault(t *testing.T) {
134143
// defining a struct
135144
cfg := struct {
@@ -149,6 +158,8 @@ func TestFallBackToDefault(t *testing.T) {
149158
}
150159

151160
func TestSetOnFailFn(t *testing.T) {
161+
t.Parallel()
162+
152163
cfg := struct {
153164
Name string `default:"test_name"`
154165
}{}
@@ -172,6 +183,8 @@ func TestSetOnFailFn(t *testing.T) {
172183
}
173184

174185
func TestProviderName(t *testing.T) {
186+
t.Parallel()
187+
175188
testCases := map[string]struct {
176189
provider Provider
177190
expectedName string
@@ -198,21 +211,29 @@ func TestProviderName(t *testing.T) {
198211
test := test
199212

200213
t.Run(name, func(t *testing.T) {
214+
t.Parallel()
215+
201216
assert(t, test.expectedName, test.provider.Name())
202217
})
203218
}
204219
}
205220

206221
func TestConfigurator_NameCollision(t *testing.T) {
222+
t.Parallel()
223+
207224
err := New(&struct{}{}, NewDefaultProvider(), NewDefaultProvider()).InitValues()
208225
assert(t, ErrProviderNameCollision, err)
209226
}
210227

211228
func TestConfigurator_FailedProvider(t *testing.T) {
229+
t.Parallel()
230+
212231
err := New(&struct{}{}, NewJSONFileProvider("doesn't exist")).InitValues()
213232
assert(t, "cannot init [JSONFileProvider] provider: JSONFileProvider.Init: open doesn't exist: no such file or directory", err.Error())
214233
}
215234

235+
// nolint:paralleltest
236+
// t.Setenv doesn't work with t.Parallel()
216237
func Test_FromEnvAndDefault(t *testing.T) {
217238
t.Setenv("AGE", "24")
218239

defaultProvider_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
)
88

99
func TestDefaultProvider(t *testing.T) {
10+
t.Parallel()
11+
1012
type testStruct struct {
1113
Name string `default:"default_provider_val"`
1214
}
@@ -28,6 +30,8 @@ func TestDefaultProvider(t *testing.T) {
2830
}
2931

3032
func TestDefaultProviderPtr(t *testing.T) {
33+
t.Parallel()
34+
3135
type testStruct struct {
3236
Name *string `default:"default_provider_val_ptr"`
3337
}
@@ -49,6 +53,8 @@ func TestDefaultProviderPtr(t *testing.T) {
4953
}
5054

5155
func TestDefaultProviderFailed(t *testing.T) {
56+
t.Parallel()
57+
5258
type testStruct struct {
5359
Name string
5460
}

envProvider_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// nolint:dupl
1+
// nolint:dupl,paralleltest
22
package configuration
33

44
import (

fieldStetter_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ func TestSetPtrValue_Floats(t *testing.T) {
275275
}
276276

277277
func TestSetPtrValue_Bool(t *testing.T) {
278+
t.Parallel()
279+
278280
var testBool *bool
279281
fieldType := reflect.TypeOf(&testBool).Elem()
280282
fieldVal := reflect.ValueOf(&testBool).Elem()

flagProvider_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// nolint:dupl,goconst
1+
// nolint:dupl,goconst,paralleltest
22
package configuration
33

44
import (
@@ -210,7 +210,6 @@ func TestFlagProvider_Errors(t *testing.T) {
210210

211211
for name, test := range testCases {
212212
test := test
213-
214213
t.Run(name, func(t *testing.T) {
215214
fieldType := reflect.TypeOf(test.obj).Elem().Field(0)
216215
fieldVal := reflect.ValueOf(test.obj).Elem().Field(0)

jsonProvider_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// nolint:paralleltest
12
package configuration
23

34
import (

0 commit comments

Comments
 (0)