Test artifact hashes as opaque values

This commit is contained in:
2026-11-05 14:31:14 +00:00
parent e7a3665443
commit a91bc1608b
3 changed files with 16 additions and 10 deletions

View File

@@ -3,9 +3,7 @@ package artifact
import (
"bytes"
"context"
"crypto/sha256"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
@@ -284,9 +282,12 @@ func TestFileReaderUsesOpenedSizeOnlyAsACapacityHint(t *testing.T) {
if artifact.Name != filepath.Base(filePath) || artifact.URI != filePath || artifact.ContentType == "" {
t.Fatalf("unexpected artifact metadata: name=%q URI=%q content type=%q", artifact.Name, artifact.URI, artifact.ContentType)
}
wantHash := fmt.Sprintf("%x", sha256.Sum256(tc.body))
if artifact.Hash != wantHash {
t.Fatalf("artifact hash=%q, want %q", artifact.Hash, wantHash)
inline, err := NewCompositeReader().Read(context.Background(), domain.ArtifactRef{Type: domain.ArtifactRefInline, Body: string(tc.body)})
if err != nil {
t.Fatal(err)
}
if inline.Hash == "" || artifact.Hash != inline.Hash {
t.Fatalf("file and inline hashes differ: %q/%q", artifact.Hash, inline.Hash)
}
})
}