Skip to content

Conversation

@baude
Copy link
Member

@baude baude commented Dec 12, 2025

This PR adds unit tests for libartfact's store. It's only a first pass but should help finding any regressions. Speaking of which, this PR also fixes a regression that was introduced in artifact Add.

The tests were basically lifted from my previous PR and isolated as such.

This PR adds unit tests for libartfact's store.  It's only a first pass
but should help finding any regressions.  Speaking of which, this PR
also fixes a regression that was introduced in artifact Add.

The tests were basically lifted from my previous PR and isolated as
such.

Signed-off-by: Brent Baude <bbaude@redhat.com>
@github-actions github-actions bot added the common Related to "common" package label Dec 12, 2025
@baude baude marked this pull request as draft December 12, 2025 14:45
podmanbot pushed a commit to podmanbot/buildah that referenced this pull request Dec 12, 2025
@podmanbot
Copy link

✅ A new PR has been created in buildah to vendor these changes: containers/buildah#6601

@baude
Copy link
Member Author

baude commented Dec 12, 2025

Test PR for podman -> containers/podman#27761

Copy link
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really just the .Replace implementation comment — on tests I’ll completely defer the style to people working on this subpackage.

return nil, err
}
var err2 error
oldDigest, err2 = arty.GetDigest()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICS oldDigest is later used for deleting the old version; if we already fully delete it here, isn’t that sufficient?


If this were required: It might work just fine as is — just, as a reader, reading metadata about an object after deleting it would require an extra look, and ordering it the other way would trivially remove that concern.

Comment on lines +287 to +301
// Create new manifest
annotations := make(map[string]string)
if options.Annotations != nil {
annotations = maps.Clone(options.Annotations)
}
annotations[specV1.AnnotationCreated] = time.Now().UTC().Format(time.RFC3339Nano)

artifactManifest = specV1.Manifest{
Versioned: specs.Versioned{SchemaVersion: ManifestSchemaVersion},
MediaType: specV1.MediaTypeImageManifest,
ArtifactType: options.ArtifactMIMEType,
Config: specV1.DescriptorEmptyJSON,
Layers: make([]specV1.Descriptor, 0),
Annotations: annotations,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worthwhile to share this with the default: case? This new version already dropped a comment, the are very likely to get of sync over time.

Comment on lines +90 to +95
// if no specific files were passed, create a random file of 2k
if fileNames == nil {
filename, err := randomAlphanumeric(5)
require.NoError(t, err)
fileNames = map[string]int{
filename: 2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment doesn’t match

// Verify artifact properties
artifact := artifacts[0]
assert.Equal(t, refName, artifact.Name)
assert.Equal(t, "application/vnd.test+type", artifact.Manifest.ArtifactType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This is sort of a remote dependency on helperAddArtifact’s default, but, as a test of the storage persisting data, it works well enough.

Also happens in other tests.

This doesn’t necessarily require making this more verbose in all helperAdd… calls — maybe define a constant for this value, and use it both in helperAdd… and in tests; that will demonstrate that the string values are related.)

Comment on lines +556 to +567
stat1, err := os.Stat(extractedFile1)
require.NoError(t, err)
assert.Equal(t, int64(512), stat1.Size())

stat2, err := os.Stat(extractedFile2)
require.NoError(t, err)
assert.Equal(t, int64(1024), stat2.Size())

stat3, err := os.Stat(extractedFile3)
require.NoError(t, err)
assert.Equal(t, int64(2048), stat3.Size())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really redundant with the assert.Len checks below. (Absolutely non-blocking: Comparing the actual contents as well might be valuable.)

}
}

func TestDetermineBlobMIMEType_FromFile(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Absolutely non-blocking: This might be easier table-driven; in fact all 3 of the “success” test functions for determine… could share a test core, and either have separate tables, or be merged into one test function.)


_, _, err = determineBlobMIMEType(blob)
require.Error(t, err)
assert.Contains(t, err.Error(), "Artifact.BlobFile or Artifact.BlobReader must be provided")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[When we are testing on exact error messages at all… but it’s useful in this case] the error message is maybe technically accurate, but not obviously matching the input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to "common" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants