Add some tests for config update from env
This commit is contained in:
parent
94b5b45396
commit
84fc2d6667
@ -88,8 +88,13 @@ func FromDefault() *Config {
|
||||
HTTP: &ServerHTTPConfig{
|
||||
ListenAddr: ":8089",
|
||||
},
|
||||
DataStoreConfig: &ServerDataStoreConfig{},
|
||||
FileStoreConfig: &ServerFileStoreConfig{},
|
||||
DataStoreConfig: &ServerDataStoreConfig{
|
||||
BoltStoreConfig: &BoltStoreConfig{},
|
||||
},
|
||||
FileStoreConfig: &ServerFileStoreConfig{
|
||||
BoltStoreConfig: &BoltStoreConfig{},
|
||||
FSStoreConfig: &FSStoreConfig{},
|
||||
},
|
||||
},
|
||||
Client: &ClientConfig{
|
||||
Certs: &CertificatePaths{},
|
||||
|
@ -1,6 +1,7 @@
|
||||
package config_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@ -206,4 +207,55 @@ func TestConfig(t *testing.T) {
|
||||
})
|
||||
}
|
||||
})
|
||||
t.Run("FromEnv", func(t *testing.T) {
|
||||
// Unset any existing ezshare env vars
|
||||
for _, env := range os.Environ() {
|
||||
if strings.HasPrefix(env, "EZSHARE") {
|
||||
os.Unsetenv(env)
|
||||
}
|
||||
}
|
||||
|
||||
cfg := config.FromDefault()
|
||||
// Test Server.LogLevel
|
||||
if cfg.Server.LogLevel == "WARN" {
|
||||
t.Errorf("Loglevel is WARN before updating from env.")
|
||||
}
|
||||
os.Setenv("EZSHARE_SERVER_LOGLEVEL", "WARN")
|
||||
if err := cfg.UpdateFromEnv(); err != nil {
|
||||
t.Fatalf("Error updating config from environment: %s", err)
|
||||
}
|
||||
if cfg.Server.LogLevel != "WARN" {
|
||||
t.Errorf("Loglevel is not WARN after updating from env.")
|
||||
}
|
||||
|
||||
// Test Server.Hostname
|
||||
hostname := "https://share.example.org"
|
||||
os.Setenv("EZSHARE_SERVER_HOSTNAME", hostname)
|
||||
if err := cfg.UpdateFromEnv(); err != nil {
|
||||
t.Fatalf("Error updating config from environment: %s", err)
|
||||
}
|
||||
if cfg.Server.Hostname != hostname {
|
||||
t.Errorf("Hostname is incorrect after updating from env.")
|
||||
}
|
||||
|
||||
// Test Server.Datastore.Bolt.Path
|
||||
boltPath := "/data/bolt.db"
|
||||
os.Setenv("EZSHARE_SERVER_DATASTORE_BOLT_PATH", boltPath)
|
||||
if err := cfg.UpdateFromEnv(); err != nil {
|
||||
t.Fatalf("Error updating config from environment: %s", err)
|
||||
}
|
||||
if cfg.Server.DataStoreConfig.BoltStoreConfig.Path != boltPath {
|
||||
t.Errorf("Bolt path is incorrect after updating from env.")
|
||||
}
|
||||
|
||||
// Test Server.Datastore.Bolt.Path
|
||||
caCertPath := "/data/cert.pem"
|
||||
os.Setenv("EZSHARE_SERVER_GRPC_CACERTS_CERTIFICATEKEYPATH", caCertPath)
|
||||
if err := cfg.UpdateFromEnv(); err != nil {
|
||||
t.Fatalf("Error updating config from environment: %s", err)
|
||||
}
|
||||
if cfg.Server.GRPC.CACerts.CertificateKeyPath != caCertPath {
|
||||
t.Errorf("GPRC CA Cert path is incorrect after updating from env.")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user