-
Notifications
You must be signed in to change notification settings - Fork 2
/
config_test.go
51 lines (43 loc) · 1 KB
/
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
50
package main
import (
"testing"
)
const ConfigFile string = "test_config.yaml"
const ConfigContent string = `#test comment
address: 0.0.0.0
port: 8888
pages:
/about: pages/about.md
articlesperpage: 5`
func getConfig(t *testing.T) *Config{
config, err := LoadConfig(ConfigFile)
if err != nil || config == nil{
t.Fatal("Couldn't load config from file", err)
}
return config
}
func TestLoadConfigWithExistingFile(t *testing.T) {
getConfig(t)
}
func TestLoadConfigWithMissingFile(t *testing.T) {
//This file shouldn't exist
config, err := LoadConfig("test_missing.yaml")
if err == nil || config != nil{
t.Fail()
}
}
func TestLoadConfigOutput(t *testing.T){
config := getConfig(t)
if config.Address != "0.0.0.0" {
t.Fail()
}
if config.Port != "8888"{
t.Fail()
}
if page, ok := config.Pages["/about"]; !ok || page != "pages/about.md" {
t.Fail()
}
if config.ArticlesPerPage != 5 {
t.Fail()
}
}