55 lines
965 B
Go
55 lines
965 B
Go
package appmode_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.dwysokinski.me/twhelp/sessions/cmd/sessions/internal/appmode"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// t.Setenv cannot be used in parallel tests.
|
|
//
|
|
//nolint:tparallel
|
|
func TestParse(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
output string
|
|
err error
|
|
}{
|
|
{
|
|
name: "OK: default",
|
|
output: appmode.Development,
|
|
},
|
|
{
|
|
name: "OK: development",
|
|
input: "development",
|
|
output: appmode.Development,
|
|
},
|
|
{
|
|
name: "OK: production",
|
|
input: "production",
|
|
output: appmode.Production,
|
|
},
|
|
{
|
|
name: "ERR: unsupported app mode",
|
|
input: "production2",
|
|
err: appmode.ErrUnsupported,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if tt.input != "" {
|
|
t.Setenv("APP_MODE", tt.input)
|
|
}
|
|
|
|
res, err := appmode.Parse()
|
|
assert.ErrorIs(t, err, tt.err)
|
|
assert.Equal(t, tt.output, res)
|
|
})
|
|
}
|
|
}
|