Switch to mirrorred images for Drone, make linters happy.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
0e795d5bc8
commit
090756ada8
@ -5,7 +5,7 @@ name: build
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: lint
|
- name: lint
|
||||||
image: golangci/golangci-lint:v1.43.0
|
image: code.pztrn.name/containers/mirror/golangci/golangci-lint:v1.46.2
|
||||||
environment:
|
environment:
|
||||||
GOFLAGS: -mod=vendor
|
GOFLAGS: -mod=vendor
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
@ -13,9 +13,8 @@ steps:
|
|||||||
- golangci-lint run
|
- golangci-lint run
|
||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
image: golang:1.17.3-alpine
|
image: code.pztrn.name/containers/mirror/golang:1.18.3-alpine
|
||||||
environment:
|
environment:
|
||||||
GOFLAGS: -mod=vendor
|
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
commands:
|
commands:
|
||||||
- go test ./...
|
- go test ./...
|
||||||
|
@ -7,6 +7,12 @@ linters:
|
|||||||
- gochecknoglobals
|
- gochecknoglobals
|
||||||
- exhaustive
|
- exhaustive
|
||||||
- testpackage
|
- testpackage
|
||||||
|
- cyclop
|
||||||
|
- varnamelen
|
||||||
|
- gomnd
|
||||||
|
- paralleltest
|
||||||
|
# Deprecated.
|
||||||
|
- exhaustivestruct
|
||||||
linters-settings:
|
linters-settings:
|
||||||
lll:
|
lll:
|
||||||
line-length: 120
|
line-length: 120
|
||||||
@ -17,4 +23,3 @@ linters-settings:
|
|||||||
funlen:
|
funlen:
|
||||||
lines: 200
|
lines: 200
|
||||||
statements: 100
|
statements: 100
|
||||||
|
|
||||||
|
7
field.go
7
field.go
@ -9,13 +9,10 @@ import (
|
|||||||
type field struct {
|
type field struct {
|
||||||
// Name is a field name. Mostly for debugging purpose.
|
// Name is a field name. Mostly for debugging purpose.
|
||||||
Name string
|
Name string
|
||||||
// Pointer is a pointer to field wrapped in reflect.Value.
|
|
||||||
Pointer reflect.Value
|
|
||||||
// EnvVar is a name of environment variable we will try to read.
|
// EnvVar is a name of environment variable we will try to read.
|
||||||
EnvVar string
|
EnvVar string
|
||||||
|
// Pointer is a pointer to field wrapped in reflect.Value.
|
||||||
|
Pointer reflect.Value
|
||||||
// Kind is a reflect.Kind value.
|
// Kind is a reflect.Kind value.
|
||||||
Kind reflect.Kind
|
Kind reflect.Kind
|
||||||
|
|
||||||
// Next variables are tag-related.
|
|
||||||
// optional bool
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// nolint:exhaustruct
|
||||||
package sec
|
package sec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -13,7 +14,7 @@ func TestParseString(t *testing.T) {
|
|||||||
StringData string
|
StringData string
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Setenv("STRINGDATA", "test")
|
t.Setenv("STRINGDATA", "test")
|
||||||
|
|
||||||
s := &testStruct{}
|
s := &testStruct{}
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ func TestParseBoolean(t *testing.T) {
|
|||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Logf("Testing: %+v", testCase)
|
t.Logf("Testing: %+v", testCase)
|
||||||
os.Setenv("BOOLDATA", testCase.TestData)
|
t.Setenv("BOOLDATA", testCase.TestData)
|
||||||
|
|
||||||
// If ErrorsAreCritical == false, then we should check only
|
// If ErrorsAreCritical == false, then we should check only
|
||||||
// equality of parsed data and valid data.
|
// equality of parsed data and valid data.
|
||||||
@ -111,7 +112,7 @@ func TestParseInt8(t *testing.T) {
|
|||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Logf("Testing: %+v", testCase)
|
t.Logf("Testing: %+v", testCase)
|
||||||
os.Setenv("INTDATA", testCase.TestData)
|
t.Setenv("INTDATA", testCase.TestData)
|
||||||
|
|
||||||
// If ErrorsAreCritical == false, then we should check only
|
// If ErrorsAreCritical == false, then we should check only
|
||||||
// equality of parsed data and valid data.
|
// equality of parsed data and valid data.
|
||||||
@ -185,7 +186,7 @@ func TestParseInt16(t *testing.T) {
|
|||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Logf("Testing: %+v", testCase)
|
t.Logf("Testing: %+v", testCase)
|
||||||
os.Setenv("INTDATA", testCase.TestData)
|
t.Setenv("INTDATA", testCase.TestData)
|
||||||
|
|
||||||
// If ErrorsAreCritical == false, then we should check only
|
// If ErrorsAreCritical == false, then we should check only
|
||||||
// equality of parsed data and valid data.
|
// equality of parsed data and valid data.
|
||||||
@ -259,7 +260,7 @@ func TestParseInt32(t *testing.T) {
|
|||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Logf("Testing: %+v", testCase)
|
t.Logf("Testing: %+v", testCase)
|
||||||
os.Setenv("INTDATA", testCase.TestData)
|
t.Setenv("INTDATA", testCase.TestData)
|
||||||
|
|
||||||
// If ErrorsAreCritical == false, then we should check only
|
// If ErrorsAreCritical == false, then we should check only
|
||||||
// equality of parsed data and valid data.
|
// equality of parsed data and valid data.
|
||||||
@ -333,7 +334,7 @@ func TestParseInt64(t *testing.T) {
|
|||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Logf("Testing: %+v", testCase)
|
t.Logf("Testing: %+v", testCase)
|
||||||
os.Setenv("INTDATA", testCase.TestData)
|
t.Setenv("INTDATA", testCase.TestData)
|
||||||
|
|
||||||
// If ErrorsAreCritical == false, then we should check only
|
// If ErrorsAreCritical == false, then we should check only
|
||||||
// equality of parsed data and valid data.
|
// equality of parsed data and valid data.
|
||||||
@ -406,7 +407,7 @@ func TestParseUint8(t *testing.T) {
|
|||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Logf("Testing: %+v", testCase)
|
t.Logf("Testing: %+v", testCase)
|
||||||
os.Setenv("UINTDATA", testCase.TestData)
|
t.Setenv("UINTDATA", testCase.TestData)
|
||||||
|
|
||||||
// If ErrorsAreCritical == false, then we should check only
|
// If ErrorsAreCritical == false, then we should check only
|
||||||
// equality of parsed data and valid data.
|
// equality of parsed data and valid data.
|
||||||
@ -479,7 +480,7 @@ func TestParseUint16(t *testing.T) {
|
|||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Logf("Testing: %+v", testCase)
|
t.Logf("Testing: %+v", testCase)
|
||||||
os.Setenv("UINTDATA", testCase.TestData)
|
t.Setenv("UINTDATA", testCase.TestData)
|
||||||
|
|
||||||
// If ErrorsAreCritical == false, then we should check only
|
// If ErrorsAreCritical == false, then we should check only
|
||||||
// equality of parsed data and valid data.
|
// equality of parsed data and valid data.
|
||||||
@ -552,7 +553,7 @@ func TestParseUint32(t *testing.T) {
|
|||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Logf("Testing: %+v", testCase)
|
t.Logf("Testing: %+v", testCase)
|
||||||
os.Setenv("UINTDATA", testCase.TestData)
|
t.Setenv("UINTDATA", testCase.TestData)
|
||||||
|
|
||||||
// If ErrorsAreCritical == false, then we should check only
|
// If ErrorsAreCritical == false, then we should check only
|
||||||
// equality of parsed data and valid data.
|
// equality of parsed data and valid data.
|
||||||
@ -625,7 +626,7 @@ func TestParseUint64(t *testing.T) {
|
|||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Logf("Testing: %+v", testCase)
|
t.Logf("Testing: %+v", testCase)
|
||||||
os.Setenv("UINTDATA", testCase.TestData)
|
t.Setenv("UINTDATA", testCase.TestData)
|
||||||
|
|
||||||
// If ErrorsAreCritical == false, then we should check only
|
// If ErrorsAreCritical == false, then we should check only
|
||||||
// equality of parsed data and valid data.
|
// equality of parsed data and valid data.
|
||||||
@ -697,7 +698,7 @@ func TestParseFloat32(t *testing.T) {
|
|||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Logf("Testing: %+v", testCase)
|
t.Logf("Testing: %+v", testCase)
|
||||||
os.Setenv("FLOATDATA", testCase.TestData)
|
t.Setenv("FLOATDATA", testCase.TestData)
|
||||||
|
|
||||||
// If ErrorsAreCritical == false, then we should check only
|
// If ErrorsAreCritical == false, then we should check only
|
||||||
// equality of parsed data and valid data.
|
// equality of parsed data and valid data.
|
||||||
@ -768,7 +769,7 @@ func TestParseFloat64(t *testing.T) {
|
|||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Logf("Testing: %+v", testCase)
|
t.Logf("Testing: %+v", testCase)
|
||||||
os.Setenv("FLOATDATA", testCase.TestData)
|
t.Setenv("FLOATDATA", testCase.TestData)
|
||||||
|
|
||||||
// If ErrorsAreCritical == false, then we should check only
|
// If ErrorsAreCritical == false, then we should check only
|
||||||
// equality of parsed data and valid data.
|
// equality of parsed data and valid data.
|
||||||
@ -826,12 +827,12 @@ func TestParseStructWithInterfaceFields(t *testing.T) {
|
|||||||
Data interface{}
|
Data interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Setenv(debugFlagEnvName, "true")
|
t.Setenv(debugFlagEnvName, "true")
|
||||||
|
|
||||||
testCase := &testStruct{}
|
testCase := &testStruct{}
|
||||||
testCase.Data = 0
|
testCase.Data = 0
|
||||||
|
|
||||||
os.Setenv("DATA", "64")
|
t.Setenv("DATA", "64")
|
||||||
|
|
||||||
err := Parse(testCase, nil)
|
err := Parse(testCase, nil)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@ -845,6 +846,7 @@ func TestParseStructWithInterfaceFields(t *testing.T) {
|
|||||||
|
|
||||||
err1 := Parse(testCase1, nil)
|
err1 := Parse(testCase1, nil)
|
||||||
require.Nil(t, err1)
|
require.Nil(t, err1)
|
||||||
|
// nolint:forcetypeassert
|
||||||
require.Equal(t, (*shouldBe), (*testCase1.Data.(*int)))
|
require.Equal(t, (*shouldBe), (*testCase1.Data.(*int)))
|
||||||
|
|
||||||
os.Unsetenv("DATA")
|
os.Unsetenv("DATA")
|
||||||
@ -861,9 +863,9 @@ func TestParseStructWitStructAsInterface(t *testing.T) {
|
|||||||
Data string
|
Data string
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Setenv(debugFlagEnvName, "true")
|
t.Setenv(debugFlagEnvName, "true")
|
||||||
os.Setenv("INT", "64")
|
t.Setenv("INT", "64")
|
||||||
os.Setenv("DATA_DATA", "Test data")
|
t.Setenv("DATA_DATA", "Test data")
|
||||||
|
|
||||||
testCase := &testStruct{}
|
testCase := &testStruct{}
|
||||||
testUnderlyingCase := &testUnderlyingStruct{}
|
testUnderlyingCase := &testUnderlyingStruct{}
|
||||||
@ -872,6 +874,7 @@ func TestParseStructWitStructAsInterface(t *testing.T) {
|
|||||||
|
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, testCase.Int, 64)
|
require.Equal(t, testCase.Int, 64)
|
||||||
|
// nolint:forcetypeassert
|
||||||
require.Equal(t, testCase.Data.(*testUnderlyingStruct).Data, "Test data")
|
require.Equal(t, testCase.Data.(*testUnderlyingStruct).Data, "Test data")
|
||||||
|
|
||||||
os.Unsetenv("INT")
|
os.Unsetenv("INT")
|
||||||
|
103
sec_test.go
103
sec_test.go
@ -1,3 +1,4 @@
|
|||||||
|
// nolint:exhaustruct
|
||||||
package sec
|
package sec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -24,74 +25,54 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type testDatas struct {
|
type testDatas struct {
|
||||||
|
TestString string
|
||||||
TestFloat64 float64
|
TestFloat64 float64
|
||||||
TestUint64 uint64
|
TestUint64 uint64
|
||||||
TestInt64 int64
|
TestInt64 int64
|
||||||
|
|
||||||
TestFloat32 float32
|
TestFloat32 float32
|
||||||
TestUint32 uint32
|
TestUint32 uint32
|
||||||
TestInt32 int32
|
TestInt32 int32
|
||||||
|
TestUint16 uint16
|
||||||
TestUint16 uint16
|
TestInt16 int16
|
||||||
TestInt16 int16
|
TestUint8 uint8
|
||||||
|
TestInt8 int8
|
||||||
TestUint8 uint8
|
TestBool bool
|
||||||
TestInt8 int8
|
|
||||||
|
|
||||||
TestBool bool
|
|
||||||
|
|
||||||
TestString string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// type testStringType string
|
|
||||||
|
|
||||||
type testStruct1 struct {
|
type testStruct1 struct {
|
||||||
testDatas
|
|
||||||
// testStringType
|
|
||||||
TestNestAnonymous struct {
|
|
||||||
TestFloat64 float64
|
|
||||||
TestUint64 uint64
|
|
||||||
TestInt64 int64
|
|
||||||
|
|
||||||
TestFloat32 float32
|
|
||||||
TestUint32 uint32
|
|
||||||
TestInt32 int32
|
|
||||||
|
|
||||||
TestUint16 uint16
|
|
||||||
TestInt16 int16
|
|
||||||
|
|
||||||
TestUint8 uint8
|
|
||||||
TestInt8 int8
|
|
||||||
|
|
||||||
TestBool bool
|
|
||||||
|
|
||||||
TestString string
|
|
||||||
}
|
|
||||||
TestNestAnonymousPointer *struct {
|
|
||||||
TestFloat64 float64
|
|
||||||
TestUint64 uint64
|
|
||||||
TestInt64 int64
|
|
||||||
|
|
||||||
TestFloat32 float32
|
|
||||||
TestUint32 uint32
|
|
||||||
TestInt32 int32
|
|
||||||
|
|
||||||
TestUint16 uint16
|
|
||||||
TestInt16 int16
|
|
||||||
|
|
||||||
TestUint8 uint8
|
|
||||||
TestInt8 int8
|
|
||||||
|
|
||||||
TestBool bool
|
|
||||||
|
|
||||||
TestString string
|
|
||||||
}
|
|
||||||
TestNestPointer *testDatas
|
|
||||||
TestNest testDatas
|
|
||||||
TestNestInterfacePointer interface{}
|
|
||||||
TestNestInterface interface{}
|
TestNestInterface interface{}
|
||||||
// testUnexported string
|
TestNestInterfacePointer interface{}
|
||||||
// testUnexportedNest *testDatas
|
TestNestAnonymousPointer *struct {
|
||||||
|
TestString string
|
||||||
|
TestFloat64 float64
|
||||||
|
TestUint64 uint64
|
||||||
|
TestInt64 int64
|
||||||
|
TestFloat32 float32
|
||||||
|
TestUint32 uint32
|
||||||
|
TestInt32 int32
|
||||||
|
TestUint16 uint16
|
||||||
|
TestInt16 int16
|
||||||
|
TestUint8 uint8
|
||||||
|
TestInt8 int8
|
||||||
|
TestBool bool
|
||||||
|
}
|
||||||
|
TestNestPointer *testDatas
|
||||||
|
TestNestAnonymous struct {
|
||||||
|
TestString string
|
||||||
|
TestFloat64 float64
|
||||||
|
TestUint64 uint64
|
||||||
|
TestInt64 int64
|
||||||
|
TestFloat32 float32
|
||||||
|
TestUint32 uint32
|
||||||
|
TestInt32 int32
|
||||||
|
TestUint16 uint16
|
||||||
|
TestInt16 int16
|
||||||
|
TestUint8 uint8
|
||||||
|
TestInt8 int8
|
||||||
|
TestBool bool
|
||||||
|
}
|
||||||
|
TestNest testDatas
|
||||||
|
testDatas
|
||||||
}
|
}
|
||||||
|
|
||||||
type testStructWithMap struct {
|
type testStructWithMap struct {
|
||||||
@ -209,7 +190,8 @@ func TestParseNotStructurePassed(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidDebugFlagValue(t *testing.T) {
|
func TestInvalidDebugFlagValue(t *testing.T) {
|
||||||
_ = os.Setenv(debugFlagEnvName, "INVALID")
|
t.Setenv(debugFlagEnvName, "INVALID")
|
||||||
|
|
||||||
c := &testStruct1{}
|
c := &testStruct1{}
|
||||||
err := Parse(c, nil)
|
err := Parse(c, nil)
|
||||||
|
|
||||||
@ -220,7 +202,8 @@ func TestInvalidDebugFlagValue(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidDebugFlagValueWithErrorsAreCritical(t *testing.T) {
|
func TestInvalidDebugFlagValueWithErrorsAreCritical(t *testing.T) {
|
||||||
_ = os.Setenv(debugFlagEnvName, "INVALID")
|
t.Setenv(debugFlagEnvName, "INVALID")
|
||||||
|
|
||||||
c := &testStruct1{}
|
c := &testStruct1{}
|
||||||
|
|
||||||
err := Parse(c, &Options{ErrorsAreCritical: true})
|
err := Parse(c, &Options{ErrorsAreCritical: true})
|
||||||
|
Loading…
Reference in New Issue
Block a user