✅ Test config
This commit is contained in:
parent
2b888f203d
commit
e441e541c7
5 changed files with 101 additions and 0 deletions
59
config/env_test.go
Normal file
59
config/env_test.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEnvString(t *testing.T) {
|
||||
cases := Envs[:]
|
||||
cases = append(cases, Env("foobar"), Env(""), Env("42"), Env("✨"))
|
||||
for _, e := range cases {
|
||||
t.Run(string(e), func(t *testing.T) {
|
||||
assert.Equal(t, string(e), e.String())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidEnv(t *testing.T) {
|
||||
cases := [...]struct {
|
||||
e Env
|
||||
exp bool
|
||||
}{
|
||||
{DEV, true},
|
||||
{PROD, true},
|
||||
{QA, true},
|
||||
{TEST, true},
|
||||
{Env("foobar"), false},
|
||||
{Env(""), false},
|
||||
{Env("✨"), false},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(string(c.e), func(t *testing.T) {
|
||||
assert.Equal(t, c.exp, ValidEnv(c.e))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidEnvOrDev(t *testing.T) {
|
||||
cases := [...]struct {
|
||||
give Env
|
||||
exp Env
|
||||
}{
|
||||
{DEV, DEV},
|
||||
{PROD, PROD},
|
||||
{QA, QA},
|
||||
{TEST, TEST},
|
||||
{Env("foobar"), DEV},
|
||||
{Env(""), DEV},
|
||||
{Env("✨"), DEV},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(string(c.give), func(t *testing.T) {
|
||||
assert.Equal(t, c.exp, ValidEnvOrDev(c.give))
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue