handle os.PathError in GetLocalAttestations

Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
Meredith Lancaster 2024-09-09 08:53:11 -06:00
parent 945e2b7eee
commit bbefc5b24f
2 changed files with 10 additions and 2 deletions

View file

@ -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{}

View file

@ -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) {