2016-11-06 21:41:46 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2016-11-08 19:48:45 +00:00
|
|
|
|
|
|
|
yaml "github.com/cloudfoundry-incubator/candiedyaml"
|
|
|
|
"github.com/rancher/os/util"
|
2016-11-06 21:41:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func testValidate(t *testing.T, cfg []byte, contains string) {
|
|
|
|
validationErrors, err := Validate(cfg)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if contains == "" && len(validationErrors.Errors()) != 0 {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
if !strings.Contains(fmt.Sprint(validationErrors.Errors()), contains) {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidate(t *testing.T) {
|
|
|
|
testValidate(t, []byte("{}"), "")
|
|
|
|
testValidate(t, []byte(`rancher:
|
|
|
|
log: true
|
|
|
|
`), "")
|
|
|
|
testValidate(t, []byte("bad_key: {}"), "Additional property bad_key is not allowed")
|
|
|
|
testValidate(t, []byte("rancher: []"), "rancher: Invalid type. Expected: object, given: array")
|
2016-11-08 19:48:45 +00:00
|
|
|
|
|
|
|
var fullConfig map[string]interface{}
|
|
|
|
if err := util.ConvertIgnoreOmitEmpty(CloudConfig{}, &fullConfig); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
fullConfigBytes, err := yaml.Marshal(fullConfig)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
testValidate(t, fullConfigBytes, "")
|
2016-11-06 21:41:46 +00:00
|
|
|
}
|