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 10b48b27b0 internal: walk config in go, check, parse and load from scheme like in python
closes #2719

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
2022-07-26 11:33:37 +02:00

40 lines
750 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
Get().fromEnv()
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
Get().fromEnv()
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())
file.Write([]byte("bar"))
os.Setenv("AUTHENTIK_SECRET_KEY", fmt.Sprintf("file://%s", file.Name()))
cfg = nil
Get().fromEnv()
assert.Equal(t, "bar", Get().SecretKey)
}