-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal_config_test.go
49 lines (40 loc) · 1.36 KB
/
global_config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// global_db_config_test
package main
import (
"encoding/json"
"io/ioutil"
"os"
"testing"
)
//initialization and unmarshalling of fetched json file
//that contains db details of the admin account
func TestConfigInitialization(t *testing.T) {
//dummy json file
DefaultConfig := &DbConfig{}
DefaultConfig.Db_addr = "127.0.0.1"
DefaultConfig.Db_port = "6379"
DefaultConfig.Db_password = "RNG!"
DefaultConfig.Bconfig.Description = "I write about code!"
DefaultConfig.Bconfig.Gplus = "#"
DefaultConfig.Bconfig.BlogTitle = "N/A"
DefaultJson, _ := json.MarshalIndent(&DefaultConfig, "\n", "\t")
ioutil.WriteFile("config.json", []byte(DefaultJson), 0644)
defer os.Remove("config.json")
/* test config initialization */
if cfg, err := InitDbConfig(); err != nil || cfg == nil {
t.Error("ADMIN DEFAULT PATH:\tfailed reading configuration file")
} else {
if cfg.Db_addr == "" || cfg.Db_port == "" || cfg.Db_password == "" {
t.Log("ADMIN DEFAULT PATH:\tone of the address values is empty")
t.Fail()
}
}
if custom_cfg, cerr := InitDbConfigWithPath("config.json"); cerr != nil || custom_cfg == nil {
t.Error("ADMIN CUSTOM PATH:\tfailed reading configuration file")
} else {
if custom_cfg.Db_addr == "" || custom_cfg.Db_port == "" || custom_cfg.Db_password == "" {
t.Log("ADMIN CUSTOM PATH:\tone or more of the address values is empty")
t.Fail()
}
}
}