Skip to content

Commit

Permalink
Merge pull request #676 from wolfi-dev/update-import
Browse files Browse the repository at this point in the history
receive a byte not the path for a file
  • Loading branch information
rawlingsj committed Mar 6, 2024
2 parents 3743342 + 402abc1 commit b0ade16
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 2 additions & 7 deletions pkg/advisory/import.go
Expand Up @@ -15,13 +15,8 @@ import (
)

// ImporAdvisoriesYAML import and yaml Advisories data and present as a config index struct
func ImporAdvisoriesYAML(inputData string) (tempDir string, documents *configs.Index[v2.Document], err error) {
inputAdv, err := os.ReadFile(inputData)
if err != nil {
return "", nil, fmt.Errorf("unable to create output file: %v", err)
}

yamlDocs := bytes.Split(inputAdv, []byte("\n---\n"))
func ImporAdvisoriesYAML(inputData []byte) (tempDir string, documents *configs.Index[v2.Document], err error) {
yamlDocs := bytes.Split(inputData, []byte("\n---\n"))
// Unmarshal YAML documents
var docs []v2.Document
for _, doc := range yamlDocs {
Expand Down
6 changes: 5 additions & 1 deletion pkg/advisory/import_test.go
Expand Up @@ -2,6 +2,7 @@ package advisory

import (
"context"
"os"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -29,7 +30,10 @@ func Test_ImportAdvisoriesYAML(t *testing.T) {
advisoryDocs, err := v2.NewIndex(context.Background(), advisoryFsys)
require.NoError(t, err)

_, importedDocuments, err := ImporAdvisoriesYAML(tt.pathToInputData)
b, err := os.ReadFile(tt.pathToInputData)
require.NoError(t, err)

_, importedDocuments, err := ImporAdvisoriesYAML(b)
require.NoError(t, err)
require.Equal(t, advisoryDocs.Select().Len(), importedDocuments.Select().Len())
})
Expand Down

0 comments on commit b0ade16

Please sign in to comment.