in pkg/targettesting/targettest.go [56:100]
func newConstraintTemplate(targetName, rego string) *templates.ConstraintTemplate {
// Building a correct constraint template is difficult based on the struct. It's easier
// to reason about yaml files and rely on existing conversion code.
ctSpec := map[string]interface{}{
"crd": map[string]interface{}{
"spec": map[string]interface{}{
"names": map[string]interface{}{
"kind": testConstraintKind,
},
"validation": map[string]interface{}{
"openAPIV3Schema": map[string]interface{}{
"type": "object",
},
},
},
},
"targets": []map[string]interface{}{
{
"target": targetName,
"rego": rego,
},
},
}
ct := map[string]interface{}{
"apiVersion": fmt.Sprintf("templates.gatekeeper.sh/%s", testVersion),
"kind": "ConstraintTemplate",
"metadata": map[string]interface{}{
"name": strings.ToLower(testConstraintKind),
},
"spec": ctSpec,
}
config, err := configs.NewConfigurationFromContents([]*unstructured.Unstructured{&unstructured.Unstructured{Object: ct}}, []string{})
if err != nil {
// This represents an error in a test case
panic(err)
}
var templates []*templates.ConstraintTemplate
templates = append(templates, config.GCPTemplates...)
templates = append(templates, config.K8STemplates...)
templates = append(templates, config.TFTemplates...)
return templates[0]
}