|
| 1 | +//go:build linux || freebsd |
| 2 | + |
| 3 | +package integration |
| 4 | + |
| 5 | +import ( |
| 6 | + "os" |
| 7 | + "path/filepath" |
| 8 | + "time" |
| 9 | + |
| 10 | + . "github.com/containers/podman/v5/test/utils" |
| 11 | + . "github.com/onsi/ginkgo/v2" |
| 12 | + . "github.com/onsi/gomega" |
| 13 | +) |
| 14 | + |
| 15 | +var _ = Describe("Podman artifact created timestamp", func() { |
| 16 | + |
| 17 | + createArtifactFile := func(size int) (string, error) { |
| 18 | + artifactFile := filepath.Join(podmanTest.TempDir, RandomString(12)) |
| 19 | + f, err := os.Create(artifactFile) |
| 20 | + if err != nil { |
| 21 | + return "", err |
| 22 | + } |
| 23 | + defer f.Close() |
| 24 | + |
| 25 | + data := RandomString(size) |
| 26 | + _, err = f.WriteString(data) |
| 27 | + if err != nil { |
| 28 | + return "", err |
| 29 | + } |
| 30 | + return artifactFile, nil |
| 31 | + } |
| 32 | + |
| 33 | + It("podman artifact inspect shows created date in RFC3339 format", func() { |
| 34 | + artifactFile, err := createArtifactFile(1024) |
| 35 | + Expect(err).ToNot(HaveOccurred()) |
| 36 | + |
| 37 | + artifactName := "localhost/test/artifact-created" |
| 38 | + |
| 39 | + // Record time before creation (with some buffer for slow systems) |
| 40 | + beforeCreate := time.Now().UTC().Add(-time.Second) |
| 41 | + |
| 42 | + // Add artifact |
| 43 | + podmanTest.PodmanExitCleanly("artifact", "add", artifactName, artifactFile) |
| 44 | + |
| 45 | + // Record time after creation |
| 46 | + afterCreate := time.Now().UTC().Add(time.Second) |
| 47 | + |
| 48 | + // Inspect artifact |
| 49 | + a := podmanTest.InspectArtifact(artifactName) |
| 50 | + Expect(a.Name).To(Equal(artifactName)) |
| 51 | + |
| 52 | + // Check that created annotation exists and is in valid RFC3339 format |
| 53 | + createdStr, exists := a.Manifest.Annotations["org.opencontainers.image.created"] |
| 54 | + Expect(exists).To(BeTrue(), "Should have org.opencontainers.image.created annotation") |
| 55 | + |
| 56 | + // Parse the created timestamp as RFC3339Nano |
| 57 | + createdTime, err := time.Parse(time.RFC3339Nano, createdStr) |
| 58 | + Expect(err).ToNot(HaveOccurred(), "Created timestamp should be valid RFC3339Nano format") |
| 59 | + |
| 60 | + // Verify timestamp is reasonable (within our time window) |
| 61 | + Expect(createdTime).To(BeTemporally(">=", beforeCreate)) |
| 62 | + Expect(createdTime).To(BeTemporally("<=", afterCreate)) |
| 63 | + }) |
| 64 | + |
| 65 | + It("podman artifact append preserves original created date", func() { |
| 66 | + artifactFile1, err := createArtifactFile(1024) |
| 67 | + Expect(err).ToNot(HaveOccurred()) |
| 68 | + artifactFile2, err := createArtifactFile(2048) |
| 69 | + Expect(err).ToNot(HaveOccurred()) |
| 70 | + |
| 71 | + artifactName := "localhost/test/artifact-append" |
| 72 | + |
| 73 | + // Add initial artifact |
| 74 | + podmanTest.PodmanExitCleanly("artifact", "add", artifactName, artifactFile1) |
| 75 | + |
| 76 | + // Get initial created timestamp |
| 77 | + a := podmanTest.InspectArtifact(artifactName) |
| 78 | + originalCreated := a.Manifest.Annotations["org.opencontainers.image.created"] |
| 79 | + Expect(originalCreated).ToNot(BeEmpty()) |
| 80 | + |
| 81 | + // Wait a moment to ensure timestamps would be different |
| 82 | + time.Sleep(100 * time.Millisecond) |
| 83 | + |
| 84 | + // Append to the artifact |
| 85 | + podmanTest.PodmanExitCleanly("artifact", "add", "--append", artifactName, artifactFile2) |
| 86 | + |
| 87 | + // Check that created timestamp is unchanged |
| 88 | + a = podmanTest.InspectArtifact(artifactName) |
| 89 | + currentCreated := a.Manifest.Annotations["org.opencontainers.image.created"] |
| 90 | + Expect(currentCreated).To(Equal(originalCreated), "Created timestamp should not change when appending") |
| 91 | + |
| 92 | + // Verify we have 2 layers |
| 93 | + Expect(a.Manifest.Layers).To(HaveLen(2)) |
| 94 | + }) |
| 95 | +}) |
0 commit comments