From bbefc5b24feeac275596d006c8bffdcb77209f77 Mon Sep 17 00:00:00 2001 From: Meredith Lancaster Date: Mon, 9 Sep 2024 08:53:11 -0600 Subject: [PATCH] handle os.PathError in GetLocalAttestations Signed-off-by: Meredith Lancaster --- pkg/cmd/attestation/verification/attestation.go | 2 +- pkg/cmd/attestation/verification/attestation_test.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/attestation/verification/attestation.go b/pkg/cmd/attestation/verification/attestation.go index 6107ccf4e..d6e7d9e15 100644 --- a/pkg/cmd/attestation/verification/attestation.go +++ b/pkg/cmd/attestation/verification/attestation.go @@ -86,7 +86,7 @@ func loadBundleFromJSONFile(path string) ([]*api.Attestation, error) { func loadBundlesFromJSONLinesFile(path string) ([]*api.Attestation, error) { fileContent, err := os.ReadFile(path) if err != nil { - return nil, fmt.Errorf("could not read file: %v", err) + return nil, err } attestations := []*api.Attestation{} diff --git a/pkg/cmd/attestation/verification/attestation_test.go b/pkg/cmd/attestation/verification/attestation_test.go index e321ffd87..68914afad 100644 --- a/pkg/cmd/attestation/verification/attestation_test.go +++ b/pkg/cmd/attestation/verification/attestation_test.go @@ -88,13 +88,21 @@ func TestGetLocalAttestations(t *testing.T) { require.Nil(t, attestations) }) - t.Run("with non-existent bundle file", func(t *testing.T) { + t.Run("with non-existent bundle file and JSON file", func(t *testing.T) { path := "../test/data/not-found-bundle.json" attestations, err := GetLocalAttestations(path) require.ErrorContains(t, err, "bundle could not be loaded from JSON file") require.Nil(t, attestations) }) + + t.Run("with non-existent bundle file and JSON lines file", func(t *testing.T) { + path := "../test/data/not-found-bundle.jsonl" + attestations, err := GetLocalAttestations(path) + + require.ErrorContains(t, err, "bundles could not be loaded from JSON lines file") + require.Nil(t, attestations) + }) } func TestFilterAttestations(t *testing.T) {