Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/formats/common/spdxhelpers/to_syft_model.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package spdxhelpers

import (
"errors"
"strconv"
"strings"

Expand All @@ -17,6 +18,10 @@ import (
)

func ToSyftModel(doc *spdx.Document2_2) (*sbom.SBOM, error) {
if doc == nil {
return nil, errors.New("cannot convert SPDX document to Syft model because document is nil")
}

spdxIDMap := make(map[string]interface{})

s := &sbom.SBOM{
Expand Down
26 changes: 26 additions & 0 deletions syft/formats_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package syft

import (
"bytes"
"io"
"os"
"testing"
Expand Down Expand Up @@ -41,6 +42,31 @@ func TestIdentify(t *testing.T) {
}
}

func TestFormats_EmptyInput(t *testing.T) {
for _, format := range formats {
t.Run(format.ID().String(), func(t *testing.T) {
t.Run("format.Decode", func(t *testing.T) {
input := bytes.NewReader(nil)

assert.NotPanics(t, func() {
decodedSBOM, err := format.Decode(input)
assert.Error(t, err)
assert.Nil(t, decodedSBOM)
})
})

t.Run("format.Validate", func(t *testing.T) {
input := bytes.NewReader(nil)

assert.NotPanics(t, func() {
err := format.Validate(input)
assert.Error(t, err)
})
})
})
}
}

func TestFormatByName(t *testing.T) {

tests := []struct {
Expand Down
5 changes: 5 additions & 0 deletions syft/sbom/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ var (

type FormatID string

// String returns a string representation of the FormatID.
func (f FormatID) String() string {
return string(f)
}

type Format interface {
ID() FormatID
Encode(io.Writer, SBOM) error
Expand Down