From dea67a3eba2bfc4a3951d2333715fad4034c0a97 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 1 Jun 2026 21:55:36 +0200 Subject: [PATCH] test/e2e: use Ginkgo Setenv in info tests Signed-off-by: Evan Lezar --- test/e2e/info_test.go | 44 ++++++++++++++++++++++++++++++--------- test/system/005-info.bats | 31 --------------------------- 2 files changed, 34 insertions(+), 41 deletions(-) diff --git a/test/e2e/info_test.go b/test/e2e/info_test.go index 4e1b7f2530..fbcfb42828 100644 --- a/test/e2e/info_test.go +++ b/test/e2e/info_test.go @@ -66,10 +66,7 @@ var _ = Describe("Podman Info", func() { SkipIfNotRootless("test of rootless_storage_path is only meaningful as rootless") SkipIfRemote("Only tests storage on local client") configPath := filepath.Join(podmanTest.TempDir, ".config", "containers", "storage.conf") - os.Setenv("CONTAINERS_STORAGE_CONF", configPath) - defer func() { - os.Unsetenv("CONTAINERS_STORAGE_CONF") - }() + GinkgoT().Setenv("CONTAINERS_STORAGE_CONF", configPath) err := os.RemoveAll(filepath.Dir(configPath)) Expect(err).ToNot(HaveOccurred()) @@ -150,7 +147,7 @@ var _ = Describe("Podman Info", func() { It("Podman info: check default network from configuration", func() { configPath := filepath.Join(podmanTest.TempDir, "containers.conf") - os.Setenv("CONTAINERS_CONF_OVERRIDE", configPath) + GinkgoT().Setenv("CONTAINERS_CONF_OVERRIDE", configPath) customNetName := "my-custom-test-network" configContent := fmt.Sprintf("[network]\ndefault_network=%q\n", customNetName) @@ -165,8 +162,7 @@ var _ = Describe("Podman Info", func() { It("Podman info: check CDI spec dirs and devices from configuration", func() { cdiDir := filepath.Join(podmanTest.TempDir, "cdi") - err := os.MkdirAll(cdiDir, os.ModePerm) - Expect(err).ToNot(HaveOccurred()) + Expect(os.MkdirAll(cdiDir, os.ModePerm)).To(Succeed()) cdiSpec := []byte(`{ "cdiVersion": "0.3.0", @@ -180,12 +176,11 @@ var _ = Describe("Podman Info", func() { } ] }`) - err = os.WriteFile(filepath.Join(cdiDir, "device.json"), cdiSpec, os.ModePerm) - Expect(err).ToNot(HaveOccurred()) + Expect(os.WriteFile(filepath.Join(cdiDir, "device.json"), cdiSpec, os.ModePerm)).To(Succeed()) configPath := filepath.Join(podmanTest.TempDir, "containers.conf") configContent := fmt.Sprintf("[engine]\ncdi_spec_dirs = [%q]\n", cdiDir) - err = os.WriteFile(configPath, []byte(configContent), os.ModePerm) + err := os.WriteFile(configPath, []byte(configContent), os.ModePerm) Expect(err).ToNot(HaveOccurred()) GinkgoT().Setenv("CONTAINERS_CONF_OVERRIDE", configPath) @@ -197,6 +192,35 @@ var _ = Describe("Podman Info", func() { Expect(session.OutputToString()).To(ContainSubstring("vendor.com/device=myKmsg")) }) + It("Podman info: check CDI spec dirs and devices with --cdi-spec-dir", func() { + SkipIfRemote("The --cdi-spec-dir flag is not supported for remote") + + cdiDir := filepath.Join(podmanTest.TempDir, "cdi") + Expect(os.MkdirAll(cdiDir, os.ModePerm)).To(Succeed()) + + cdiSpec := []byte(`{ + "cdiVersion": "0.3.0", + "kind": "vendor.com/device", + "devices": [ + { + "name": "myKmsg", + "containerEdits": { + "env": ["PODMAN_CDI_INFO_TEST=1"] + } + } + ] +}`) + Expect(os.WriteFile(filepath.Join(cdiDir, "device.json"), cdiSpec, os.ModePerm)).To(Succeed()) + + session := podmanTest.PodmanExitCleanly("--cdi-spec-dir", cdiDir, "info", "--format", "{{.Host.CDISpecDirs}} {{.Host.DiscoveredDevices}}") + Expect(session.OutputToString()).To(ContainSubstring(cdiDir)) + Expect(session.OutputToString()).To(ContainSubstring("vendor.com/device=myKmsg")) + + session = podmanTest.PodmanExitCleanly("--cdi-spec-dir", cdiDir, "system", "info", "--format", "{{.Host.CDISpecDirs}} {{.Host.DiscoveredDevices}}") + Expect(session.OutputToString()).To(ContainSubstring(cdiDir)) + Expect(session.OutputToString()).To(ContainSubstring("vendor.com/device=myKmsg")) + }) + It("Podman info: check desired storage driver", func() { // defined in .cirrus.yml want := os.Getenv("CI_DESIRED_STORAGE") diff --git a/test/system/005-info.bats b/test/system/005-info.bats index 7a8a37e314..e56dcfce2c 100644 --- a/test/system/005-info.bats +++ b/test/system/005-info.bats @@ -62,37 +62,6 @@ store.imageStore.number | 1 done < <(parse_table "$tests") } -@test "podman info - CDI spec dirs and devices" { - skip_if_remote "--cdi-spec-dir flag is not supported for remote" - - cdi_dir=$PODMAN_TMPDIR/cdi - mkdir -p "$cdi_dir" - cat >"$cdi_dir/device.json" <