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