diff options
author | Brandon Lum <lumjjb@gmail.com> | 2022-07-19 16:43:48 -0400 |
---|---|---|
committer | Brandon Lum <lumjjb@gmail.com> | 2022-07-19 22:43:24 -0400 |
commit | 9ae1bd2f8e0dabb0845f1225b54f23e8f3a429f1 (patch) | |
tree | a43213aadfb9bde3d9ec15634a39305f19ff38b2 /tvsaver/saver2v1 | |
parent | 41d2272711255f5a25e16e3507ec3318bc550189 (diff) | |
download | spdx-tools-9ae1bd2f8e0dabb0845f1225b54f23e8f3a429f1.tar.gz |
replace all v2_1, v2_2 with new convention
Signed-off-by: Brandon Lum <lumjjb@gmail.com>
Diffstat (limited to 'tvsaver/saver2v1')
-rw-r--r-- | tvsaver/saver2v1/save_annotation.go | 7 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_annotation_test.go | 21 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_creation_info.go | 5 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_creation_info_test.go | 15 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_document.go | 7 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_document_test.go | 113 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_file.go | 9 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_file_test.go | 79 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_other_license.go | 4 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_other_license_test.go | 6 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_package.go | 7 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_package_test.go | 95 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_relationship.go | 9 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_relationship_test.go | 21 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_review.go | 4 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_review_test.go | 8 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_snippet.go | 9 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_snippet_test.go | 43 |
18 files changed, 238 insertions, 224 deletions
diff --git a/tvsaver/saver2v1/save_annotation.go b/tvsaver/saver2v1/save_annotation.go index f7d7953..3fa351f 100644 --- a/tvsaver/saver2v1/save_annotation.go +++ b/tvsaver/saver2v1/save_annotation.go @@ -6,10 +6,11 @@ import ( "fmt" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderAnnotation2_1(ann *spdx.Annotation2_1, w io.Writer) error { +func renderAnnotation2_1(ann *v2_1.Annotation, w io.Writer) error { if ann.Annotator.Annotator != "" && ann.Annotator.AnnotatorType != "" { fmt.Fprintf(w, "Annotator: %s: %s\n", ann.Annotator.AnnotatorType, ann.Annotator.Annotator) } @@ -19,7 +20,7 @@ func renderAnnotation2_1(ann *spdx.Annotation2_1, w io.Writer) error { if ann.AnnotationType != "" { fmt.Fprintf(w, "AnnotationType: %s\n", ann.AnnotationType) } - annIDStr := spdx.RenderDocElementID(ann.AnnotationSPDXIdentifier) + annIDStr := common.RenderDocElementID(ann.AnnotationSPDXIdentifier) if annIDStr != "SPDXRef-" { fmt.Fprintf(w, "SPDXREF: %s\n", annIDStr) } diff --git a/tvsaver/saver2v1/save_annotation_test.go b/tvsaver/saver2v1/save_annotation_test.go index 3eef5a7..405bf8a 100644 --- a/tvsaver/saver2v1/save_annotation_test.go +++ b/tvsaver/saver2v1/save_annotation_test.go @@ -6,16 +6,17 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Annotation section Saver tests ===== func TestSaver2_1AnnotationSavesTextForPerson(t *testing.T) { - ann := &spdx.Annotation2_1{ - Annotator: spdx.Annotator{AnnotatorType: "Person", Annotator: "John Doe"}, + ann := &v2_1.Annotation{ + Annotator: common.Annotator{AnnotatorType: "Person", Annotator: "John Doe"}, AnnotationDate: "2018-10-10T17:52:00Z", AnnotationType: "REVIEW", - AnnotationSPDXIdentifier: spdx.MakeDocElementID("", "DOCUMENT"), + AnnotationSPDXIdentifier: common.MakeDocElementID("", "DOCUMENT"), AnnotationComment: "This is an annotation about the SPDX document", } @@ -43,11 +44,11 @@ AnnotationComment: This is an annotation about the SPDX document } func TestSaver2_1AnnotationSavesTextForOrganization(t *testing.T) { - ann := &spdx.Annotation2_1{ - Annotator: spdx.Annotator{AnnotatorType: "Organization", Annotator: "John Doe, Inc."}, + ann := &v2_1.Annotation{ + Annotator: common.Annotator{AnnotatorType: "Organization", Annotator: "John Doe, Inc."}, AnnotationDate: "2018-10-10T17:52:00Z", AnnotationType: "REVIEW", - AnnotationSPDXIdentifier: spdx.MakeDocElementID("", "DOCUMENT"), + AnnotationSPDXIdentifier: common.MakeDocElementID("", "DOCUMENT"), AnnotationComment: "This is an annotation about the SPDX document", } @@ -75,11 +76,11 @@ AnnotationComment: This is an annotation about the SPDX document } func TestSaver2_1AnnotationSavesTextForTool(t *testing.T) { - ann := &spdx.Annotation2_1{ - Annotator: spdx.Annotator{AnnotatorType: "Tool", Annotator: "magictool-1.1"}, + ann := &v2_1.Annotation{ + Annotator: common.Annotator{AnnotatorType: "Tool", Annotator: "magictool-1.1"}, AnnotationDate: "2018-10-10T17:52:00Z", AnnotationType: "REVIEW", - AnnotationSPDXIdentifier: spdx.MakeDocElementID("", "DOCUMENT"), + AnnotationSPDXIdentifier: common.MakeDocElementID("", "DOCUMENT"), AnnotationComment: "This is an annotation about the SPDX document", } diff --git a/tvsaver/saver2v1/save_creation_info.go b/tvsaver/saver2v1/save_creation_info.go index de8b107..e4b5992 100644 --- a/tvsaver/saver2v1/save_creation_info.go +++ b/tvsaver/saver2v1/save_creation_info.go @@ -4,11 +4,12 @@ package saver2v1 import ( "fmt" - "github.com/spdx/tools-golang/spdx" "io" + + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderCreationInfo2_1(ci *spdx.CreationInfo2_1, w io.Writer) error { +func renderCreationInfo2_1(ci *v2_1.CreationInfo, w io.Writer) error { if ci.LicenseListVersion != "" { fmt.Fprintf(w, "LicenseListVersion: %s\n", ci.LicenseListVersion) } diff --git a/tvsaver/saver2v1/save_creation_info_test.go b/tvsaver/saver2v1/save_creation_info_test.go index 1784cf5..5225735 100644 --- a/tvsaver/saver2v1/save_creation_info_test.go +++ b/tvsaver/saver2v1/save_creation_info_test.go @@ -6,14 +6,15 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Creation Info section Saver tests ===== func TestSaver2_1CISavesText(t *testing.T) { - ci := &spdx.CreationInfo2_1{ + ci := &v2_1.CreationInfo{ LicenseListVersion: "2.0", - Creators: []spdx.Creator{ + Creators: []common.Creator{ {Creator: "John Doe", CreatorType: "Person"}, {Creator: "Jane Doe (janedoe@example.com)", CreatorType: "Person"}, {Creator: "John Doe, Inc.", CreatorType: "Organization"}, @@ -56,8 +57,8 @@ CreatorComment: this is a creator comment func TestSaver2_1CIOmitsOptionalFieldsIfEmpty(t *testing.T) { // --- need at least one creator; do first for Persons --- - ci1 := &spdx.CreationInfo2_1{ - Creators: []spdx.Creator{ + ci1 := &v2_1.CreationInfo{ + Creators: []common.Creator{ {Creator: "John Doe", CreatorType: "Person"}, }, Created: "2018-10-10T06:20:00Z", @@ -83,8 +84,8 @@ Created: 2018-10-10T06:20:00Z } // --- need at least one creator; now switch to organization --- - ci2 := &spdx.CreationInfo2_1{ - Creators: []spdx.Creator{ + ci2 := &v2_1.CreationInfo{ + Creators: []common.Creator{ {Creator: "John Doe, Inc.", CreatorType: "Organization"}, }, Created: "2018-10-10T06:20:00Z", diff --git a/tvsaver/saver2v1/save_document.go b/tvsaver/saver2v1/save_document.go index ea17db2..1db4bf6 100644 --- a/tvsaver/saver2v1/save_document.go +++ b/tvsaver/saver2v1/save_document.go @@ -9,14 +9,15 @@ import ( "io" "sort" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // RenderDocument2_1 is the main entry point to take an SPDX in-memory // Document (version 2.1), and render it to the received io.Writer. // It is only exported in order to be available to the tvsaver package, // and typically does not need to be called by client code. -func RenderDocument2_1(doc *spdx.Document2_1, w io.Writer) error { +func RenderDocument2_1(doc *v2_1.Document, w io.Writer) error { if doc.CreationInfo == nil { return fmt.Errorf("Document had nil CreationInfo section") } @@ -28,7 +29,7 @@ func RenderDocument2_1(doc *spdx.Document2_1, w io.Writer) error { fmt.Fprintf(w, "DataLicense: %s\n", doc.DataLicense) } if doc.SPDXIdentifier != "" { - fmt.Fprintf(w, "SPDXID: %s\n", spdx.RenderElementID(doc.SPDXIdentifier)) + fmt.Fprintf(w, "SPDXID: %s\n", common.RenderElementID(doc.SPDXIdentifier)) } if doc.DocumentName != "" { fmt.Fprintf(w, "DocumentName: %s\n", doc.DocumentName) diff --git a/tvsaver/saver2v1/save_document_test.go b/tvsaver/saver2v1/save_document_test.go index b186564..1447c07 100644 --- a/tvsaver/saver2v1/save_document_test.go +++ b/tvsaver/saver2v1/save_document_test.go @@ -6,65 +6,66 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== entire Document Saver tests ===== func TestSaver2_1DocumentSavesText(t *testing.T) { // Creation Info section - ci := &spdx.CreationInfo2_1{ - Creators: []spdx.Creator{ + ci := &v2_1.CreationInfo{ + Creators: []common.Creator{ {Creator: "John Doe", CreatorType: "Person"}, }, Created: "2018-10-10T06:20:00Z", } // unpackaged files - f1 := &spdx.File2_1{ + f1 := &v2_1.File{ FileName: "/tmp/whatever1.txt", - FileSPDXIdentifier: spdx.ElementID("File1231"), - Checksums: []spdx.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983c", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File1231"), + Checksums: []common.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983c", Algorithm: common.SHA1}}, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{"Apache-2.0"}, FileCopyrightText: "Copyright (c) Jane Doe", } - f2 := &spdx.File2_1{ + f2 := &v2_1.File{ FileName: "/tmp/whatever2.txt", - FileSPDXIdentifier: spdx.ElementID("File1232"), - Checksums: []spdx.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983d", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File1232"), + Checksums: []common.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983d", Algorithm: common.SHA1}}, LicenseConcluded: "MIT", LicenseInfoInFiles: []string{"MIT"}, FileCopyrightText: "Copyright (c) John Doe", } - unFiles := []*spdx.File2_1{ + unFiles := []*v2_1.File{ f1, f2, } // Package 1: packaged files with snippets - sn1 := &spdx.Snippet2_1{ + sn1 := &v2_1.Snippet{ SnippetSPDXIdentifier: "Snippet19", - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "FileHasSnippets").ElementRefID, - Ranges: []spdx.SnippetRange{{StartPointer: spdx.SnippetRangePointer{Offset: 17}, EndPointer: spdx.SnippetRangePointer{Offset: 209}}}, + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "FileHasSnippets").ElementRefID, + Ranges: []common.SnippetRange{{StartPointer: common.SnippetRangePointer{Offset: 17}, EndPointer: common.SnippetRangePointer{Offset: 209}}}, SnippetLicenseConcluded: "GPL-2.0-or-later", SnippetCopyrightText: "Copyright (c) John Doe 20x6", } - sn2 := &spdx.Snippet2_1{ + sn2 := &v2_1.Snippet{ SnippetSPDXIdentifier: "Snippet20", - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "FileHasSnippets").ElementRefID, - Ranges: []spdx.SnippetRange{{StartPointer: spdx.SnippetRangePointer{Offset: 268}, EndPointer: spdx.SnippetRangePointer{Offset: 309}}}, + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "FileHasSnippets").ElementRefID, + Ranges: []common.SnippetRange{{StartPointer: common.SnippetRangePointer{Offset: 268}, EndPointer: common.SnippetRangePointer{Offset: 309}}}, SnippetLicenseConcluded: "WTFPL", SnippetCopyrightText: "NOASSERTION", } - f3 := &spdx.File2_1{ + f3 := &v2_1.File{ FileName: "/tmp/file-with-snippets.txt", - FileSPDXIdentifier: spdx.ElementID("FileHasSnippets"), - Checksums: []spdx.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983e", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("FileHasSnippets"), + Checksums: []common.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983e", Algorithm: common.SHA1}}, LicenseConcluded: "GPL-2.0-or-later AND WTFPL", LicenseInfoInFiles: []string{ "Apache-2.0", @@ -72,28 +73,28 @@ func TestSaver2_1DocumentSavesText(t *testing.T) { "WTFPL", }, FileCopyrightText: "Copyright (c) Jane Doe", - Snippets: map[spdx.ElementID]*spdx.Snippet2_1{ - spdx.ElementID("Snippet19"): sn1, - spdx.ElementID("Snippet20"): sn2, + Snippets: map[common.ElementID]*v2_1.Snippet{ + common.ElementID("Snippet19"): sn1, + common.ElementID("Snippet20"): sn2, }, } - f4 := &spdx.File2_1{ + f4 := &v2_1.File{ FileName: "/tmp/another-file.txt", - FileSPDXIdentifier: spdx.ElementID("FileAnother"), - Checksums: []spdx.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983f", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("FileAnother"), + Checksums: []common.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983f", Algorithm: common.SHA1}}, LicenseConcluded: "BSD-3-Clause", LicenseInfoInFiles: []string{"BSD-3-Clause"}, FileCopyrightText: "Copyright (c) Jane Doe LLC", } - pkgWith := &spdx.Package2_1{ + pkgWith := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, - PackageVerificationCode: spdx.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, + PackageVerificationCode: common.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, PackageLicenseConcluded: "GPL-2.0-or-later AND BSD-3-Clause AND WTFPL", PackageLicenseInfoFromFiles: []string{ "Apache-2.0", @@ -103,14 +104,14 @@ func TestSaver2_1DocumentSavesText(t *testing.T) { }, PackageLicenseDeclared: "Apache-2.0 OR GPL-2.0-or-later", PackageCopyrightText: "Copyright (c) John Doe, Inc.", - Files: []*spdx.File2_1{ + Files: []*v2_1.File{ f3, f4, }, } // Other Licenses 1 and 2 - ol1 := &spdx.OtherLicense2_1{ + ol1 := &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-1", ExtractedText: `License 1 text blah blah blah @@ -118,57 +119,57 @@ blah blah blah blah`, LicenseName: "License 1", } - ol2 := &spdx.OtherLicense2_1{ + ol2 := &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-2", ExtractedText: `License 2 text - this is a license that does some stuff`, LicenseName: "License 2", } // Relationships - rln1 := &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p1"), + rln1 := &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p1"), Relationship: "DESCRIBES", } - rln2 := &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "File1231"), + rln2 := &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "File1231"), Relationship: "DESCRIBES", } - rln3 := &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "File1232"), + rln3 := &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "File1232"), Relationship: "DESCRIBES", } // Annotations - ann1 := &spdx.Annotation2_1{ - Annotator: spdx.Annotator{Annotator: "John Doe", + ann1 := &v2_1.Annotation{ + Annotator: common.Annotator{Annotator: "John Doe", AnnotatorType: "Person"}, AnnotationDate: "2018-10-10T17:52:00Z", AnnotationType: "REVIEW", - AnnotationSPDXIdentifier: spdx.MakeDocElementID("", "DOCUMENT"), + AnnotationSPDXIdentifier: common.MakeDocElementID("", "DOCUMENT"), AnnotationComment: "This is an annotation about the SPDX document", } - ann2 := &spdx.Annotation2_1{ - Annotator: spdx.Annotator{Annotator: "John Doe, Inc.", + ann2 := &v2_1.Annotation{ + Annotator: common.Annotator{Annotator: "John Doe, Inc.", AnnotatorType: "Organization"}, AnnotationDate: "2018-10-10T17:52:00Z", AnnotationType: "REVIEW", - AnnotationSPDXIdentifier: spdx.MakeDocElementID("", "p1"), + AnnotationSPDXIdentifier: common.MakeDocElementID("", "p1"), AnnotationComment: "This is an annotation about Package p1", } // Reviews - rev1 := &spdx.Review2_1{ + rev1 := &v2_1.Review{ Reviewer: "John Doe", ReviewerType: "Person", ReviewDate: "2018-10-14T10:28:00Z", } - rev2 := &spdx.Review2_1{ + rev2 := &v2_1.Review{ Reviewer: "Jane Doe LLC", ReviewerType: "Organization", ReviewDate: "2018-10-14T10:28:00Z", @@ -176,31 +177,31 @@ blah blah blah blah`, } // now, build the document - doc := &spdx.Document2_1{ + doc := &v2_1.Document{ SPDXVersion: "SPDX-2.1", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), + SPDXIdentifier: common.ElementID("DOCUMENT"), DocumentName: "spdx-go-0.0.1.abcdef", DocumentNamespace: "https://github.com/swinslow/spdx-docs/spdx-go/spdx-go-0.0.1.abcdef.whatever", CreationInfo: ci, - Packages: []*spdx.Package2_1{ + Packages: []*v2_1.Package{ pkgWith, }, Files: unFiles, - OtherLicenses: []*spdx.OtherLicense2_1{ + OtherLicenses: []*v2_1.OtherLicense{ ol1, ol2, }, - Relationships: []*spdx.Relationship2_1{ + Relationships: []*v2_1.Relationship{ rln1, rln2, rln3, }, - Annotations: []*spdx.Annotation2_1{ + Annotations: []*v2_1.Annotation{ ann1, ann2, }, - Reviews: []*spdx.Review2_1{ + Reviews: []*v2_1.Review{ rev1, rev2, }, @@ -332,7 +333,7 @@ ReviewComment: I have reviewed this SPDX document and it is awesome } func TestSaver2_1DocumentReturnsErrorIfNilCreationInfo(t *testing.T) { - doc := &spdx.Document2_1{} + doc := &v2_1.Document{} var got bytes.Buffer err := RenderDocument2_1(doc, &got) diff --git a/tvsaver/saver2v1/save_file.go b/tvsaver/saver2v1/save_file.go index c131122..3cb9027 100644 --- a/tvsaver/saver2v1/save_file.go +++ b/tvsaver/saver2v1/save_file.go @@ -7,15 +7,16 @@ import ( "io" "sort" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderFile2_1(f *spdx.File2_1, w io.Writer) error { +func renderFile2_1(f *v2_1.File, w io.Writer) error { if f.FileName != "" { fmt.Fprintf(w, "FileName: %s\n", f.FileName) } if f.FileSPDXIdentifier != "" { - fmt.Fprintf(w, "SPDXID: %s\n", spdx.RenderElementID(f.FileSPDXIdentifier)) + fmt.Fprintf(w, "SPDXID: %s\n", common.RenderElementID(f.FileSPDXIdentifier)) } for _, s := range f.FileTypes { fmt.Fprintf(w, "FileType: %s\n", s) @@ -68,7 +69,7 @@ func renderFile2_1(f *spdx.File2_1, w io.Writer) error { } sort.Strings(snippetKeys) for _, sID := range snippetKeys { - s := f.Snippets[spdx.ElementID(sID)] + s := f.Snippets[common.ElementID(sID)] renderSnippet2_1(s, w) } diff --git a/tvsaver/saver2v1/save_file_test.go b/tvsaver/saver2v1/save_file_test.go index 9708430..ba1d82b 100644 --- a/tvsaver/saver2v1/save_file_test.go +++ b/tvsaver/saver2v1/save_file_test.go @@ -6,22 +6,23 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== File section Saver tests ===== func TestSaver2_1FileSavesText(t *testing.T) { - f := &spdx.File2_1{ + f := &v2_1.File{ FileName: "/tmp/whatever.txt", - FileSPDXIdentifier: spdx.ElementID("File123"), + FileSPDXIdentifier: common.ElementID("File123"), FileTypes: []string{ "TEXT", "DOCUMENTATION", }, - Checksums: []spdx.Checksum{ - {Algorithm: spdx.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, - {Algorithm: spdx.SHA256, Value: "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd"}, - {Algorithm: spdx.MD5, Value: "624c1abb3664f4b35547e7c73864ad24"}, + Checksums: []common.Checksum{ + {Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, + {Algorithm: common.SHA256, Value: "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd"}, + {Algorithm: common.MD5, Value: "624c1abb3664f4b35547e7c73864ad24"}, }, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{ @@ -30,20 +31,20 @@ func TestSaver2_1FileSavesText(t *testing.T) { }, LicenseComments: "this is a license comment(s)", FileCopyrightText: "Copyright (c) Jane Doe", - ArtifactOfProjects: []*spdx.ArtifactOfProject2_1{ - &spdx.ArtifactOfProject2_1{ + ArtifactOfProjects: []*v2_1.ArtifactOfProject{ + &v2_1.ArtifactOfProject{ Name: "project1", HomePage: "http://example.com/1/", URI: "http://example.com/1/uri.whatever", }, - &spdx.ArtifactOfProject2_1{ + &v2_1.ArtifactOfProject{ Name: "project2", }, - &spdx.ArtifactOfProject2_1{ + &v2_1.ArtifactOfProject{ Name: "project3", HomePage: "http://example.com/3/", }, - &spdx.ArtifactOfProject2_1{ + &v2_1.ArtifactOfProject{ Name: "project4", URI: "http://example.com/4/uri.whatever", }, @@ -105,32 +106,32 @@ FileDependency: g.txt } func TestSaver2_1FileSavesSnippetsAlso(t *testing.T) { - sn1 := &spdx.Snippet2_1{ - SnippetSPDXIdentifier: spdx.ElementID("Snippet19"), - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File123").ElementRefID, - Ranges: []spdx.SnippetRange{{StartPointer: spdx.SnippetRangePointer{Offset: 17}, EndPointer: spdx.SnippetRangePointer{Offset: 209}}}, + sn1 := &v2_1.Snippet{ + SnippetSPDXIdentifier: common.ElementID("Snippet19"), + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "File123").ElementRefID, + Ranges: []common.SnippetRange{{StartPointer: common.SnippetRangePointer{Offset: 17}, EndPointer: common.SnippetRangePointer{Offset: 209}}}, SnippetLicenseConcluded: "GPL-2.0-or-later", SnippetCopyrightText: "Copyright (c) John Doe 20x6", } - sn2 := &spdx.Snippet2_1{ - SnippetSPDXIdentifier: spdx.ElementID("Snippet20"), - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File123").ElementRefID, - Ranges: []spdx.SnippetRange{{StartPointer: spdx.SnippetRangePointer{Offset: 268}, EndPointer: spdx.SnippetRangePointer{Offset: 309}}}, + sn2 := &v2_1.Snippet{ + SnippetSPDXIdentifier: common.ElementID("Snippet20"), + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "File123").ElementRefID, + Ranges: []common.SnippetRange{{StartPointer: common.SnippetRangePointer{Offset: 268}, EndPointer: common.SnippetRangePointer{Offset: 309}}}, SnippetLicenseConcluded: "WTFPL", SnippetCopyrightText: "NOASSERTION", } - sns := map[spdx.ElementID]*spdx.Snippet2_1{ - spdx.ElementID("Snippet19"): sn1, - spdx.ElementID("Snippet20"): sn2, + sns := map[common.ElementID]*v2_1.Snippet{ + common.ElementID("Snippet19"): sn1, + common.ElementID("Snippet20"): sn2, } - f := &spdx.File2_1{ + f := &v2_1.File{ FileName: "/tmp/whatever.txt", - FileSPDXIdentifier: spdx.ElementID("File123"), - Checksums: []spdx.Checksum{ - {Algorithm: spdx.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, + FileSPDXIdentifier: common.ElementID("File123"), + Checksums: []common.Checksum{ + {Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, }, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{ @@ -177,11 +178,11 @@ SnippetCopyrightText: NOASSERTION } func TestSaver2_1FileOmitsOptionalFieldsIfEmpty(t *testing.T) { - f := &spdx.File2_1{ + f := &v2_1.File{ FileName: "/tmp/whatever.txt", - FileSPDXIdentifier: spdx.ElementID("File123"), - Checksums: []spdx.Checksum{ - {Algorithm: spdx.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, + FileSPDXIdentifier: common.ElementID("File123"), + Checksums: []common.Checksum{ + {Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, }, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{ @@ -215,11 +216,11 @@ FileCopyrightText: Copyright (c) Jane Doe } func TestSaver2_1FileWrapsCopyrightMultiLine(t *testing.T) { - f := &spdx.File2_1{ + f := &v2_1.File{ FileName: "/tmp/whatever.txt", - FileSPDXIdentifier: spdx.ElementID("File123"), - Checksums: []spdx.Checksum{ - {Algorithm: spdx.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, + FileSPDXIdentifier: common.ElementID("File123"), + Checksums: []common.Checksum{ + {Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, }, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{ @@ -255,11 +256,11 @@ Copyright (c) John Doe</text> } func TestSaver2_1FileWrapsCommentsAndNoticesMultiLine(t *testing.T) { - f := &spdx.File2_1{ + f := &v2_1.File{ FileName: "/tmp/whatever.txt", - FileSPDXIdentifier: spdx.ElementID("File123"), - Checksums: []spdx.Checksum{ - {Algorithm: spdx.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, + FileSPDXIdentifier: common.ElementID("File123"), + Checksums: []common.Checksum{ + {Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, }, LicenseComments: `this is a multi-line license comment`, diff --git a/tvsaver/saver2v1/save_other_license.go b/tvsaver/saver2v1/save_other_license.go index ea48b80..b30aecf 100644 --- a/tvsaver/saver2v1/save_other_license.go +++ b/tvsaver/saver2v1/save_other_license.go @@ -6,10 +6,10 @@ import ( "fmt" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderOtherLicense2_1(ol *spdx.OtherLicense2_1, w io.Writer) error { +func renderOtherLicense2_1(ol *v2_1.OtherLicense, w io.Writer) error { if ol.LicenseIdentifier != "" { fmt.Fprintf(w, "LicenseID: %s\n", ol.LicenseIdentifier) } diff --git a/tvsaver/saver2v1/save_other_license_test.go b/tvsaver/saver2v1/save_other_license_test.go index 5feb96e..46ef82c 100644 --- a/tvsaver/saver2v1/save_other_license_test.go +++ b/tvsaver/saver2v1/save_other_license_test.go @@ -6,12 +6,12 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Other License section Saver tests ===== func TestSaver2_1OtherLicenseSavesText(t *testing.T) { - ol := &spdx.OtherLicense2_1{ + ol := &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-1", ExtractedText: `License 1 text blah blah blah @@ -51,7 +51,7 @@ LicenseComment: this is a license comment } func TestSaver2_1OtherLicenseOmitsOptionalFieldsIfEmpty(t *testing.T) { - ol := &spdx.OtherLicense2_1{ + ol := &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-1", ExtractedText: `License 1 text blah blah blah diff --git a/tvsaver/saver2v1/save_package.go b/tvsaver/saver2v1/save_package.go index 24a468c..762876f 100644 --- a/tvsaver/saver2v1/save_package.go +++ b/tvsaver/saver2v1/save_package.go @@ -8,15 +8,16 @@ import ( "sort" "strings" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderPackage2_1(pkg *spdx.Package2_1, w io.Writer) error { +func renderPackage2_1(pkg *v2_1.Package, w io.Writer) error { if pkg.PackageName != "" { fmt.Fprintf(w, "PackageName: %s\n", pkg.PackageName) } if pkg.PackageSPDXIdentifier != "" { - fmt.Fprintf(w, "SPDXID: %s\n", spdx.RenderElementID(pkg.PackageSPDXIdentifier)) + fmt.Fprintf(w, "SPDXID: %s\n", common.RenderElementID(pkg.PackageSPDXIdentifier)) } if pkg.PackageVersion != "" { fmt.Fprintf(w, "PackageVersion: %s\n", pkg.PackageVersion) diff --git a/tvsaver/saver2v1/save_package_test.go b/tvsaver/saver2v1/save_package_test.go index 0f1541c..4939b3f 100644 --- a/tvsaver/saver2v1/save_package_test.go +++ b/tvsaver/saver2v1/save_package_test.go @@ -6,7 +6,8 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Package section Saver tests ===== @@ -17,7 +18,7 @@ func TestSaver2_1PackageSavesTextCombo1(t *testing.T) { // PackageVerificationCodeExcludedFile has string // NOTE, this is an entirely made up CPE and the format is likely invalid - per1 := &spdx.PackageExternalReference2_1{ + per1 := &v2_1.PackageExternalReference{ Category: "SECURITY", RefType: "cpe22Type", Locator: "cpe:/a:john_doe_inc:p1:0.1.0", @@ -25,7 +26,7 @@ func TestSaver2_1PackageSavesTextCombo1(t *testing.T) { } // NOTE, this is an entirely made up NPM - per2 := &spdx.PackageExternalReference2_1{ + per2 := &v2_1.PackageExternalReference{ Category: "PACKAGE-MANAGER", RefType: "npm", Locator: "p1@0.1.0", @@ -33,38 +34,38 @@ func TestSaver2_1PackageSavesTextCombo1(t *testing.T) { multi-line external ref comment`, } - per3 := &spdx.PackageExternalReference2_1{ + per3 := &v2_1.PackageExternalReference{ Category: "OTHER", RefType: "anything", Locator: "anything-without-spaces-can-go-here", // no ExternalRefComment for this one } - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageVersion: "0.1.0", PackageFileName: "p1-0.1.0-master.tar.gz", - PackageSupplier: &spdx.Supplier{SupplierType: "Organization", Supplier: "John Doe, Inc."}, - PackageOriginator: &spdx.Originator{Originator: "John Doe", OriginatorType: "Person"}, + PackageSupplier: &common.Supplier{SupplierType: "Organization", Supplier: "John Doe, Inc."}, + PackageOriginator: &common.Originator{Originator: "John Doe", OriginatorType: "Person"}, PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, - PackageVerificationCode: spdx.PackageVerificationCode{ + PackageVerificationCode: common.PackageVerificationCode{ Value: "0123456789abcdef0123456789abcdef01234567", ExcludedFiles: []string{"p1-0.1.0.spdx"}, }, - PackageChecksums: []spdx.Checksum{ + PackageChecksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c", }, { - Algorithm: spdx.SHA256, + Algorithm: common.SHA256, Value: "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd", }, { - Algorithm: spdx.MD5, + Algorithm: common.MD5, Value: "624c1abb3664f4b35547e7c73864ad24", }, }, @@ -82,7 +83,7 @@ multi-line external ref comment`, PackageSummary: "this is a summary comment", PackageDescription: "this is a description comment", PackageComment: "this is a comment comment", - PackageExternalReferences: []*spdx.PackageExternalReference2_1{ + PackageExternalReferences: []*v2_1.PackageExternalReference{ per1, per2, per3, @@ -143,28 +144,28 @@ func TestSaver2_1PackageSavesTextCombo2(t *testing.T) { // FilesAnalyzed true, IsFilesAnalyzedTagPresent false // PackageVerificationCodeExcludedFile is empty - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageVersion: "0.1.0", PackageFileName: "p1-0.1.0-master.tar.gz", - PackageSupplier: &spdx.Supplier{Supplier: "NOASSERTION"}, - PackageOriginator: &spdx.Originator{OriginatorType: "Organization", Originator: "John Doe, Inc."}, + PackageSupplier: &common.Supplier{Supplier: "NOASSERTION"}, + PackageOriginator: &common.Originator{OriginatorType: "Organization", Originator: "John Doe, Inc."}, PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: false, - PackageVerificationCode: spdx.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, - PackageChecksums: []spdx.Checksum{ + PackageVerificationCode: common.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, + PackageChecksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c", }, { - Algorithm: spdx.SHA256, + Algorithm: common.SHA256, Value: "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd", }, { - Algorithm: spdx.MD5, + Algorithm: common.MD5, Value: "624c1abb3664f4b35547e7c73864ad24", }, }, @@ -231,30 +232,30 @@ func TestSaver2_1PackageSavesTextCombo3(t *testing.T) { // FilesAnalyzed false, IsFilesAnalyzedTagPresent true // PackageVerificationCodeExcludedFile is empty - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageVersion: "0.1.0", PackageFileName: "p1-0.1.0-master.tar.gz", - PackageSupplier: &spdx.Supplier{Supplier: "John Doe", SupplierType: "Person"}, - PackageOriginator: &spdx.Originator{Originator: "NOASSERTION"}, + PackageSupplier: &common.Supplier{Supplier: "John Doe", SupplierType: "Person"}, + PackageOriginator: &common.Originator{Originator: "NOASSERTION"}, PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: false, IsFilesAnalyzedTagPresent: true, // NOTE that verification code MUST be omitted from output // since FilesAnalyzed is false - PackageVerificationCode: spdx.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, - PackageChecksums: []spdx.Checksum{ + PackageVerificationCode: common.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, + PackageChecksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c", }, { - Algorithm: spdx.SHA256, + Algorithm: common.SHA256, Value: "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd", }, { - Algorithm: spdx.MD5, + Algorithm: common.MD5, Value: "624c1abb3664f4b35547e7c73864ad24", }, }, @@ -315,9 +316,9 @@ PackageComment: this is a comment comment } func TestSaver2_1PackageSaveOmitsOptionalFieldsIfEmpty(t *testing.T) { - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: false, IsFilesAnalyzedTagPresent: true, @@ -361,12 +362,12 @@ PackageCopyrightText: Copyright (c) John Doe, Inc. } func TestSaver2_1PackageSavesFilesIfPresent(t *testing.T) { - f1 := &spdx.File2_1{ + f1 := &v2_1.File{ FileName: "/tmp/whatever1.txt", - FileSPDXIdentifier: spdx.ElementID("File1231"), - Checksums: []spdx.Checksum{ + FileSPDXIdentifier: common.ElementID("File1231"), + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c", }, }, @@ -375,12 +376,12 @@ func TestSaver2_1PackageSavesFilesIfPresent(t *testing.T) { FileCopyrightText: "Copyright (c) Jane Doe", } - f2 := &spdx.File2_1{ + f2 := &v2_1.File{ FileName: "/tmp/whatever2.txt", - FileSPDXIdentifier: spdx.ElementID("File1232"), - Checksums: []spdx.Checksum{ + FileSPDXIdentifier: common.ElementID("File1232"), + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983d", }, }, @@ -389,9 +390,9 @@ func TestSaver2_1PackageSavesFilesIfPresent(t *testing.T) { FileCopyrightText: "Copyright (c) John Doe", } - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: false, IsFilesAnalyzedTagPresent: true, @@ -407,7 +408,7 @@ func TestSaver2_1PackageSavesFilesIfPresent(t *testing.T) { }, PackageLicenseDeclared: "Apache-2.0 OR GPL-2.0-or-later", PackageCopyrightText: "Copyright (c) John Doe, Inc.", - Files: []*spdx.File2_1{ + Files: []*v2_1.File{ f1, f2, }, @@ -453,9 +454,9 @@ FileCopyrightText: Copyright (c) John Doe } func TestSaver2_1PackageWrapsCopyrightMultiLine(t *testing.T) { - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: false, IsFilesAnalyzedTagPresent: true, diff --git a/tvsaver/saver2v1/save_relationship.go b/tvsaver/saver2v1/save_relationship.go index aea48bc..01aa3dd 100644 --- a/tvsaver/saver2v1/save_relationship.go +++ b/tvsaver/saver2v1/save_relationship.go @@ -6,12 +6,13 @@ import ( "fmt" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderRelationship2_1(rln *spdx.Relationship2_1, w io.Writer) error { - rlnAStr := spdx.RenderDocElementID(rln.RefA) - rlnBStr := spdx.RenderDocElementID(rln.RefB) +func renderRelationship2_1(rln *v2_1.Relationship, w io.Writer) error { + rlnAStr := common.RenderDocElementID(rln.RefA) + rlnBStr := common.RenderDocElementID(rln.RefB) if rlnAStr != "SPDXRef-" && rlnBStr != "SPDXRef-" && rln.Relationship != "" { fmt.Fprintf(w, "Relationship: %s %s %s\n", rlnAStr, rln.Relationship, rlnBStr) } diff --git a/tvsaver/saver2v1/save_relationship_test.go b/tvsaver/saver2v1/save_relationship_test.go index 6fa03bd..886670b 100644 --- a/tvsaver/saver2v1/save_relationship_test.go +++ b/tvsaver/saver2v1/save_relationship_test.go @@ -6,14 +6,15 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Relationship section Saver tests ===== func TestSaver2_1RelationshipSavesText(t *testing.T) { - rln := &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "2"), + rln := &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "2"), Relationship: "DESCRIBES", RelationshipComment: "this is a comment", } @@ -39,9 +40,9 @@ RelationshipComment: this is a comment } func TestSaver2_1RelationshipOmitsOptionalFieldsIfEmpty(t *testing.T) { - rln := &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "2"), + rln := &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "2"), Relationship: "DESCRIBES", } @@ -64,9 +65,9 @@ func TestSaver2_1RelationshipOmitsOptionalFieldsIfEmpty(t *testing.T) { } func TestSaver2_1RelationshipWrapsCommentMultiLine(t *testing.T) { - rln := &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "2"), + rln := &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "2"), Relationship: "DESCRIBES", RelationshipComment: `this is a multi-line comment`, diff --git a/tvsaver/saver2v1/save_review.go b/tvsaver/saver2v1/save_review.go index 3193963..33511a3 100644 --- a/tvsaver/saver2v1/save_review.go +++ b/tvsaver/saver2v1/save_review.go @@ -6,10 +6,10 @@ import ( "fmt" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderReview2_1(rev *spdx.Review2_1, w io.Writer) error { +func renderReview2_1(rev *v2_1.Review, w io.Writer) error { if rev.Reviewer != "" && rev.ReviewerType != "" { fmt.Fprintf(w, "Reviewer: %s: %s\n", rev.ReviewerType, rev.Reviewer) } diff --git a/tvsaver/saver2v1/save_review_test.go b/tvsaver/saver2v1/save_review_test.go index 7421681..10d030b 100644 --- a/tvsaver/saver2v1/save_review_test.go +++ b/tvsaver/saver2v1/save_review_test.go @@ -6,12 +6,12 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Review section Saver tests ===== func TestSaver2_1ReviewSavesText(t *testing.T) { - rev := &spdx.Review2_1{ + rev := &v2_1.Review{ Reviewer: "John Doe", ReviewerType: "Person", ReviewDate: "2018-10-14T10:28:00Z", @@ -40,7 +40,7 @@ ReviewComment: this is a review comment } func TestSaver2_1ReviewOmitsOptionalFieldsIfEmpty(t *testing.T) { - rev := &spdx.Review2_1{ + rev := &v2_1.Review{ Reviewer: "John Doe", ReviewerType: "Person", ReviewDate: "2018-10-14T10:28:00Z", @@ -67,7 +67,7 @@ ReviewDate: 2018-10-14T10:28:00Z } func TestSaver2_1ReviewWrapsMultiLine(t *testing.T) { - rev := &spdx.Review2_1{ + rev := &v2_1.Review{ Reviewer: "John Doe", ReviewerType: "Person", ReviewDate: "2018-10-14T10:28:00Z", diff --git a/tvsaver/saver2v1/save_snippet.go b/tvsaver/saver2v1/save_snippet.go index 1399548..19c9323 100644 --- a/tvsaver/saver2v1/save_snippet.go +++ b/tvsaver/saver2v1/save_snippet.go @@ -6,14 +6,15 @@ import ( "fmt" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderSnippet2_1(sn *spdx.Snippet2_1, w io.Writer) error { +func renderSnippet2_1(sn *v2_1.Snippet, w io.Writer) error { if sn.SnippetSPDXIdentifier != "" { - fmt.Fprintf(w, "SnippetSPDXID: %s\n", spdx.RenderElementID(sn.SnippetSPDXIdentifier)) + fmt.Fprintf(w, "SnippetSPDXID: %s\n", common.RenderElementID(sn.SnippetSPDXIdentifier)) } - snFromFileIDStr := spdx.RenderElementID(sn.SnippetFromFileSPDXIdentifier) + snFromFileIDStr := common.RenderElementID(sn.SnippetFromFileSPDXIdentifier) if snFromFileIDStr != "" { fmt.Fprintf(w, "SnippetFromFileSPDXID: %s\n", snFromFileIDStr) } diff --git a/tvsaver/saver2v1/save_snippet_test.go b/tvsaver/saver2v1/save_snippet_test.go index fd6357e..3c9036a 100644 --- a/tvsaver/saver2v1/save_snippet_test.go +++ b/tvsaver/saver2v1/save_snippet_test.go @@ -6,22 +6,23 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Snippet section Saver tests ===== func TestSaver2_1SnippetSavesText(t *testing.T) { - sn := &spdx.Snippet2_1{ - SnippetSPDXIdentifier: spdx.ElementID("Snippet17"), - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File292").ElementRefID, - Ranges: []spdx.SnippetRange{ + sn := &v2_1.Snippet{ + SnippetSPDXIdentifier: common.ElementID("Snippet17"), + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "File292").ElementRefID, + Ranges: []common.SnippetRange{ { - StartPointer: spdx.SnippetRangePointer{LineNumber: 3}, - EndPointer: spdx.SnippetRangePointer{LineNumber: 8}, + StartPointer: common.SnippetRangePointer{LineNumber: 3}, + EndPointer: common.SnippetRangePointer{LineNumber: 8}, }, { - StartPointer: spdx.SnippetRangePointer{Offset: 17}, - EndPointer: spdx.SnippetRangePointer{Offset: 209}, + StartPointer: common.SnippetRangePointer{Offset: 17}, + EndPointer: common.SnippetRangePointer{Offset: 209}, }, }, SnippetLicenseConcluded: "GPL-2.0-or-later", @@ -65,13 +66,13 @@ SnippetName: from John's program } func TestSaver2_1SnippetOmitsOptionalFieldsIfEmpty(t *testing.T) { - sn := &spdx.Snippet2_1{ - SnippetSPDXIdentifier: spdx.ElementID("Snippet17"), - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File292").ElementRefID, - Ranges: []spdx.SnippetRange{ + sn := &v2_1.Snippet{ + SnippetSPDXIdentifier: common.ElementID("Snippet17"), + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "File292").ElementRefID, + Ranges: []common.SnippetRange{ { - StartPointer: spdx.SnippetRangePointer{Offset: 17}, - EndPointer: spdx.SnippetRangePointer{Offset: 209}, + StartPointer: common.SnippetRangePointer{Offset: 17}, + EndPointer: common.SnippetRangePointer{Offset: 209}, }, }, SnippetLicenseConcluded: "GPL-2.0-or-later", @@ -102,13 +103,13 @@ SnippetCopyrightText: Copyright (c) John Doe 20x6 } func TestSaver2_1SnippetWrapsCopyrightMultiline(t *testing.T) { - sn := &spdx.Snippet2_1{ - SnippetSPDXIdentifier: spdx.ElementID("Snippet17"), - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File292").ElementRefID, - Ranges: []spdx.SnippetRange{ + sn := &v2_1.Snippet{ + SnippetSPDXIdentifier: common.ElementID("Snippet17"), + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "File292").ElementRefID, + Ranges: []common.SnippetRange{ { - StartPointer: spdx.SnippetRangePointer{Offset: 17}, - EndPointer: spdx.SnippetRangePointer{Offset: 209}, + StartPointer: common.SnippetRangePointer{Offset: 17}, + EndPointer: common.SnippetRangePointer{Offset: 209}, }, }, SnippetLicenseConcluded: "GPL-2.0-or-later", |