Skip to content

Commit

Permalink
Change to envconfig fork to enable lookups from map
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Balogh <[email protected]>
  • Loading branch information
javaducky authored and codebien committed Feb 9, 2023
1 parent 42c8df2 commit 46b84ad
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ go 1.18

require (
github.com/influxdata/influxdb-client-go/v2 v2.5.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/mstoykov/envconfig v1.4.1-0.20220114105314-765c6d8c76f1
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.0
go.k6.io/k6 v0.41.0
go.k6.io/k6 v0.42.0
gopkg.in/guregu/null.v3 v3.3.0
)

Expand Down
11 changes: 5 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/klauspost/compress v1.15.11 h1:Lcadnb3RKGin4FYM/orgq0qde+nc15E5Cbqg4B9Sx9c=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand Down Expand Up @@ -58,6 +56,7 @@ github.com/mccutchen/go-httpbin v1.1.2-0.20190116014521-c5cb2f4802fa h1:lx8ZnNPw
github.com/mstoykov/atlas v0.0.0-20220808085829-90340e9998bd h1:x/wQ8/umYu2x0icx5wNNTSK1NlkYVmsgzQ+U6v4ijv0=
github.com/mstoykov/atlas v0.0.0-20220808085829-90340e9998bd/go.mod h1:9vRHVuLCjoFfE3GT06X0spdOAO+Zzo4AMjdIwUHBvAk=
github.com/mstoykov/envconfig v1.4.1-0.20220114105314-765c6d8c76f1 h1:94EkGmhXrVUEal+uLwFUf4fMXPhZpM5tYxuIsxrCCbI=
github.com/mstoykov/envconfig v1.4.1-0.20220114105314-765c6d8c76f1/go.mod h1:vk/d9jpexY2Z9Bb0uB4Ndesss1Sr0Z9ZiGUrg5o9VGk=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand All @@ -83,8 +82,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
go.k6.io/k6 v0.41.0 h1:w/J10BV3MGahDF3UsT3WESNBCpsw7soxj9GaLCGTf4I=
go.k6.io/k6 v0.41.0/go.mod h1:ZrgrR06UZbzZt9u+so/yQhlkJFH5gkJ3qCp1hwq1mEU=
go.k6.io/k6 v0.42.0 h1:TXYyaNPI5GuX2k+r0EDqawdAkdU2Kuxl68GpBbwSkUk=
go.k6.io/k6 v0.42.0/go.mod h1:BY6vVmsNSaetHmPqQ8D6VMJJRptzwevdSpURQmSkrMQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand Down Expand Up @@ -127,9 +126,9 @@ golang.org/x/time v0.0.0-20220922220347-f3bd1da661af/go.mod h1:tRJNPiyCQ0inRvYxb
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08 h1:pc16UedxnxXXtGxHCSUhafAoVHQZ0yXl8ZelMH4EETc=
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 h1:hrbNEivu7Zn1pxvHk6MBrq9iE22woVILTHqexqBxe6I=
google.golang.org/grpc v1.49.0 h1:WTLtQzmQori5FUH25Pq4WT22oCsv8USpQ+F6rqtsmxw=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down
8 changes: 5 additions & 3 deletions pkg/influxdb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/kelseyhightower/envconfig"
"github.com/mstoykov/envconfig"
"go.k6.io/k6/lib/types"
"gopkg.in/guregu/null.v3"
)
Expand Down Expand Up @@ -105,8 +105,10 @@ func GetConsolidatedConfig(
}

envConfig := Config{}
if err := envconfig.Process("", &envConfig); err != nil {
// TODO: get rid of envconfig and actually use the env parameter...
if err := envconfig.Process("", &envConfig, func(key string) (string, bool) {
v, ok := env[key]
return v, ok
}); err != nil {
return result, err
}
result = result.Apply(envConfig)
Expand Down
32 changes: 32 additions & 0 deletions pkg/influxdb/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package influxdb

import (
"testing"
"time"

"go.k6.io/k6/lib/types"

"github.com/stretchr/testify/assert"
"gopkg.in/guregu/null.v3"
Expand All @@ -27,3 +30,32 @@ func TestParseURL(t *testing.T) {
})
}
}

func TestGetConsolidatedConfig(t *testing.T) {
t.Parallel()
duration999s, _ := time.ParseDuration("999s")
testdata := map[string]string{
"K6_INFLUXDB_ADDR": "http://test-url",
"K6_INFLUXDB_ORGANIZATION": "test-org",
"K6_INFLUXDB_BUCKET": "test-bucket",
"K6_INFLUXDB_TOKEN": "test-token",
"K6_INFLUXDB_INSECURE": "true",
"K6_INFLUXDB_PUSH_INTERVAL": duration999s.String(),
"K6_INFLUXDB_CONCURRENT_WRITES": "999",
"K6_INFLUXDB_PRECISION": duration999s.String(),
"K6_INFLUXDB_TAGS_AS_FIELDS": "test-tag-1,test-tag-2,test-tag-3",
}

check, err := GetConsolidatedConfig(nil, testdata, "http://test-url-override/test-bucket-override")
assert.NoError(t, err)

assert.Equal(t, null.StringFrom("http://test-url-override"), check.Addr)
assert.Equal(t, null.StringFrom("test-org"), check.Organization)
assert.Equal(t, null.StringFrom("test-bucket-override"), check.Bucket)
assert.Equal(t, null.StringFrom("test-token"), check.Token)
assert.Equal(t, null.BoolFrom(true), check.InsecureSkipTLSVerify)
assert.Equal(t, types.NullDurationFrom(duration999s), check.PushInterval)
assert.Equal(t, null.IntFrom(999), check.ConcurrentWrites)
assert.Equal(t, types.NullDurationFrom(duration999s), check.Precision)
assert.Equal(t, []string{"test-tag-1", "test-tag-2", "test-tag-3"}, check.TagsAsFields)
}

0 comments on commit 46b84ad

Please sign in to comment.