components/calico-hostendpoint-controller: test bad configuration
Make sure that when bad configuration is provided, we return error to
ther user, rather than just ignore it.
@@ -87,3 +87,37 @@ func TestRenderManifestNoConfig(t *testing.T) {
t.Fatalf("Rendered manifests shouldn't be empty")
}
}
+
+func TestRenderManifestBadConfig(t *testing.T) {
+ configHCL := `
+component "calico-hostendpoint-controller" {
+ foo = "bar"
+}
+ `
+
+ hclParser := hclparse.NewParser()
+ component := &component{}
+
+ file, diags := hclParser.ParseHCL([]byte(configHCL), fmt.Sprintf("%s.lokocfg", name))
+ if diags.HasErrors() {
+ t.Fatalf("Parsing config should succeed")
+ }
+
+ configBody := hcl.MergeFiles([]*hcl.File{file})
+
+ var rootConfig config.RootConfig
+
+ diagnostics := gohcl.DecodeBody(configBody, nil, &rootConfig)
+ if diagnostics.HasErrors() {
+ t.Fatalf("Valid root config should not return error, got: %s", diagnostics)
+ }
+
+ c := &config.Config{
+ RootConfig: &rootConfig,
+ }
+
+ diagnostics = component.LoadConfig(c.LoadComponentConfigBody(name), &hcl.EvalContext{})
+ if !diagnostics.HasErrors() {
+ t.Fatalf("Invalid config should return error")
+ }
+}
