about summary refs log tree commit diff
path: root/context/context_test.go
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2017-06-22T15·01+0200
committerVincent Ambo <tazjin@gmail.com>2017-07-03T12·27+0200
commit9d26c17f13240479ef3e12e9182aca3ac2e61901 (patch)
tree9ead86ab4028e81b4413a63d65908b355ba53e42 /context/context_test.go
parent68e1e484594aa86a874c6eb2ad328274c5f48dd7 (diff)
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.
Diffstat (limited to 'context/context_test.go')
-rw-r--r--context/context_test.go44
1 files changed, 44 insertions, 0 deletions
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()
+	}
+}