From 9d26c17f13240479ef3e12e9182aca3ac2e61901 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 22 Jun 2017 17:01:36 +0200 Subject: feat context: Add ability to import extra variables from files Kontemplate context specifications can now load extra variables from YAML or JSON files by specifying a list of files (relative to the context file) under the `import` key. --- context/context_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'context/context_test.go') diff --git a/context/context_test.go b/context/context_test.go index c5b5e7f12611..b6acf416e6cc 100644 --- a/context/context_test.go +++ b/context/context_test.go @@ -159,3 +159,47 @@ func TestDefaultValuesLoading(t *testing.T) { t.Fail() } } + +func TestImportValuesLoading(t *testing.T) { + ctx, err := LoadContextFromFile("testdata/import-vars-simple.yaml") + if err != nil { + t.Error(err) + t.Fail() + } + + expected := map[string]interface{}{ + "override": "true", + "music": map[string]interface{}{ + "artist": "Pallida", + "track": "Tractor Beam", + }, + } + + if !reflect.DeepEqual(ctx.Global, expected) { + t.Error("Expected global values after loading imports did not match!") + t.Fail() + } +} + +func TestImportValuesOverride(t *testing.T) { + ctx, err := LoadContextFromFile("testdata/import-vars-override.yaml") + if err != nil { + t.Error(err) + t.Fail() + } + + expected := map[string]interface{}{ + "override": float64(3), + "music": map[string]interface{}{ + "artist": "Pallida", + "track": "Tractor Beam", + }, + "place": "Oslo", + "globalVar": "very global!", + } + + if !reflect.DeepEqual(ctx.Global, expected) { + t.Error("Expected global values after loading imports did not match!") + t.Fail() + } +} -- cgit 1.4.1