This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/internal/config/config_test.go
Jens Langhammer 55739ee982 internal: add additional error handling in config loader
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
2022-07-26 11:48:57 +02:00

49 lines
912 B
Go

package config
import (
"fmt"
"log"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestConfigEnv(t *testing.T) {
os.Setenv("AUTHENTIK_SECRET_KEY", "bar")
cfg = nil
if err := Get().fromEnv(); err != nil {
panic(err)
}
assert.Equal(t, "bar", Get().SecretKey)
}
func TestConfigEnv_Scheme(t *testing.T) {
os.Setenv("foo", "bar")
os.Setenv("AUTHENTIK_SECRET_KEY", "env://foo")
cfg = nil
if err := Get().fromEnv(); err != nil {
panic(err)
}
assert.Equal(t, "bar", Get().SecretKey)
}
func TestConfigEnv_File(t *testing.T) {
file, err := os.CreateTemp("", "")
if err != nil {
log.Fatal(err)
}
defer os.Remove(file.Name())
_, err = file.Write([]byte("bar"))
if err != nil {
panic(err)
}
os.Setenv("AUTHENTIK_SECRET_KEY", fmt.Sprintf("file://%s", file.Name()))
cfg = nil
if err := Get().fromEnv(); err != nil {
panic(err)
}
assert.Equal(t, "bar", Get().SecretKey)
}