Skip to content

Commit

Permalink
tests: Update assets test to adapt to recent changes
Browse files Browse the repository at this point in the history
The changes introduced in PR kata-containers#3031 require additional changes.
Code lifted from kata-containers/kata-containers#1086.

Fixes: kata-containers#3005

Suggested-by: James O.D. Hunt <james.o.hunt@intel.com>
Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
  • Loading branch information
c3d authored and fidencio committed Nov 11, 2020
1 parent fd59f15 commit d389fa4
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions virtcontainers/pkg/oci/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,26 +665,37 @@ func TestMain(m *testing.M) {
func TestAddAssetAnnotations(t *testing.T) {
assert := assert.New(t)

tmpdir, err := ioutil.TempDir("", "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)

// Create a pretend asset file
// (required since the existence of binary asset annotations is verified).
fakeAssetFile := filepath.Join(tmpdir, "fake-binary")

err = ioutil.WriteFile(fakeAssetFile, []byte(""), fileMode)
assert.NoError(err)

expectedAnnotations := map[string]string{
vcAnnotations.FirmwarePath: "/some/where",
vcAnnotations.FirmwarePath: fakeAssetFile,
vcAnnotations.FirmwareHash: "ffff",

vcAnnotations.HypervisorPath: "/some/where",
vcAnnotations.HypervisorPath: fakeAssetFile,
vcAnnotations.HypervisorHash: "bbbbb",

vcAnnotations.HypervisorCtlPath: "/some/where/else",
vcAnnotations.HypervisorCtlPath: fakeAssetFile,
vcAnnotations.HypervisorCtlHash: "cc",

vcAnnotations.ImagePath: "/abc/rgb/image",
vcAnnotations.ImagePath: fakeAssetFile,
vcAnnotations.ImageHash: "52ss2550983",

vcAnnotations.InitrdPath: "/abc/rgb/initrd",
vcAnnotations.InitrdPath: fakeAssetFile,
vcAnnotations.InitrdHash: "aaaa",

vcAnnotations.JailerPath: "/foo/bar",
vcAnnotations.JailerPath: fakeAssetFile,
vcAnnotations.JailerHash: "dddd",

vcAnnotations.KernelPath: "/abc/rgb/kernel",
vcAnnotations.KernelPath: fakeAssetFile,
vcAnnotations.KernelHash: "3l2353we871g",
}

Expand All @@ -705,7 +716,7 @@ func TestAddAssetAnnotations(t *testing.T) {
}

// Try annotations without enabling them first
err := addAnnotations(ocispec, &config, runtimeConfig)
err = addAnnotations(ocispec, &config, runtimeConfig)
assert.Error(err)
assert.Exactly(map[string]string{}, config.Annotations)

Expand All @@ -714,8 +725,16 @@ func TestAddAssetAnnotations(t *testing.T) {
err = addAnnotations(ocispec, &config, runtimeConfig)
assert.Error(err)

// Check if we filter the assets when the value is not allowed by path lists
runtimeConfig.HypervisorConfig.EnableAnnotations = []string{".*"}
err = addAnnotations(ocispec, &config, runtimeConfig)
assert.Error(err)

// Check that it works if all annotation are enabled
runtimeConfig.HypervisorConfig.EnableAnnotations = []string{".*"}
runtimeConfig.HypervisorConfig.HypervisorPathList = []string{fakeAssetFile}
runtimeConfig.HypervisorConfig.HypervisorCtlPathList = []string{fakeAssetFile}
runtimeConfig.HypervisorConfig.JailerPathList = []string{fakeAssetFile}
err = addAnnotations(ocispec, &config, runtimeConfig)
assert.NoError(err)
assert.Exactly(expectedAnnotations, config.Annotations)
Expand Down

0 comments on commit d389fa4

Please sign in to comment.