Beispiel #1
0
func runAllProcessorTests(t *testing.T, cases map[string]processorTestCase) {
	color.NoColor = false

	json := `{
		"var1": "var1",
		"var-var": "var-var",
		"var": {"var": "1"},
		"version": "{{ feature }}-{{ feature-suffix }}",
		"feature": "value-unknown",
		"feature-suffix": "{{ feature }}",
		"list": [1, 2, 3]
	}`

	tree, err := gabs.ParseJSON([]byte(json))
	if err != nil {
		color.Red("%v: failed!\n", err)
		t.Fail()
	}

	for name, test := range cases {
		if res, err := Template(test.in, tree); err == nil {
			if test.expect == res {
				color.Green("%v: Ok\n", name)
			} else {
				color.Red("%v: %v != %v: failed!\n", name, test.expect, res)
				t.Fail()
			}
		} else {
			color.Red("error %v\n: failed!", err)
			t.Fail()
		}
	}
}
Beispiel #2
0
func LoadJSON(json string) *Manifest {
	tree, err := gabs.ParseJSON([]byte(json))
	if err != nil {
		log.Fatalf("Error on parse json '%s': %v\n", json, err)
	}

	return &Manifest{tree}
}
Beispiel #3
0
func LoadFile(path string) (*gabs.Container, error) {
	data, err := ioutil.ReadFile(path)
	if err != nil {
		return nil, errors.New(color.RedString("Manifest file `%s` not found: %v", path, err))
	}

	if jsonData, err := yaml.YAMLToJSON(data); err != nil {
		return nil, errors.New(color.RedString("Error on parse manifest %s: %v!", path, err))
	} else {
		return gabs.ParseJSON(jsonData)
	}
}