加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main_test.go 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
Louis-Félix Tessier 提交于 2020-01-27 11:33 . Adding unit tests
package main
import (
"reflect"
"testing"
)
func TestLoadConfig_No_Config(t *testing.T) {
_, err := loadConfig("no_config")
if err != nil {
t.Errorf("Error on loading config %v", err)
}
}
func TestLoadConfig_Example_Config(t *testing.T) {
_, err := loadConfig("config/config_example.yml")
if err != nil {
t.Errorf("Error on loading config %v", err)
}
}
func TestLoadConfigContent_ParsingError(t *testing.T) {
configFile := `
DUMMY
:FOO
`
_, err := loadConfigContent([]byte(configFile))
if err == nil {
t.Errorf("Should have an error parsing unparseable content")
}
}
func TestLoadConfigContent_Ok_Standard(t *testing.T) {
configFile := `
expose_azure_tag_info: true
resource_configurations:
- resource_tags:
Client: "Alice"
Env: "Prod"
resource_types:
- "Microsoft.Web/serverfarms"
- "Microsoft.Web/sites"
`
want := Config{
ResourceConfigurations: []ResourceConfiguration{
ResourceConfiguration{
ResourceTags: map[string]string{
"Client": "Alice",
"Env": "Prod",
},
ResourceTypes: []string{
"Microsoft.Web/serverfarms",
"Microsoft.Web/sites",
},
},
},
ExposeAzureTagInfo: true,
}
got, err := loadConfigContent([]byte(configFile))
if err != nil {
t.Errorf("Error on loading config content %v", err)
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Error in getting config Got:%v, Expected config:%v", got, want)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化