This commit is contained in:
10
go.mod
10
go.mod
@@ -1,13 +1,3 @@
|
||||
module gitoa.ru/go-4devs/config
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/stretchr/testify v1.7.0
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||
)
|
||||
|
||||
19
go.sum
19
go.sum
@@ -1,19 +0,0 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"gitoa.ru/go-4devs/config"
|
||||
"gitoa.ru/go-4devs/config/provider/watcher"
|
||||
"gitoa.ru/go-4devs/config/test/require"
|
||||
"gitoa.ru/go-4devs/config/value"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,14 +2,12 @@ package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"gitoa.ru/go-4devs/config"
|
||||
"gitoa.ru/go-4devs/config/test/require"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -21,17 +19,17 @@ const (
|
||||
func Run(t *testing.T, provider config.Provider, read []Read) {
|
||||
t.Helper()
|
||||
|
||||
prov := &ProviderSuite{
|
||||
provider: provider,
|
||||
read: read,
|
||||
}
|
||||
suite.Run(t, prov)
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
for idx, read := range read {
|
||||
t.Run(fmt.Sprintf("%v:%v", idx, read.Key), func(t *testing.T) {
|
||||
val, err := provider.Value(ctx, read.Key...)
|
||||
require.NoError(t, err, read.Key)
|
||||
read.Assert(t, val)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
type ProviderSuite struct {
|
||||
suite.Suite
|
||||
provider config.Provider
|
||||
read []Read
|
||||
}
|
||||
|
||||
type Read struct {
|
||||
@@ -110,7 +108,7 @@ func NewRead(expected interface{}, key ...string) Read {
|
||||
val, err = v.ParseTime()
|
||||
short = v.Time()
|
||||
default:
|
||||
require.Fail(t, "unexpected type", "type:%+T", expected)
|
||||
require.Fail(t, "unexpected type:%+T", expected)
|
||||
}
|
||||
|
||||
require.Equalf(t, val, short, "type:%T", expected)
|
||||
@@ -119,22 +117,3 @@ func NewRead(expected interface{}, key ...string) Read {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (ps *ProviderSuite) TestReadKeys() {
|
||||
ctx := context.Background()
|
||||
|
||||
for _, read := range ps.read {
|
||||
val, err := ps.provider.Value(ctx, read.Key...)
|
||||
require.NoError(ps.T(), err, read.Key)
|
||||
read.Assert(ps.T(), val)
|
||||
}
|
||||
}
|
||||
|
||||
func LoadConfig(t *testing.T, path string) []byte {
|
||||
t.Helper()
|
||||
|
||||
file, err := ioutil.ReadFile(filepath.Clean(path))
|
||||
require.NoError(t, err)
|
||||
|
||||
return file
|
||||
}
|
||||
|
||||
28
test/require/equal.go
Normal file
28
test/require/equal.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package require
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Equal(t *testing.T, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
|
||||
t.Helper()
|
||||
|
||||
if reflect.DeepEqual(expected, actual) {
|
||||
return
|
||||
}
|
||||
|
||||
t.Error(msgAndArgs...)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
func Equalf(t *testing.T, expected interface{}, actual interface{}, msg string, args ...interface{}) {
|
||||
t.Helper()
|
||||
|
||||
if reflect.DeepEqual(expected, actual) {
|
||||
return
|
||||
}
|
||||
|
||||
t.Errorf(msg, args...)
|
||||
t.FailNow()
|
||||
}
|
||||
23
test/require/error.go
Normal file
23
test/require/error.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package require
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func NoError(t *testing.T, err error, msgAndArgs ...interface{}) {
|
||||
t.Helper()
|
||||
|
||||
if err != nil {
|
||||
t.Error(msgAndArgs...)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func NoErrorf(t *testing.T, err error, msg string, args ...interface{}) {
|
||||
t.Helper()
|
||||
|
||||
if err != nil {
|
||||
t.Errorf(msg, args...)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
9
test/require/fail.go
Normal file
9
test/require/fail.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package require
|
||||
|
||||
import "testing"
|
||||
|
||||
func Fail(t *testing.T, msg string, args ...interface{}) {
|
||||
t.Helper()
|
||||
t.Errorf(msg, args...)
|
||||
t.FailNow()
|
||||
}
|
||||
14
test/require/true.go
Normal file
14
test/require/true.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package require
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Truef(t *testing.T, value bool, msg string, args ...interface{}) {
|
||||
t.Helper()
|
||||
|
||||
if !value {
|
||||
t.Errorf(msg, args...)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"gitoa.ru/go-4devs/config"
|
||||
"gitoa.ru/go-4devs/config/test/require"
|
||||
"gitoa.ru/go-4devs/config/value"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user