Centralize source manifest validation
This commit is contained in:
@@ -2,6 +2,7 @@ package bundle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -32,8 +33,10 @@ func TestValidateRejectsMissingFile(t *testing.T) {
|
||||
|
||||
func TestValidateRejectsSizeMismatch(t *testing.T) {
|
||||
backend := validFakeBundle(t)
|
||||
manifest := strings.Replace(string(readFixture(t, "testdata/valid_bundle/manifest.json")), `"size": 8`, `"size": 9`, 1)
|
||||
writeFakeFile(t, backend, "manifest.json", manifest)
|
||||
manifest := validFixtureManifest(t)
|
||||
manifest.Files[1].Size = 9
|
||||
manifest.Digest = BundleDigest(manifest.Files)
|
||||
writeManifest(t, backend, manifest)
|
||||
_, err := Validate(context.Background(), backend, "")
|
||||
assertErrorContains(t, err, "size mismatch")
|
||||
}
|
||||
@@ -79,6 +82,15 @@ func writeFakeFile(t *testing.T, backend *fake.Backend, path, data string) {
|
||||
}
|
||||
}
|
||||
|
||||
func writeManifest(t *testing.T, backend *fake.Backend, manifest Manifest) {
|
||||
t.Helper()
|
||||
data, err := json.MarshalIndent(manifest, "", " ")
|
||||
if err != nil {
|
||||
t.Fatalf("MarshalIndent() error = %v", err)
|
||||
}
|
||||
writeFakeFile(t, backend, ManifestName, string(append(data, '\n')))
|
||||
}
|
||||
|
||||
func deleteFakeFile(t *testing.T, backend *fake.Backend, path string) {
|
||||
t.Helper()
|
||||
err := backend.DeleteManagedBundle(context.Background(), "", []string{path}, storage.DeleteOptions{IgnoreMissing: true})
|
||||
|
||||
Reference in New Issue
Block a user