Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

receive a byte not the path for a file #676

Merged
merged 1 commit into from Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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