Skip to content

Commit

Permalink
chore: add version update during conversion
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Zantow <kzantow@gmail.com>
  • Loading branch information
kzantow committed Jan 17, 2023
1 parent 11b0757 commit eb63bc4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
8 changes: 5 additions & 3 deletions convert/spdx_document_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"reflect"
"testing"

converter "github.com/anchore/go-struct-converter"
"github.com/anchore/go-struct-converter"
"github.com/stretchr/testify/require"

"github.com/spdx/tools-golang/spdx"
Expand All @@ -25,6 +25,7 @@ func Test_ConvertSPDXDocuments(t *testing.T) {
{
name: "basic v2_2 to v2_3",
source: v2_2.Document{
SPDXVersion: v2_2.Version,
Packages: []*v2_2.Package{
{
PackageName: "Pkg 1",
Expand All @@ -47,6 +48,7 @@ func Test_ConvertSPDXDocuments(t *testing.T) {
},
},
expected: spdx.Document{
SPDXVersion: spdx.Version,
Packages: []*spdx.Package{
{
PackageName: "Pkg 1",
Expand Down Expand Up @@ -575,7 +577,7 @@ func Test_ConvertSPDXDocuments(t *testing.T) {
},
},
expected: spdx.Document{
SPDXVersion: "SPDX-2.2", // TODO implement ConvertFrom to update this value
SPDXVersion: "SPDX-2.3", // ConvertFrom updates this value
DataLicense: "data license",
SPDXIdentifier: "spdx id",
DocumentName: "doc name",
Expand Down Expand Up @@ -1594,7 +1596,7 @@ func Test_ConvertSPDXDocuments(t *testing.T) {
},
},
expected: spdx.Document{
SPDXVersion: "SPDX-2.2", // TODO implement ConvertFrom to update this value
SPDXVersion: "SPDX-2.3", // ConvertFrom updates this value
DataLicense: "data license",
SPDXIdentifier: "spdx id",
DocumentName: "doc name",
Expand Down
9 changes: 9 additions & 0 deletions spdx/v2/v2_1/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package v2_1

import (
"github.com/anchore/go-struct-converter"

"github.com/spdx/tools-golang/spdx/v2/common"
)

Expand Down Expand Up @@ -68,3 +70,10 @@ type Document struct {
// DEPRECATED in version 2.0 of spec
Reviews []*Review `json:"-"`
}

func (d *Document) ConvertFrom(_ interface{}) error {
d.SPDXVersion = Version
return nil
}

var _ converter.ConvertFrom = (*Document)(nil)
9 changes: 9 additions & 0 deletions spdx/v2/v2_2/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package v2_2

import (
"github.com/anchore/go-struct-converter"

"github.com/spdx/tools-golang/spdx/v2/common"
)

Expand Down Expand Up @@ -68,3 +70,10 @@ type Document struct {
// DEPRECATED in version 2.0 of spec
Reviews []*Review `json:"-"`
}

func (d *Document) ConvertFrom(_ interface{}) error {
d.SPDXVersion = Version
return nil
}

var _ converter.ConvertFrom = (*Document)(nil)
9 changes: 9 additions & 0 deletions spdx/v2/v2_3/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package v2_3

import (
"github.com/anchore/go-struct-converter"

"github.com/spdx/tools-golang/spdx/v2/common"
)

Expand Down Expand Up @@ -67,3 +69,10 @@ type Document struct {
// DEPRECATED in version 2.0 of spec
Reviews []*Review `json:"-" yaml:"-"`
}

func (d *Document) ConvertFrom(_ interface{}) error {
d.SPDXVersion = Version
return nil
}

var _ converter.ConvertFrom = (*Document)(nil)

0 comments on commit eb63bc4

Please sign in to comment.