firestormy/config/config_test.go

58 lines
1012 B
Go
Executable File

package config
import (
"io/ioutil"
"os"
"testing"
)
func TestConfigRefresh(t *testing.T) {
was := os.Args
defer func() {
os.Args = was
}()
os.Args = []string{"na"}
d, err := ioutil.TempDir(os.TempDir(), "firestormy.config.test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(d)
os.Setenv("PORT", "11111")
os.Setenv("OAUTH", "localhost:27777")
os.Setenv("STORETYPE", "leveldb")
os.Setenv("STOREADDR", d)
os.Setenv("STOREUSER", "user")
os.Setenv("STOREPASS", "pass")
Refresh()
if v := Port; v != ":11111" {
t.Error(v)
}
if v := OAuthServer; v != "localhost:27777" {
t.Error(v)
}
if v := StoreType; v != "leveldb" {
t.Error(v)
}
if v := StoreAddr; v != d {
t.Error(v)
}
if v := StoreUser; v != "user" {
t.Error(v)
}
if v := StorePass; v != "pass" {
t.Error(v)
}
if err := Store.Set("key", []byte("value")); err != nil {
t.Error(err)
} else if b, err := Store.Get("key"); err != nil {
t.Error(err)
} else if string(b) != "value" {
t.Error(err)
}
}