diff options
| author | Christine Dodrill <me@christine.website> | 2018-10-04 18:04:48 -0700 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2018-10-04 18:04:48 -0700 |
| commit | fbedf4acda9ff659a69fe577465db9617ec94ba1 (patch) | |
| tree | 74c0e72a1380a431813c78eb688b5b93db72800a /discord | |
| parent | 51b60f36ac286c973dd258571b77db24e9ace031 (diff) | |
| download | x-fbedf4acda9ff659a69fe577465db9617ec94ba1.tar.xz x-fbedf4acda9ff659a69fe577465db9617ec94ba1.zip | |
remove vendored dependencies for some things, vgo is coming
Diffstat (limited to 'discord')
32 files changed, 0 insertions, 3109 deletions
diff --git a/discord/pdevbitcoinbot/Gopkg.lock b/discord/pdevbitcoinbot/Gopkg.lock deleted file mode 100644 index c30a77f..0000000 --- a/discord/pdevbitcoinbot/Gopkg.lock +++ /dev/null @@ -1,30 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - name = "github.com/caarlos0/env" - packages = ["."] - revision = "7cd7992b3bc86f920394f8de92c13900da1a46b7" - version = "v3.2.0" - -[[projects]] - branch = "master" - name = "github.com/codahale/hdrhistogram" - packages = ["."] - revision = "3a0bb77429bd3a61596f5e8a3172445844342120" - -[[projects]] - name = "github.com/joho/godotenv" - packages = [ - ".", - "autoload" - ] - revision = "a79fa1e548e2c689c241d10173efd51e5d689d5b" - version = "v1.2.0" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - inputs-digest = "ce13f8ee2ca2392356358cef4fbb7bf0e8361b29789607b061ba3b024d9cf493" - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/discord/pdevbitcoinbot/Gopkg.toml b/discord/pdevbitcoinbot/Gopkg.toml deleted file mode 100644 index 1fecccd..0000000 --- a/discord/pdevbitcoinbot/Gopkg.toml +++ /dev/null @@ -1,33 +0,0 @@ -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" - - -[[constraint]] - name = "github.com/caarlos0/env" - version = "3.2.0" - -[[constraint]] - branch = "master" - name = "github.com/codahale/hdrhistogram" - -[[constraint]] - name = "github.com/joho/godotenv" - version = "1.2.0" diff --git a/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/.gitignore b/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/.gitignore deleted file mode 100644 index 2d83068..0000000 --- a/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/.gitignore +++ /dev/null @@ -1 +0,0 @@ -coverage.out diff --git a/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/.hound.yml b/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/.hound.yml deleted file mode 100644 index e5c719d..0000000 --- a/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/.hound.yml +++ /dev/null @@ -1,2 +0,0 @@ -go: - enabled: true diff --git a/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/.travis.yml b/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/.travis.yml deleted file mode 100644 index 4ad7e69..0000000 --- a/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -language: go -go: - - 1.5 - - 1.6 - - 1.7 - - 1.8 - - tip -before_install: - - go get github.com/axw/gocov/gocov - - go get github.com/mattn/goveralls - - go get golang.org/x/tools/cmd/cover -script: - - go test -v -cover -race -coverprofile=coverage.out -after_script: - - go get github.com/mattn/goveralls - - goveralls -coverprofile=coverage.out -service=travis-ci -repotoken='eCcizKmTdSaJCz8Ih33WDppdqb9kioYwi' diff --git a/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/LICENSE.md b/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/LICENSE.md deleted file mode 100644 index b739867..0000000 --- a/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/LICENSE.md +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015-2016 Carlos Alexandro Becker - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/README.md b/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/README.md deleted file mode 100644 index f50c425..0000000 --- a/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/README.md +++ /dev/null @@ -1,114 +0,0 @@ -# env [](https://travis-ci.org/caarlos0/env) [](https://coveralls.io/github/caarlos0/env?branch=master) [](http://godoc.org/github.com/caarlos0/env) [](http://goreportcard.com/report/caarlos0/env) [](https://saythanks.io/to/caarlos0) - -A KISS way to deal with environment variables in Go. - -## Why - -At first, it was boring for me to write down an entire function just to -get some `var` from the environment and default to another in case it's missing. - -For that manner, I wrote a `GetOr` function in the -[go-idioms](https://github.com/caarlos0/go-idioms) project. - -Then, I got pissed about writing `os.Getenv`, `os.Setenv`, `os.Unsetenv`... -it kind of make more sense to me write it as `env.Get`, `env.Set`, `env.Unset`. -So I did. - -Then I got a better idea: to use `struct` tags to do all that work for me. - -## Example - -A very basic example (check the `examples` folder): - -```go -package main - -import ( - "fmt" - "time" - - "github.com/caarlos0/env" -) - -type config struct { - Home string `env:"HOME"` - Port int `env:"PORT" envDefault:"3000"` - IsProduction bool `env:"PRODUCTION"` - Hosts []string `env:"HOSTS" envSeparator:":"` - Duration time.Duration `env:"DURATION"` -} - -func main() { - cfg := config{} - err := env.Parse(&cfg) - if err != nil { - fmt.Printf("%+v\n", err) - } - fmt.Printf("%+v\n", cfg) -} -``` - -You can run it like this: - -```sh -$ PRODUCTION=true HOSTS="host1:host2:host3" DURATION=1s go run examples/first.go -{Home:/your/home Port:3000 IsProduction:true Hosts:[host1 host2 host3] Duration:1s} -``` - -## Supported types and defaults - -The library has built-in support for the following types: - -* `string` -* `int` -* `uint` -* `int64` -* `bool` -* `float32` -* `float64` -* `[]string` -* `[]int` -* `[]bool` -* `[]float32` -* `[]float64` -* `time.Duration` -* .. or use/define a [custom parser func](#custom-parser-funcs) for any other type - -If you set the `envDefault` tag for something, this value will be used in the -case of absence of it in the environment. If you don't do that AND the -environment variable is also not set, the zero-value -of the type will be used: empty for `string`s, `false` for `bool`s -and `0` for `int`s. - -By default, slice types will split the environment value on `,`; you can change this behavior by setting the `envSeparator` tag. - -## Custom Parser Funcs - -If you have a type that is not supported out of the box by the lib, you are able -to use (or define) and pass custom parsers (and their associated `reflect.Type`) to the -`env.ParseWithFuncs()` function. - -In addition to accepting a struct pointer (same as `Parse()`), this function also -accepts a `env.CustomParsers` arg that under the covers is a `map[reflect.Type]env.ParserFunc`. - -To see what this looks like in practice, take a look at the [commented block in the example](https://github.com/caarlos0/env/blob/master/examples/first.go#L35-L39). - -`env` also ships with some pre-built custom parser funcs for common types. You -can check them out [here](parsers/). - -## Required fields - -The `env` tag option `required` (e.g., `env:"tagKey,required"`) can be added -to ensure that some environment variable is set. In the example above, -an error is returned if the `config` struct is changed to: - - -```go -type config struct { - Home string `env:"HOME"` - Port int `env:"PORT" envDefault:"3000"` - IsProduction bool `env:"PRODUCTION"` - Hosts []string `env:"HOSTS" envSeparator:":"` - SecretKey string `env:"SECRET_KEY,required"` -} -``` diff --git a/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/env.go b/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/env.go deleted file mode 100644 index 09747ce..0000000 --- a/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/env.go +++ /dev/null @@ -1,336 +0,0 @@ -package env - -import ( - "errors" - "fmt" - "os" - "reflect" - "strconv" - "strings" - "time" -) - -var ( - // ErrNotAStructPtr is returned if you pass something that is not a pointer to a - // Struct to Parse - ErrNotAStructPtr = errors.New("Expected a pointer to a Struct") - // ErrUnsupportedType if the struct field type is not supported by env - ErrUnsupportedType = errors.New("Type is not supported") - // ErrUnsupportedSliceType if the slice element type is not supported by env - ErrUnsupportedSliceType = errors.New("Unsupported slice type") - // Friendly names for reflect types - sliceOfInts = reflect.TypeOf([]int(nil)) - sliceOfInt64s = reflect.TypeOf([]int64(nil)) - sliceOfStrings = reflect.TypeOf([]string(nil)) - sliceOfBools = reflect.TypeOf([]bool(nil)) - sliceOfFloat32s = reflect.TypeOf([]float32(nil)) - sliceOfFloat64s = reflect.TypeOf([]float64(nil)) -) - -// CustomParsers is a friendly name for the type that `ParseWithFuncs()` accepts -type CustomParsers map[reflect.Type]ParserFunc - -// ParserFunc defines the signature of a function that can be used within `CustomParsers` -type ParserFunc func(v string) (interface{}, error) - -// Parse parses a struct containing `env` tags and loads its values from -// environment variables. -func Parse(v interface{}) error { - ptrRef := reflect.ValueOf(v) - if ptrRef.Kind() != reflect.Ptr { - return ErrNotAStructPtr - } - ref := ptrRef.Elem() - if ref.Kind() != reflect.Struct { - return ErrNotAStructPtr - } - return doParse(ref, make(map[reflect.Type]ParserFunc, 0)) -} - -// ParseWithFuncs is the same as `Parse` except it also allows the user to pass -// in custom parsers. -func ParseWithFuncs(v interface{}, funcMap CustomParsers) error { - ptrRef := reflect.ValueOf(v) - if ptrRef.Kind() != reflect.Ptr { - return ErrNotAStructPtr - } - ref := ptrRef.Elem() - if ref.Kind() != reflect.Struct { - return ErrNotAStructPtr - } - return doParse(ref, funcMap) -} - -func doParse(ref reflect.Value, funcMap CustomParsers) error { - refType := ref.Type() - var errorList []string - - for i := 0; i < refType.NumField(); i++ { - if reflect.Ptr == ref.Field(i).Kind() && !ref.Field(i).IsNil() && ref.Field(i).CanSet() { - err := Parse(ref.Field(i).Interface()) - if nil != err { - return err - } - continue - } - value, err := get(refType.Field(i)) - if err != nil { - errorList = append(errorList, err.Error()) - continue - } - if value == "" { - continue - } - if err := set(ref.Field(i), refType.Field(i), value, funcMap); err != nil { - errorList = append(errorList, err.Error()) - continue - } - } - if len(errorList) == 0 { - return nil - } - return errors.New(strings.Join(errorList, ". ")) -} - -func get(field reflect.StructField) (string, error) { - var ( - val string - err error - ) - - key, opts := parseKeyForOption(field.Tag.Get("env")) - - defaultValue := field.Tag.Get("envDefault") - val = getOr(key, defaultValue) - - if len(opts) > 0 { - for _, opt := range opts { - // The only option supported is "required". - switch opt { - case "": - break - case "required": - val, err = getRequired(key) - default: - err = errors.New("Env tag option " + opt + " not supported.") - } - } - } - - return val, err -} - -// split the env tag's key into the expected key and desired option, if any. -func parseKeyForOption(key string) (string, []string) { - opts := strings.Split(key, ",") - return opts[0], opts[1:] -} - -func getRequired(key string) (string, error) { - if value, ok := os.LookupEnv(key); ok { - return value, nil - } - // We do not use fmt.Errorf to avoid another import. - return "", errors.New("Required environment variable " + key + " is not set") -} - -func getOr(key, defaultValue string) string { - value, ok := os.LookupEnv(key) - if ok { - return value - } - return defaultValue -} - -func set(field reflect.Value, refType reflect.StructField, value string, funcMap CustomParsers) error { - switch field.Kind() { - case reflect.Slice: - separator := refType.Tag.Get("envSeparator") - return handleSlice(field, value, separator) - case reflect.String: - field.SetString(value) - case reflect.Bool: - bvalue, err := strconv.ParseBool(value) - if err != nil { - return err - } - field.SetBool(bvalue) - case reflect.Int: - intValue, err := strconv.ParseInt(value, 10, 32) - if err != nil { - return err - } - field.SetInt(intValue) - case reflect.Uint: - uintValue, err := strconv.ParseUint(value, 10, 32) - if err != nil { - return err - } - field.SetUint(uintValue) - case reflect.Float32: - v, err := strconv.ParseFloat(value, 32) - if err != nil { - return err - } - field.SetFloat(v) - case reflect.Float64: - v, err := strconv.ParseFloat(value, 64) - if err != nil { - return err - } - field.Set(reflect.ValueOf(v)) - case reflect.Int64: - if refType.Type.String() == "time.Duration" { - dValue, err := time.ParseDuration(value) - if err != nil { - return err - } - field.Set(reflect.ValueOf(dValue)) - } else { - intValue, err := strconv.ParseInt(value, 10, 64) - if err != nil { - return err - } - field.SetInt(intValue) - } - case reflect.Struct: - return handleStruct(field, refType, value, funcMap) - default: - return ErrUnsupportedType - } - return nil -} - -func handleStruct(field reflect.Value, refType reflect.StructField, value string, funcMap CustomParsers) error { - // Does the custom parser func map contain this type? - parserFunc, ok := funcMap[field.Type()] - if !ok { - // Map does not contain a custom parser for this type - return ErrUnsupportedType - } - - // Call on the custom parser func - data, err := parserFunc(value) - if err != nil { - return fmt.Errorf("Custom parser error: %v", err) - } - - // Set the field to the data returned by the customer parser func - rv := reflect.ValueOf(data) - field.Set(rv) - - return nil -} - -func handleSlice(field reflect.Value, value, separator string) error { - if separator == "" { - separator = "," - } - - splitData := strings.Split(value, separator) - - switch field.Type() { - case sliceOfStrings: - field.Set(reflect.ValueOf(splitData)) - case sliceOfInts: - intData, err := parseInts(splitData) - if err != nil { - return err - } - field.Set(reflect.ValueOf(intData)) - case sliceOfInt64s: - int64Data, err := parseInt64s(splitData) - if err != nil { - return err - } - field.Set(reflect.ValueOf(int64Data)) - - case sliceOfFloat32s: - data, err := parseFloat32s(splitData) - if err != nil { - return err - } - field.Set(reflect.ValueOf(data)) - case sliceOfFloat64s: - data, err := parseFloat64s(splitData) - if err != nil { - return err - } - field.Set(reflect.ValueOf(data)) - case sliceOfBools: - boolData, err := parseBools(splitData) - if err != nil { - return err - } - field.Set(reflect.ValueOf(boolData)) - default: - return ErrUnsupportedSliceType - } - return nil -} - -func parseInts(data []string) ([]int, error) { - var intSlice []int - - for _, v := range data { - intValue, err := strconv.ParseInt(v, 10, 32) - if err != nil { - return nil, err - } - intSlice = append(intSlice, int(intValue)) - } - return intSlice, nil -} - -func parseInt64s(data []string) ([]int64, error) { - var intSlice []int64 - - for _, v := range data { - intValue, err := strconv.ParseInt(v, 10, 64) - if err != nil { - return nil, err - } - intSlice = append(intSlice, int64(intValue)) - } - return intSlice, nil -} - -func parseFloat32s(data []string) ([]float32, error) { - var float32Slice []float32 - - for _, v := range data { - data, err := strconv.ParseFloat(v, 32) - if err != nil { - return nil, err - } - float32Slice = append(float32Slice, float32(data)) - } - return float32Slice, nil -} - -func parseFloat64s(data []string) ([]float64, error) { - var float64Slice []float64 - - for _, v := range data { - data, err := strconv.ParseFloat(v, 64) - if err != nil { - return nil, err - } - float64Slice = append(float64Slice, float64(data)) - } - return float64Slice, nil -} - -func parseBools(data []string) ([]bool, error) { - var boolSlice []bool - - for _, v := range data { - bvalue, err := strconv.ParseBool(v) - if err != nil { - return nil, err - } - - boolSlice = append(boolSlice, bvalue) - } - return boolSlice, nil -} diff --git a/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/env_test.go b/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/env_test.go deleted file mode 100644 index 7eae615..0000000 --- a/discord/pdevbitcoinbot/vendor/github.com/caarlos0/env/env_test.go +++ /dev/null @@ -1,372 +0,0 @@ -package env_test - -import ( - "errors" - "fmt" - "net/http" - "os" - "reflect" - "testing" - "time" - - "github.com/caarlos0/env" - "github.com/stretchr/testify/assert" -) - -type Config struct { - Some string `env:"somevar"` - Other bool `env:"othervar"` - Port int `env:"PORT"` - UintVal uint `env:"UINTVAL"` - NotAnEnv string - DatabaseURL string `env:"DATABASE_URL" envDefault:"postgres://localhost:5432/db"` - Strings []string `env:"STRINGS"` - SepStrings []string `env:"SEPSTRINGS" envSeparator:":"` - Numbers []int `env:"NUMBERS"` - Numbers64 []int64 `env:"NUMBERS64"` - Bools []bool `env:"BOOLS"` - Duration time.Duration `env:"DURATION"` - Float32 float32 `env:"FLOAT32"` - Float64 float64 `env:"FLOAT64"` - Float32s []float32 `env:"FLOAT32S"` - Float64s []float64 `env:"FLOAT64S"` -} - -type ParentStruct struct { - InnerStruct *InnerStruct - unexported *InnerStruct - Ignored *http.Client -} - -type InnerStruct struct { - Inner string `env:"innervar"` -} - -func TestParsesEnv(t *testing.T) { - os.Setenv("somevar", "somevalue") - os.Setenv("othervar", "true") - os.Setenv("PORT", "8080") - os.Setenv("STRINGS", "string1,string2,string3") - os.Setenv("SEPSTRINGS", "string1:string2:string3") - os.Setenv("NUMBERS", "1,2,3,4") - os.Setenv("NUMBERS64", "1,2,2147483640,-2147483640") - os.Setenv("BOOLS", "t,TRUE,0,1") - os.Setenv("DURATION", "1s") - os.Setenv("FLOAT32", "3.40282346638528859811704183484516925440e+38") - os.Setenv("FLOAT64", "1.797693134862315708145274237317043567981e+308") - os.Setenv("FLOAT32S", "1.0,2.0,3.0") - os.Setenv("FLOAT64S", "1.0,2.0,3.0") - os.Setenv("UINTVAL", "44") - - defer os.Clearenv() - - cfg := Config{} - assert.NoError(t, env.Parse(&cfg)) - assert.Equal(t, "somevalue", cfg.Some) - assert.Equal(t, true, cfg.Other) - assert.Equal(t, 8080, cfg.Port) - assert.Equal(t, uint(44), cfg.UintVal) - assert.Equal(t, []string{"string1", "string2", "string3"}, cfg.Strings) - assert.Equal(t, []string{"string1", "string2", "string3"}, cfg.SepStrings) - assert.Equal(t, []int{1, 2, 3, 4}, cfg.Numbers) - assert.Equal(t, []int64{1, 2, 2147483640, -2147483640}, cfg.Numbers64) - assert.Equal(t, []bool{true, true, false, true}, cfg.Bools) - d, _ := time.ParseDuration("1s") - assert.Equal(t, d, cfg.Duration) - f32 := float32(3.40282346638528859811704183484516925440e+38) - assert.Equal(t, f32, cfg.Float32) - f64 := float64(1.797693134862315708145274237317043567981e+308) - assert.Equal(t, f64, cfg.Float64) - assert.Equal(t, []float32{float32(1.0), float32(2.0), float32(3.0)}, cfg.Float32s) - assert.Equal(t, []float64{float64(1.0), float64(2.0), float64(3.0)}, cfg.Float64s) -} - -func TestParsesEnvInner(t *testing.T) { - os.Setenv("innervar", "someinnervalue") - defer os.Clearenv() - cfg := ParentStruct{ - InnerStruct: &InnerStruct{}, - unexported: &InnerStruct{}, - } - assert.NoError(t, env.Parse(&cfg)) - assert.Equal(t, "someinnervalue", cfg.InnerStruct.Inner) -} - -func TestParsesEnvInnerNil(t *testing.T) { - os.Setenv("innervar", "someinnervalue") - defer os.Clearenv() - cfg := ParentStruct{} - assert.NoError(t, env.Parse(&cfg)) -} - -func TestEmptyVars(t *testing.T) { - cfg := Config{} - assert.NoError(t, env.Parse(&cfg)) - assert.Equal(t, "", cfg.Some) - assert.Equal(t, false, cfg.Other) - assert.Equal(t, 0, cfg.Port) - assert.Equal(t, uint(0), cfg.UintVal) - assert.Equal(t, 0, len(cfg.Strings)) - assert.Equal(t, 0, len(cfg.SepStrings)) - assert.Equal(t, 0, len(cfg.Numbers)) - assert.Equal(t, 0, len(cfg.Bools)) -} - -func TestPassAnInvalidPtr(t *testing.T) { - var thisShouldBreak int - assert.Error(t, env.Parse(&thisShouldBreak)) -} - -func TestPassReference(t *testing.T) { - cfg := Config{} - assert.Error(t, env.Parse(cfg)) -} - -func TestInvalidBool(t *testing.T) { - os.Setenv("othervar", "should-be-a-bool") - defer os.Clearenv() - - cfg := Config{} - assert.Error(t, env.Parse(&cfg)) -} - -func TestInvalidInt(t *testing.T) { - os.Setenv("PORT", "should-be-an-int") - defer os.Clearenv() - - cfg := Config{} - assert.Error(t, env.Parse(&cfg)) -} - -func TestInvalidUint(t *testing.T) { - os.Setenv("UINTVAL", "-44") - defer os.Clearenv() - - cfg := Config{} - assert.Error(t, env.Parse(&cfg)) -} - -func TestInvalidBoolsSlice(t *testing.T) { - type config struct { - BadBools []bool `env:"BADBOOLS"` - } - - os.Setenv("BADBOOLS", "t,f,TRUE,faaaalse") - cfg := &config{} - assert.Error(t, env.Parse(cfg)) -} - -func TestInvalidDuration(t *testing.T) { - os.Setenv("DURATION", "should-be-a-valid-duration") - defer os.Clearenv() - - cfg := Config{} - assert.Error(t, env.Parse(&cfg)) -} - -func TestParsesDefaultConfig(t *testing.T) { - cfg := Config{} - assert.NoError(t, env.Parse(&cfg)) - assert.Equal(t, "postgres://localhost:5432/db", cfg.DatabaseURL) -} - -func TestParseStructWithoutEnvTag(t *testing.T) { - cfg := Config{} - assert.NoError(t, env.Parse(&cfg)) - assert.Empty(t, cfg.NotAnEnv) -} - -func TestParseStructWithInvalidFieldKind(t *testing.T) { - type config struct { - WontWorkByte byte `env:"BLAH"` - } - os.Setenv("BLAH", "a") - cfg := config{} - assert.Error(t, env.Parse(&cfg)) -} - -func TestUnsupportedSliceType(t *testing.T) { - type config struct { - WontWork []map[int]int `env:"WONTWORK"` - } - - os.Setenv("WONTWORK", "1,2,3") - defer os.Clearenv() - - cfg := &config{} - assert.Error(t, env.Parse(cfg)) -} - -func TestBadSeparator(t *testing.T) { - type config struct { - WontWork []int `env:"WONTWORK" envSeparator:":"` - } - - cfg := &config{} - os.Setenv("WONTWORK", "1,2,3,4") - defer os.Clearenv() - - assert.Error(t, env.Parse(cfg)) -} - |
