mirror of
https://git.klmp200.net/ALFRED/ALFRED.git
synced 2025-01-18 02:26:44 +01:00
Tests for settings
This commit is contained in:
parent
2c34fbefe2
commit
2cd142844d
@ -9,7 +9,6 @@ pipeline:
|
||||
secrets: [ test_api_token ]
|
||||
environment: [ test_api_token ]
|
||||
commands:
|
||||
- go get -v -d ./...
|
||||
- go test ./...
|
||||
publish:
|
||||
image: plugins/docker
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-23 15:24:22
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-23 17:25:09
|
||||
* @Last Modified time: 2018-07-23 19:14:10
|
||||
*/
|
||||
|
||||
package main
|
||||
@ -15,7 +15,9 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
settings.LoadSettings("settings.json", "settings_custom.json")
|
||||
if err := settings.LoadSettings("settings.json", "settings_custom.json"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println("Bot initialisation")
|
||||
b, err := tb.NewBot(tb.Settings{
|
||||
|
@ -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…
Reference in New Issue
Block a user