forked from git.klmp200.net/ALFRED
Tests for settings
This commit is contained in:
parent
2c34fbefe2
commit
2cd142844d
4 changed files with 48 additions and 8 deletions
|
@ -2,7 +2,7 @@
|
|||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-23 15:24:30
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-23 16:02:42
|
||||
* @Last Modified time: 2018-07-23 19:14:44
|
||||
*/
|
||||
|
||||
package settings
|
||||
|
@ -27,18 +27,20 @@ func loadJson(path string) error {
|
|||
}
|
||||
|
||||
// Load settings from given files paths
|
||||
// Default settings are mandatory and program crash if there is an error at importation
|
||||
// Default settings are mandatory and program should crash if there is an error at importation
|
||||
// Custom settings are skipped if malformed or not found
|
||||
func LoadSettings(settings_default_path, settings_custom_path string) {
|
||||
func LoadSettings(settings_default_path, settings_custom_path string) error {
|
||||
log.Println("Loading settings")
|
||||
Settings = make(map[string]interface{})
|
||||
if err := loadJson(settings_default_path); err != nil {
|
||||
log.Println("error importing default settings")
|
||||
log.Fatal(err)
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
if err := loadJson(settings_custom_path); err != nil {
|
||||
log.Println("error importing custom settings, skipping")
|
||||
log.Println(err)
|
||||
}
|
||||
log.Println("Settings loaded")
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2,7 +2,44 @@
|
|||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-23 16:08:28
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-23 16:08:37
|
||||
* @Last Modified time: 2018-07-23 19:23:49
|
||||
*/
|
||||
|
||||
package settings
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoadSettings(t *testing.T) {
|
||||
if LoadSettings("", "") == nil {
|
||||
t.Error("no error for inexstant main settings file")
|
||||
}
|
||||
if LoadSettings("../settings.json", "") != nil {
|
||||
t.Error("error for existant and well formated main settings file")
|
||||
}
|
||||
if LoadSettings("../settings.json", "settings.go") != nil {
|
||||
t.Error("error for malformed custom settings json, should have ignored")
|
||||
}
|
||||
if LoadSettings("../settings.json", "../settings.json") != nil {
|
||||
t.Error("error but everything should be fine")
|
||||
}
|
||||
if token, ok := Settings["token"]; !ok {
|
||||
t.Error("token not loaded")
|
||||
} else if token != "INSERT TOKEN HERE" {
|
||||
t.Error("token is not \"INSERT TOKEN HERE\"")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadJson(t *testing.T) {
|
||||
t.Log("testing loadJson")
|
||||
if loadJson("") == nil {
|
||||
t.Error("no error for empty json")
|
||||
}
|
||||
if loadJson("../settings.json") != nil {
|
||||
t.Error("error while loading settings.json")
|
||||
}
|
||||
if loadJson("settings.go") == nil {
|
||||
t.Error("no error for malformed json")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue