@@ -664,26 +664,37 @@ func TestMain(m *testing.M) {
664664func TestAddAssetAnnotations (t * testing.T ) {
665665 assert := assert .New (t )
666666
667+ tmpdir , err := ioutil .TempDir ("" , "" )
668+ assert .NoError (err )
669+ defer os .RemoveAll (tmpdir )
670+
671+ // Create a pretend asset file
672+ // (required since the existence of binary asset annotations is verified).
673+ fakeAssetFile := filepath .Join (tmpdir , "fake-binary" )
674+
675+ err = ioutil .WriteFile (fakeAssetFile , []byte ("" ), fileMode )
676+ assert .NoError (err )
677+
667678 expectedAnnotations := map [string ]string {
668- vcAnnotations .FirmwarePath : "/some/where" ,
679+ vcAnnotations .FirmwarePath : fakeAssetFile ,
669680 vcAnnotations .FirmwareHash : "ffff" ,
670681
671- vcAnnotations .HypervisorPath : "/some/where" ,
682+ vcAnnotations .HypervisorPath : fakeAssetFile ,
672683 vcAnnotations .HypervisorHash : "bbbbb" ,
673684
674- vcAnnotations .HypervisorCtlPath : "/some/where/else" ,
685+ vcAnnotations .HypervisorCtlPath : fakeAssetFile ,
675686 vcAnnotations .HypervisorCtlHash : "cc" ,
676687
677- vcAnnotations .ImagePath : "/abc/rgb/image" ,
688+ vcAnnotations .ImagePath : fakeAssetFile ,
678689 vcAnnotations .ImageHash : "52ss2550983" ,
679690
680- vcAnnotations .InitrdPath : "/abc/rgb/initrd" ,
691+ vcAnnotations .InitrdPath : fakeAssetFile ,
681692 vcAnnotations .InitrdHash : "aaaa" ,
682693
683- vcAnnotations .JailerPath : "/foo/bar" ,
694+ vcAnnotations .JailerPath : fakeAssetFile ,
684695 vcAnnotations .JailerHash : "dddd" ,
685696
686- vcAnnotations .KernelPath : "/abc/rgb/kernel" ,
697+ vcAnnotations .KernelPath : fakeAssetFile ,
687698 vcAnnotations .KernelHash : "3l2353we871g" ,
688699 }
689700
@@ -704,7 +715,7 @@ func TestAddAssetAnnotations(t *testing.T) {
704715 }
705716
706717 // Try annotations without enabling them first
707- err : = addAnnotations (ocispec , & config , runtimeConfig )
718+ err = addAnnotations (ocispec , & config , runtimeConfig )
708719 assert .Error (err )
709720 assert .Exactly (map [string ]string {}, config .Annotations )
710721
@@ -713,8 +724,16 @@ func TestAddAssetAnnotations(t *testing.T) {
713724 err = addAnnotations (ocispec , & config , runtimeConfig )
714725 assert .Error (err )
715726
727+ // Check if we filter the assets when the value is not allowed by path lists
728+ runtimeConfig .HypervisorConfig .EnableAnnotations = []string {".*" }
729+ err = addAnnotations (ocispec , & config , runtimeConfig )
730+ assert .Error (err )
731+
716732 // Check that it works if all annotation are enabled
717733 runtimeConfig .HypervisorConfig .EnableAnnotations = []string {".*" }
734+ runtimeConfig .HypervisorConfig .HypervisorPathList = []string {fakeAssetFile }
735+ runtimeConfig .HypervisorConfig .HypervisorCtlPathList = []string {fakeAssetFile }
736+ runtimeConfig .HypervisorConfig .JailerPathList = []string {fakeAssetFile }
718737 err = addAnnotations (ocispec , & config , runtimeConfig )
719738 assert .NoError (err )
720739 assert .Exactly (expectedAnnotations , config .Annotations )
0 commit comments