mirror of
https://github.com/status-im/fathom.git
synced 2025-03-01 11:30:28 +00:00
add tests for LoadEnv func
This commit is contained in:
parent
64b131f7f5
commit
a301dec1a3
@ -1,30 +1,52 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestLoadEnv(t *testing.T) {
|
||||||
|
before := len(os.Environ())
|
||||||
|
LoadEnv("")
|
||||||
|
LoadEnv("1230")
|
||||||
|
after := len(os.Environ())
|
||||||
|
|
||||||
|
if before != after {
|
||||||
|
t.Errorf("Expected the same number of env values")
|
||||||
|
}
|
||||||
|
|
||||||
|
data := []byte("FATHOM_DATABASE_DRIVER=\"sqlite3\"")
|
||||||
|
ioutil.WriteFile("env_values", data, 0644)
|
||||||
|
defer os.Remove("env_values")
|
||||||
|
|
||||||
|
LoadEnv("env_values")
|
||||||
|
|
||||||
|
got := os.Getenv("FATHOM_DATABASE_DRIVER")
|
||||||
|
if got != "sqlite3" {
|
||||||
|
t.Errorf("Expected %v, got %v", "sqlite3", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestParse(t *testing.T) {
|
func TestParse(t *testing.T) {
|
||||||
// empty config, should not fatal
|
// empty config, should not fatal
|
||||||
cfg := Parse("")
|
cfg := Parse()
|
||||||
if cfg.Secret == "" {
|
if cfg.Secret == "" {
|
||||||
t.Errorf("expected secret, got empty string")
|
t.Errorf("expected secret, got empty string")
|
||||||
}
|
}
|
||||||
|
|
||||||
secret := "my-super-secret-string"
|
secret := "my-super-secret-string"
|
||||||
os.Setenv("FATHOM_SECRET", secret)
|
os.Setenv("FATHOM_SECRET", secret)
|
||||||
cfg = Parse("")
|
cfg = Parse()
|
||||||
if cfg.Secret != secret {
|
if cfg.Secret != secret {
|
||||||
t.Errorf("Expected %#v, got %#v", secret, cfg.Secret)
|
t.Errorf("Expected %#v, got %#v", secret, cfg.Secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Setenv("FATHOM_DATABASE_DRIVER", "sqlite")
|
os.Setenv("FATHOM_DATABASE_DRIVER", "sqlite")
|
||||||
cfg = Parse("")
|
cfg = Parse()
|
||||||
if cfg.Database.Driver != "sqlite3" {
|
if cfg.Database.Driver != "sqlite3" {
|
||||||
t.Errorf("expected %#v, got %#v", "sqlite3", cfg.Database.Driver)
|
t.Errorf("expected %#v, got %#v", "sqlite3", cfg.Database.Driver)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRandomString(t *testing.T) {
|
func TestRandomString(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user