diff --git a/cloudapi/api_test.go b/cloudapi/api_test.go index cf1c77c4314..ce8e7b61faf 100644 --- a/cloudapi/api_test.go +++ b/cloudapi/api_test.go @@ -25,7 +25,6 @@ import ( "io" "net/http" "net/http/httptest" - "os" "testing" "time" @@ -36,11 +35,6 @@ import ( "go.k6.io/k6/lib/types" ) -func init() { - _ = os.Setenv("K6CLOUD_HOST", "") - _ = os.Setenv("K6CLOUD_TOKEN", "") -} - func fprintf(t *testing.T, w io.Writer, format string, a ...interface{}) int { n, err := fmt.Fprintf(w, format, a...) require.NoError(t, err) @@ -48,6 +42,7 @@ func fprintf(t *testing.T, w io.Writer, format string, a ...interface{}) int { } func TestCreateTestRun(t *testing.T) { + t.Parallel() server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fprintf(t, w, `{"reference_id": "1", "config": {"aggregationPeriod": "2s"}}`) })) @@ -69,6 +64,7 @@ func TestCreateTestRun(t *testing.T) { } func TestFinished(t *testing.T) { + t.Parallel() server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fprintf(t, w, "") })) @@ -87,6 +83,7 @@ func TestFinished(t *testing.T) { } func TestAuthorizedError(t *testing.T) { + t.Parallel() called := 0 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { called++ @@ -105,6 +102,7 @@ func TestAuthorizedError(t *testing.T) { } func TestDetailsError(t *testing.T) { + t.Parallel() called := 0 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { called++ @@ -179,6 +177,7 @@ func TestClientRetrySuccessOnSecond(t *testing.T) { } func TestIdempotencyKey(t *testing.T) { + t.Parallel() const idempotencyKey = "xxx" server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { gotK6IdempotencyKey := r.Header.Get(k6IdempotencyKeyHeader) diff --git a/cloudapi/config.go b/cloudapi/config.go index 4bbccf07c72..ef3dd3d273a 100644 --- a/cloudapi/config.go +++ b/cloudapi/config.go @@ -26,7 +26,7 @@ import ( "gopkg.in/guregu/null.v3" - "github.com/kelseyhightower/envconfig" + "github.com/mstoykov/envconfig" "go.k6.io/k6/lib/types" ) @@ -296,7 +296,10 @@ func GetConsolidatedConfig( } envConfig := Config{} - if err := envconfig.Process("", &envConfig); err != nil { + if err := envconfig.Process("", &envConfig, func(key string) (string, bool) { + v, ok := env[key] + return v, ok + }); err != nil { // TODO: get rid of envconfig and actually use the env parameter... return result, err } diff --git a/cloudapi/config_test.go b/cloudapi/config_test.go index 30859276a1d..b735d6959aa 100644 --- a/cloudapi/config_test.go +++ b/cloudapi/config_test.go @@ -21,7 +21,6 @@ package cloudapi import ( "encoding/json" - "os" "testing" "time" @@ -33,6 +32,7 @@ import ( ) func TestConfigApply(t *testing.T) { + t.Parallel() empty := Config{} defaults := NewConfig() @@ -74,7 +74,8 @@ func TestConfigApply(t *testing.T) { assert.Equal(t, full, defaults.Apply(full)) } -func TestGetConsolidatedConfig(t *testing.T) { //nolint:paralleltest +func TestGetConsolidatedConfig(t *testing.T) { + t.Parallel() config, err := GetConsolidatedConfig(json.RawMessage(`{"token":"jsonraw"}`), nil, "", nil) require.NoError(t, err) require.Equal(t, config.Token.String, "jsonraw") @@ -84,9 +85,7 @@ func TestGetConsolidatedConfig(t *testing.T) { //nolint:paralleltest require.NoError(t, err) require.Equal(t, config.Token.String, "ext") - require.NoError(t, os.Setenv("K6_CLOUD_TOKEN", "envvalue")) // TODO drop when we don't use envconfig - defer os.Unsetenv("K6_CLOUD_TOKEN") //nolint:errcheck - config, err = GetConsolidatedConfig(json.RawMessage(`{"token":"jsonraw"}`), nil, "", + config, err = GetConsolidatedConfig(json.RawMessage(`{"token":"jsonraw"}`), map[string]string{"K6_CLOUD_TOKEN": "envvalue"}, "", map[string]json.RawMessage{"loadimpact": json.RawMessage(`{"token":"ext"}`)}) require.NoError(t, err) require.Equal(t, config.Token.String, "envvalue") diff --git a/cmd/archive.go b/cmd/archive.go index b4dcd3efec4..a83af6fcde9 100644 --- a/cmd/archive.go +++ b/cmd/archive.go @@ -71,7 +71,9 @@ An archive is a fully self-contained test run, and can be executed identically e if err != nil { return err } - conf, err := getConsolidatedConfig(afero.NewOsFs(), Config{Options: cliOpts}, r.GetOptions()) + conf, err := getConsolidatedConfig( + afero.NewOsFs(), Config{Options: cliOpts}, r.GetOptions(), buildEnvMap(os.Environ()), + ) if err != nil { return err } diff --git a/cmd/cloud.go b/cmd/cloud.go index 43d837a3421..0cf2a0b9f98 100644 --- a/cmd/cloud.go +++ b/cmd/cloud.go @@ -114,7 +114,8 @@ This will execute the test on the k6 cloud service. Use "k6 login cloud" to auth if err != nil { return err } - conf, err := getConsolidatedConfig(afero.NewOsFs(), Config{Options: cliOpts}, r.GetOptions()) + conf, err := getConsolidatedConfig( + afero.NewOsFs(), Config{Options: cliOpts}, r.GetOptions(), buildEnvMap(os.Environ())) if err != nil { return err } diff --git a/cmd/config.go b/cmd/config.go index dec047df182..666f2f124a2 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -28,7 +28,7 @@ import ( "path/filepath" "strings" - "github.com/kelseyhightower/envconfig" + "github.com/mstoykov/envconfig" "github.com/spf13/afero" "github.com/spf13/pflag" "gopkg.in/guregu/null.v3" @@ -156,10 +156,13 @@ func writeDiskConfig(fs afero.Fs, configPath string, conf Config) error { } // Reads configuration variables from the environment. -func readEnvConfig() (Config, error) { +func readEnvConfig(envMap map[string]string) (Config, error) { // TODO: replace envconfig and refactor the whole configuration from the ground up :/ conf := Config{} - err := envconfig.Process("", &conf) + err := envconfig.Process("", &conf, func(key string) (string, bool) { + v, ok := envMap[key] + return v, ok + }) return conf, err } @@ -172,14 +175,16 @@ func readEnvConfig() (Config, error) { // - set some defaults if they weren't previously specified // TODO: add better validation, more explicit default values and improve consistency between formats // TODO: accumulate all errors and differentiate between the layers? -func getConsolidatedConfig(fs afero.Fs, cliConf Config, runnerOpts lib.Options) (conf Config, err error) { +func getConsolidatedConfig( + fs afero.Fs, cliConf Config, runnerOpts lib.Options, envMap map[string]string, +) (conf Config, err error) { // TODO: use errext.WithExitCodeIfNone(err, exitcodes.InvalidConfig) where it makes sense? fileConf, _, err := readDiskConfig(fs) if err != nil { return conf, err } - envConf, err := readEnvConfig() + envConf, err := readEnvConfig(envMap) if err != nil { return conf, err } diff --git a/cmd/config_consolidation_test.go b/cmd/config_consolidation_test.go index 82837cc237d..05e90885fff 100644 --- a/cmd/config_consolidation_test.go +++ b/cmd/config_consolidation_test.go @@ -542,9 +542,6 @@ func runTestCase( logrus.SetOutput(output) logHook.Drain() - restoreEnv := testutils.SetEnv(t, testCase.options.env) - defer restoreEnv() - flagSet := newFlagSet() defer resetStickyGlobalVars() flagSet.SetOutput(output) @@ -582,7 +579,9 @@ func runTestCase( testCase.options.fs = afero.NewMemMapFs() // create an empty FS if it wasn't supplied } - consolidatedConfig, err := getConsolidatedConfig(testCase.options.fs, cliConf, runnerOpts) + consolidatedConfig, err := getConsolidatedConfig(testCase.options.fs, cliConf, runnerOpts, + // TODO: just make testcase.options.env in map[string]string + buildEnvMap(testCase.options.env)) if testCase.expected.consolidationError { require.Error(t, err) return diff --git a/cmd/config_test.go b/cmd/config_test.go index 4fdcd46e73e..4196a9417d7 100644 --- a/cmd/config_test.go +++ b/cmd/config_test.go @@ -21,11 +21,10 @@ package cmd import ( - "fmt" "testing" "time" - "github.com/kelseyhightower/envconfig" + "github.com/mstoykov/envconfig" "github.com/stretchr/testify/assert" "gopkg.in/guregu/null.v3" @@ -33,7 +32,6 @@ import ( "go.k6.io/k6/errext/exitcodes" "go.k6.io/k6/lib" "go.k6.io/k6/lib/executor" - "go.k6.io/k6/lib/testutils" "go.k6.io/k6/lib/types" ) @@ -93,8 +91,8 @@ func TestConfigCmd(t *testing.T) { } } -//nolint:paralleltest // this user testutils.SetEnv func TestConfigEnv(t *testing.T) { + t.Parallel() testdata := map[struct{ Name, Key string }]map[string]func(Config){ {"Linger", "K6_LINGER"}: { "": func(c Config) { assert.Equal(t, null.Bool{}, c.Linger) }, @@ -114,13 +112,18 @@ func TestConfigEnv(t *testing.T) { for field, data := range testdata { field, data := field, data t.Run(field.Name, func(t *testing.T) { + t.Parallel() for value, fn := range data { value, fn := value, fn t.Run(`"`+value+`"`, func(t *testing.T) { - restore := testutils.SetEnv(t, []string{fmt.Sprintf("%s=%s", field.Key, value)}) - defer restore() + t.Parallel() var config Config - assert.NoError(t, envconfig.Process("", &config)) + assert.NoError(t, envconfig.Process("", &config, func(key string) (string, bool) { + if key == field.Key { + return value, true + } + return "", false + })) fn(config) }) } diff --git a/cmd/inspect.go b/cmd/inspect.go index 19eee8406c2..431d0f6bfe2 100644 --- a/cmd/inspect.go +++ b/cmd/inspect.go @@ -119,7 +119,7 @@ func addExecRequirements(b *js.Bundle, return nil, err } - conf, err := getConsolidatedConfig(afero.NewOsFs(), Config{}, runner.GetOptions()) + conf, err := getConsolidatedConfig(afero.NewOsFs(), Config{}, runner.GetOptions(), buildEnvMap(os.Environ())) if err != nil { return nil, err } diff --git a/cmd/run.go b/cmd/run.go index fa18084db5f..7045d4b5016 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -123,7 +123,7 @@ a commandline interface for interacting with it.`, if err != nil { return err } - conf, err := getConsolidatedConfig(afero.NewOsFs(), cliConf, initRunner.GetOptions()) + conf, err := getConsolidatedConfig(afero.NewOsFs(), cliConf, initRunner.GetOptions(), buildEnvMap(os.Environ())) if err != nil { return err } diff --git a/go.mod b/go.mod index a5dc5d52095..d3f106065e7 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/gorilla/websocket v1.4.2 github.com/influxdata/influxdb1-client v0.0.0-20190402204710-8ff2fc3824fc github.com/jhump/protoreflect v1.10.0 - github.com/kelseyhightower/envconfig v1.4.0 github.com/klauspost/compress v1.13.6 github.com/mailru/easyjson v0.7.7 github.com/manyminds/api2go v0.0.0-20180125085803-95be7bd0455e @@ -50,6 +49,7 @@ require ( github.com/go-sourcemap/sourcemap v2.1.4-0.20211119122758-180fcef48034+incompatible // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/josharian/intern v1.0.0 // indirect + github.com/mstoykov/envconfig v1.4.1-0.20220114105314-765c6d8c76f1 github.com/onsi/ginkgo v1.14.0 // indirect github.com/onsi/gomega v1.10.1 // indirect github.com/tidwall/match v1.1.1 // indirect diff --git a/go.sum b/go.sum index a853557d922..ba48366a51d 100644 --- a/go.sum +++ b/go.sum @@ -160,8 +160,6 @@ github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= -github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= @@ -201,6 +199,8 @@ github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:F github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +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/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nishanths/predeclared v0.0.0-20200524104333-86fad755b4d3/go.mod h1:nt3d53pc1VYcphSCIaYAJtnPYnr3Zyn8fMq2wvPGPso= github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ= diff --git a/lib/options_test.go b/lib/options_test.go index 7987dc0377e..8f0cab3bf76 100644 --- a/lib/options_test.go +++ b/lib/options_test.go @@ -23,18 +23,16 @@ package lib import ( "crypto/tls" "encoding/json" - "fmt" "net" "reflect" "testing" "time" - "github.com/kelseyhightower/envconfig" + "github.com/mstoykov/envconfig" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gopkg.in/guregu/null.v3" - "go.k6.io/k6/lib/testutils" "go.k6.io/k6/lib/types" "go.k6.io/k6/stats" ) @@ -432,6 +430,7 @@ func TestOptions(t *testing.T) { } func TestOptionsEnv(t *testing.T) { + t.Parallel() mustIPPool := func(s string) *types.IPPool { p, err := types.NewIPPool(s) require.NoError(t, err) @@ -528,13 +527,18 @@ func TestOptionsEnv(t *testing.T) { for field, data := range testdata { field, data := field, data t.Run(field.Name, func(t *testing.T) { + t.Parallel() for str, val := range data { str, val := str, val t.Run(`"`+str+`"`, func(t *testing.T) { - restore := testutils.SetEnv(t, []string{fmt.Sprintf("%s=%s", field.Key, str)}) - defer restore() + t.Parallel() var opts Options - assert.NoError(t, envconfig.Process("k6", &opts)) + assert.NoError(t, envconfig.Process("k6", &opts, func(k string) (string, bool) { + if k == field.Key { + return str, true + } + return "", false + })) assert.Equal(t, val, reflect.ValueOf(opts).FieldByName(field.Name).Interface()) }) } diff --git a/lib/testutils/env.go b/lib/testutils/env.go deleted file mode 100644 index ea81c2dc523..00000000000 --- a/lib/testutils/env.go +++ /dev/null @@ -1,62 +0,0 @@ -/* - * - * k6 - a next-generation load testing tool - * Copyright (C) 2019 Load Impact - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -package testutils - -import ( - "os" - "strings" - "testing" - - "github.com/stretchr/testify/require" -) - -// SetEnv is a helper funcion for setting arbitrary environment variables and -// restoring the old ones at the end, usually by deferring the returned callback -// TODO: remove these hacks when we improve the configuration (hopefully -// completely, see https://github.com/k6io/k6/issues/883)... we shouldn't -// have to mess with the global environment at all... -func SetEnv(t *testing.T, newEnv []string) (restoreEnv func()) { - actuallSetEnv := func(env []string, abortOnSetErr bool) { - os.Clearenv() - for _, e := range env { - val := "" - pair := strings.SplitN(e, "=", 2) - if len(pair) > 1 { - val = pair[1] - } - err := os.Setenv(pair[0], val) - if abortOnSetErr { - require.NoError(t, err) - } else if err != nil { - t.Logf( - "Received a non-aborting but unexpected error '%s' when setting env.var '%s' to '%s'", - err, pair[0], val, - ) - } - } - } - oldEnv := os.Environ() - actuallSetEnv(newEnv, true) - - return func() { - actuallSetEnv(oldEnv, false) - } -} diff --git a/output/csv/config.go b/output/csv/config.go index 18e5011e211..8ab6f03d2e1 100644 --- a/output/csv/config.go +++ b/output/csv/config.go @@ -28,7 +28,7 @@ import ( "gopkg.in/guregu/null.v3" - "github.com/kelseyhightower/envconfig" + "github.com/mstoykov/envconfig" "github.com/sirupsen/logrus" "go.k6.io/k6/lib/types" ) @@ -112,7 +112,10 @@ func GetConsolidatedConfig( } envConfig := Config{} - if err := envconfig.Process("", &envConfig); err != nil { + if err := envconfig.Process("", &envConfig, func(key string) (string, bool) { + v, ok := env[key] + return v, ok + }); err != nil { // TODO: get rid of envconfig and actually use the env parameter... return result, err } diff --git a/output/influxdb/config.go b/output/influxdb/config.go index 37858b1b4bf..0186b4743d4 100644 --- a/output/influxdb/config.go +++ b/output/influxdb/config.go @@ -28,7 +28,7 @@ import ( "strings" "time" - "github.com/kelseyhightower/envconfig" + "github.com/mstoykov/envconfig" "gopkg.in/guregu/null.v3" "go.k6.io/k6/lib/types" @@ -199,7 +199,10 @@ func GetConsolidatedConfig(jsonRawConf json.RawMessage, env map[string]string, u } envConfig := Config{} - if err := envconfig.Process("", &envConfig); err != nil { + if err := envconfig.Process("", &envConfig, func(key string) (string, bool) { + v, ok := env[key] + return v, ok + }); err != nil { // TODO: get rid of envconfig and actually use the env parameter... return result, err } diff --git a/output/statsd/config.go b/output/statsd/config.go index c85195f16ef..e7f2a8b3bf1 100644 --- a/output/statsd/config.go +++ b/output/statsd/config.go @@ -24,7 +24,7 @@ import ( "encoding/json" "time" - "github.com/kelseyhightower/envconfig" + "github.com/mstoykov/envconfig" "gopkg.in/guregu/null.v3" "go.k6.io/k6/lib/types" @@ -101,7 +101,10 @@ func getConsolidatedConfig(jsonRawConf json.RawMessage, env map[string]string, _ envConfig := config{} _ = env // TODO: get rid of envconfig and actually use the env parameter... - if err := envconfig.Process("", &envConfig); err != nil { + 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) diff --git a/vendor/github.com/kelseyhightower/envconfig/LICENSE b/vendor/github.com/mstoykov/envconfig/LICENSE similarity index 100% rename from vendor/github.com/kelseyhightower/envconfig/LICENSE rename to vendor/github.com/mstoykov/envconfig/LICENSE diff --git a/vendor/github.com/kelseyhightower/envconfig/MAINTAINERS b/vendor/github.com/mstoykov/envconfig/MAINTAINERS similarity index 100% rename from vendor/github.com/kelseyhightower/envconfig/MAINTAINERS rename to vendor/github.com/mstoykov/envconfig/MAINTAINERS diff --git a/vendor/github.com/kelseyhightower/envconfig/README.md b/vendor/github.com/mstoykov/envconfig/README.md similarity index 82% rename from vendor/github.com/kelseyhightower/envconfig/README.md rename to vendor/github.com/mstoykov/envconfig/README.md index 33408d645e4..3446d2fecbb 100644 --- a/vendor/github.com/kelseyhightower/envconfig/README.md +++ b/vendor/github.com/mstoykov/envconfig/README.md @@ -188,5 +188,44 @@ type DNSConfig struct { } ``` +Example for decoding the environment variables into map[string][]structName type + +```Bash +export SMS_PROVIDER_WITH_WEIGHT= `IND=[{"name":"SMSProvider1","weight":70},{"name":"SMSProvider2","weight":30}];US=[{"name":"SMSProvider1","weight":100}]` +``` + +```GO +type providerDetails struct { + Name string + Weight int +} + +type SMSProviderDecoder map[string][]providerDetails + +func (sd *SMSProviderDecoder) Decode(value string) error { + smsProvider := map[string][]providerDetails{} + pairs := strings.Split(value, ";") + for _, pair := range pairs { + providerdata := []providerDetails{} + kvpair := strings.Split(pair, "=") + if len(kvpair) != 2 { + return fmt.Errorf("invalid map item: %q", pair) + } + err := json.Unmarshal([]byte(kvpair[1]), &providerdata) + if err != nil { + return fmt.Errorf("invalid map json: %w", err) + } + smsProvider[kvpair[0]] = providerdata + + } + *sd = SMSProviderDecoder(smsProvider) + return nil +} + +type SMSProviderConfig struct { + ProviderWithWeight SMSProviderDecoder `envconfig:"SMS_PROVIDER_WITH_WEIGHT"` +} +``` + Also, envconfig will use a `Set(string) error` method like from the [flag.Value](https://godoc.org/flag#Value) interface if implemented. diff --git a/vendor/github.com/kelseyhightower/envconfig/doc.go b/vendor/github.com/mstoykov/envconfig/doc.go similarity index 100% rename from vendor/github.com/kelseyhightower/envconfig/doc.go rename to vendor/github.com/mstoykov/envconfig/doc.go diff --git a/vendor/github.com/kelseyhightower/envconfig/env_os.go b/vendor/github.com/mstoykov/envconfig/env_os.go similarity index 100% rename from vendor/github.com/kelseyhightower/envconfig/env_os.go rename to vendor/github.com/mstoykov/envconfig/env_os.go diff --git a/vendor/github.com/kelseyhightower/envconfig/env_syscall.go b/vendor/github.com/mstoykov/envconfig/env_syscall.go similarity index 100% rename from vendor/github.com/kelseyhightower/envconfig/env_syscall.go rename to vendor/github.com/mstoykov/envconfig/env_syscall.go diff --git a/vendor/github.com/kelseyhightower/envconfig/envconfig.go b/vendor/github.com/mstoykov/envconfig/envconfig.go similarity index 96% rename from vendor/github.com/kelseyhightower/envconfig/envconfig.go rename to vendor/github.com/mstoykov/envconfig/envconfig.go index 3f16108db8a..b6bfcc788a8 100644 --- a/vendor/github.com/kelseyhightower/envconfig/envconfig.go +++ b/vendor/github.com/mstoykov/envconfig/envconfig.go @@ -19,8 +19,10 @@ import ( // ErrInvalidSpecification indicates that a specification is of the wrong type. var ErrInvalidSpecification = errors.New("specification must be a struct pointer") -var gatherRegexp = regexp.MustCompile("([^A-Z]+|[A-Z]+[^A-Z]+|[A-Z]+)") -var acronymRegexp = regexp.MustCompile("([A-Z]+)([A-Z][^A-Z]+)") +var ( + gatherRegexp = regexp.MustCompile("([^A-Z]+|[A-Z]+[^A-Z]+|[A-Z]+)") + acronymRegexp = regexp.MustCompile("([A-Z]+)([A-Z][^A-Z]+)") +) // A ParseError occurs when an environment variable cannot be converted to // the type required by a struct field during assignment. @@ -181,7 +183,11 @@ func CheckDisallowed(prefix string, spec interface{}) error { } // Process populates the specified struct based on environment variables -func Process(prefix string, spec interface{}) error { +func Process(prefix string, spec interface{}, args ...func(string) (string, bool)) error { + lookupEnvF := lookupEnv + if len(args) == 1 { + lookupEnvF = args[0] + } infos, err := gatherInfo(prefix, spec) for _, info := range infos { @@ -190,9 +196,9 @@ func Process(prefix string, spec interface{}) error { // and an unset value. `os.LookupEnv` is preferred to `syscall.Getenv`, // but it is only available in go1.5 or newer. We're using Go build tags // here to use os.LookupEnv for >=go1.5 - value, ok := lookupEnv(info.Key) + value, ok := lookupEnvF(info.Key) if !ok && info.Alt != "" { - value, ok = lookupEnv(info.Alt) + value, ok = lookupEnvF(info.Alt) } def := info.Tags.Get("default") diff --git a/vendor/github.com/kelseyhightower/envconfig/usage.go b/vendor/github.com/mstoykov/envconfig/usage.go similarity index 99% rename from vendor/github.com/kelseyhightower/envconfig/usage.go rename to vendor/github.com/mstoykov/envconfig/usage.go index 1e6d0a8f367..aebadb0353b 100644 --- a/vendor/github.com/kelseyhightower/envconfig/usage.go +++ b/vendor/github.com/mstoykov/envconfig/usage.go @@ -120,7 +120,7 @@ func Usage(prefix string, spec interface{}) error { return err } -// Usagef writes usage information to the specified io.Writer using the specifed template specification +// Usagef writes usage information to the specified io.Writer using the specified template specification func Usagef(prefix string, spec interface{}, out io.Writer, format string) error { // Specify the default usage template functions diff --git a/vendor/modules.txt b/vendor/modules.txt index adadcbb4fbc..e71ce845c47 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -80,9 +80,6 @@ github.com/jhump/protoreflect/internal/codec # github.com/josharian/intern v1.0.0 ## explicit; go 1.5 github.com/josharian/intern -# github.com/kelseyhightower/envconfig v1.4.0 -## explicit -github.com/kelseyhightower/envconfig # github.com/klauspost/compress v1.13.6 ## explicit; go 1.15 github.com/klauspost/compress @@ -111,6 +108,9 @@ github.com/mattn/go-isatty github.com/mccutchen/go-httpbin/httpbin github.com/mccutchen/go-httpbin/httpbin/assets github.com/mccutchen/go-httpbin/httpbin/digest +# github.com/mstoykov/envconfig v1.4.1-0.20220114105314-765c6d8c76f1 +## explicit +github.com/mstoykov/envconfig # github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d ## explicit github.com/nu7hatch/gouuid