@@ -909,6 +909,38 @@ spec:
909909 assertEqual (t , output , expected )
910910}
911911
912+ func TestCreatePolicyEmptyManifest (t * testing.T ) {
913+ t .Parallel ()
914+ tmpDir := t .TempDir ()
915+ createConfigMap (t , tmpDir , "configmap.yaml" )
916+
917+ err := os .WriteFile (path .Join (tmpDir , "empty.yaml" ), []byte {}, 0o666 )
918+ if err != nil {
919+ t .Fatalf ("Failed to write empty.yaml" )
920+ }
921+
922+ p := Plugin {}
923+ p .PolicyDefaults .Namespace = "my-policies"
924+ policyConf := types.PolicyConfig {
925+ Name : "policy-app-config" ,
926+ Manifests : []types.Manifest {
927+ {
928+ Path : path .Join (tmpDir , "empty.yaml" ),
929+ ConfigurationPolicyOptions : types.ConfigurationPolicyOptions {ComplianceType : "mustonlyhave" },
930+ }, {
931+ Path : path .Join (tmpDir , "configmap.yaml" ),
932+ ConfigurationPolicyOptions : types.ConfigurationPolicyOptions {ComplianceType : "mustnothave" },
933+ },
934+ },
935+ }
936+ p .Policies = append (p .Policies , policyConf )
937+ p .applyDefaults (map [string ]interface {}{})
938+
939+ err = p .createPolicy (& p .Policies [0 ])
940+ expectedErr := fmt .Sprintf ("found empty YAML in the manifest at %s" , path .Join (tmpDir , "empty.yaml" ))
941+ assertEqual (t , err .Error (), expectedErr )
942+ }
943+
912944func TestCreatePolicyWithAnnotations (t * testing.T ) {
913945 t .Parallel ()
914946 tmpDir := t .TempDir ()
0 commit comments