@@ -665,26 +665,37 @@ func TestMain(m *testing.M) {
665665func TestAddAssetAnnotations (t * testing.T ) {
666666 assert := assert .New (t )
667667
668+ tmpdir , err := ioutil .TempDir ("" , "" )
669+ assert .NoError (err )
670+ defer os .RemoveAll (tmpdir )
671+
672+ // Create a pretend asset file
673+ // (required since the existence of binary asset annotations is verified).
674+ fakeAssetFile := filepath .Join (tmpdir , "fake-binary" )
675+
676+ err = ioutil .WriteFile (fakeAssetFile , []byte ("" ), fileMode )
677+ assert .NoError (err )
678+
668679 expectedAnnotations := map [string ]string {
669- vcAnnotations .FirmwarePath : "/some/where" ,
680+ vcAnnotations .FirmwarePath : fakeAssetFile ,
670681 vcAnnotations .FirmwareHash : "ffff" ,
671682
672- vcAnnotations .HypervisorPath : "/some/where" ,
683+ vcAnnotations .HypervisorPath : fakeAssetFile ,
673684 vcAnnotations .HypervisorHash : "bbbbb" ,
674685
675- vcAnnotations .HypervisorCtlPath : "/some/where/else" ,
686+ vcAnnotations .HypervisorCtlPath : fakeAssetFile ,
676687 vcAnnotations .HypervisorCtlHash : "cc" ,
677688
678- vcAnnotations .ImagePath : "/abc/rgb/image" ,
689+ vcAnnotations .ImagePath : fakeAssetFile ,
679690 vcAnnotations .ImageHash : "52ss2550983" ,
680691
681- vcAnnotations .InitrdPath : "/abc/rgb/initrd" ,
692+ vcAnnotations .InitrdPath : fakeAssetFile ,
682693 vcAnnotations .InitrdHash : "aaaa" ,
683694
684- vcAnnotations .JailerPath : "/foo/bar" ,
695+ vcAnnotations .JailerPath : fakeAssetFile ,
685696 vcAnnotations .JailerHash : "dddd" ,
686697
687- vcAnnotations .KernelPath : "/abc/rgb/kernel" ,
698+ vcAnnotations .KernelPath : fakeAssetFile ,
688699 vcAnnotations .KernelHash : "3l2353we871g" ,
689700 }
690701
@@ -705,7 +716,7 @@ func TestAddAssetAnnotations(t *testing.T) {
705716 }
706717
707718 // Try annotations without enabling them first
708- err : = addAnnotations (ocispec , & config , runtimeConfig )
719+ err = addAnnotations (ocispec , & config , runtimeConfig )
709720 assert .Error (err )
710721 assert .Exactly (map [string ]string {}, config .Annotations )
711722
@@ -714,8 +725,16 @@ func TestAddAssetAnnotations(t *testing.T) {
714725 err = addAnnotations (ocispec , & config , runtimeConfig )
715726 assert .Error (err )
716727
728+ // Check if we filter the assets when the value is not allowed by path lists
729+ runtimeConfig .HypervisorConfig .EnableAnnotations = []string {".*" }
730+ err = addAnnotations (ocispec , & config , runtimeConfig )
731+ assert .Error (err )
732+
717733 // Check that it works if all annotation are enabled
718734 runtimeConfig .HypervisorConfig .EnableAnnotations = []string {".*" }
735+ runtimeConfig .HypervisorConfig .HypervisorPathList = []string {fakeAssetFile }
736+ runtimeConfig .HypervisorConfig .HypervisorCtlPathList = []string {fakeAssetFile }
737+ runtimeConfig .HypervisorConfig .JailerPathList = []string {fakeAssetFile }
719738 err = addAnnotations (ocispec , & config , runtimeConfig )
720739 assert .NoError (err )
721740 assert .Exactly (expectedAnnotations , config .Annotations )
0 commit comments