From 3e1940a8e4c73e97feebad49c17d0d50ad9e43cc Mon Sep 17 00:00:00 2001
From: Adrian Reber <areber@redhat.com>
Date: Fri, 5 Nov 2021 15:50:13 +0000
Subject: [PATCH] Test to check for presence of 'stats-dump' in exported
 checkpoints

Signed-off-by: Adrian Reber <areber@redhat.com>
---
 test/e2e/checkpoint_test.go | 53 +++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/test/e2e/checkpoint_test.go b/test/e2e/checkpoint_test.go
index a8efe1ca97..be6b782b50 100644
--- a/test/e2e/checkpoint_test.go
+++ b/test/e2e/checkpoint_test.go
@@ -5,9 +5,11 @@ import (
 	"net"
 	"os"
 	"os/exec"
+	"path/filepath"
 	"strings"
 	"time"
 
+	"github.com/checkpoint-restore/go-criu/v5/stats"
 	"github.com/containers/podman/v3/pkg/checkpoint/crutils"
 	"github.com/containers/podman/v3/pkg/criu"
 	. "github.com/containers/podman/v3/test/utils"
@@ -1191,4 +1193,55 @@ var _ = Describe("Podman checkpoint", func() {
 		// Remove exported checkpoint
 		os.Remove(fileName)
 	})
+
+	It("podman checkpoint container with export and statistics", func() {
+		localRunString := getRunString([]string{
+			"--rm",
+			ALPINE,
+			"top",
+		})
+		session := podmanTest.Podman(localRunString)
+		session.WaitWithDefaultTimeout()
+		Expect(session).Should(Exit(0))
+		Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
+		cid := session.OutputToString()
+		fileName := "/tmp/checkpoint-" + cid + ".tar.gz"
+
+		result := podmanTest.Podman([]string{
+			"container",
+			"checkpoint",
+			"-l", "-e",
+			fileName,
+		})
+		result.WaitWithDefaultTimeout()
+
+		// As the container has been started with '--rm' it will be completely
+		// cleaned up after checkpointing.
+		Expect(result).Should(Exit(0))
+		Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
+		Expect(podmanTest.NumberOfContainers()).To(Equal(0))
+
+		// Extract checkpoint archive
+		destinationDirectory, err := CreateTempDirInTempDir()
+		Expect(err).ShouldNot(HaveOccurred())
+
+		tarsession := SystemExec(
+			"tar",
+			[]string{
+				"xf",
+				fileName,
+				"-C",
+				destinationDirectory,
+			},
+		)
+		Expect(tarsession).Should(Exit(0))
+
+		_, err = os.Stat(filepath.Join(destinationDirectory, stats.StatsDump))
+		Expect(err).ShouldNot(HaveOccurred())
+
+		Expect(os.RemoveAll(destinationDirectory)).To(BeNil())
+
+		// Remove exported checkpoint
+		os.Remove(fileName)
+	})
 })