2022-02-21 22:47:36 -08:00
|
|
|
package gosimpleconf
|
2022-02-21 22:26:38 -08:00
|
|
|
|
2022-11-09 00:16:36 -08:00
|
|
|
import "testing"
|
2022-02-21 22:26:38 -08:00
|
|
|
|
2022-11-09 00:16:36 -08:00
|
|
|
func TestConfigureWithDefaults(t *testing.T) {
|
|
|
|
defaultMap := ConfigMap{
|
|
|
|
"some": "thing",
|
|
|
|
"cool": "1337",
|
2022-06-18 12:44:10 -07:00
|
|
|
}
|
|
|
|
|
2022-11-09 00:16:36 -08:00
|
|
|
filename := "idontexist_123456789"
|
2022-06-18 12:44:10 -07:00
|
|
|
|
2022-11-09 00:16:36 -08:00
|
|
|
conf, err := ConfigureWithDefaults(filename, defaultMap)
|
2022-09-27 22:17:45 -07:00
|
|
|
if err != nil {
|
2022-11-09 00:16:36 -08:00
|
|
|
t.Errorf("unexpected error: %v", err)
|
2022-09-27 22:17:45 -07:00
|
|
|
}
|
|
|
|
|
2022-11-09 00:16:36 -08:00
|
|
|
validateMap(t, conf, defaultMap)
|
2022-09-27 22:17:45 -07:00
|
|
|
}
|
|
|
|
|
2022-11-09 00:16:36 -08:00
|
|
|
func TestConfigure(t *testing.T) {
|
|
|
|
filename := "test.conf"
|
|
|
|
expectedMap := ConfigMap{
|
|
|
|
"url": "www.wisellama.rocks",
|
|
|
|
"number_of_widgets": "1337",
|
|
|
|
"pi": "3.141592653589793238462643383",
|
|
|
|
"environment": "production",
|
|
|
|
"name": "Dude guy",
|
|
|
|
"description": "Just some dude it was",
|
|
|
|
"base64_tacos": "dGFjb3M=",
|
|
|
|
"a": "b=c",
|
2022-02-21 22:26:38 -08:00
|
|
|
}
|
|
|
|
|
2022-11-09 00:16:36 -08:00
|
|
|
conf, err := Configure(filename)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error: %v", err)
|
2022-02-21 22:26:38 -08:00
|
|
|
}
|
|
|
|
|
2022-11-09 00:16:36 -08:00
|
|
|
validateMap(t, conf, expectedMap)
|
2022-02-21 22:26:38 -08:00
|
|
|
}
|