aboutsummaryrefslogtreecommitdiff
path: root/builder
diff options
context:
space:
mode:
authorIan Ling <ian@iancaling.com>2022-04-08 08:52:57 -0700
committerIan Ling <ian@iancaling.com>2022-04-25 15:00:47 -0700
commit460cf54ece7eba418c50407ee35544c5d63588a7 (patch)
tree07ec7aaf51a92a1ae209e540f45241f990561919 /builder
parentfa24fac85dd550a3f815896241081a1246810d2c (diff)
downloadspdx-tools-460cf54ece7eba418c50407ee35544c5d63588a7.tar.gz
Overhaul structs, refactor JSON parser and saver
Signed-off-by: Ian Ling <ian@iancaling.com>
Diffstat (limited to 'builder')
-rw-r--r--builder/build.go27
-rw-r--r--builder/build_test.go337
-rw-r--r--builder/builder2v1/build_creation_info.go42
-rw-r--r--builder/builder2v1/build_creation_info_test.go112
-rw-r--r--builder/builder2v1/build_file.go19
-rw-r--r--builder/builder2v1/build_file_test.go33
-rw-r--r--builder/builder2v1/build_package.go4
-rw-r--r--builder/builder2v1/build_package_test.go47
-rw-r--r--builder/builder2v2/build_creation_info.go39
-rw-r--r--builder/builder2v2/build_creation_info_test.go112
-rw-r--r--builder/builder2v2/build_file.go14
-rw-r--r--builder/builder2v2/build_file_test.go12
-rw-r--r--builder/builder2v2/build_package.go4
-rw-r--r--builder/builder2v2/build_package_test.go26
14 files changed, 381 insertions, 447 deletions
diff --git a/builder/build.go b/builder/build.go
index f70f911..235e91d 100644
--- a/builder/build.go
+++ b/builder/build.go
@@ -5,6 +5,7 @@
package builder
import (
+ "fmt"
"github.com/spdx/tools-golang/builder/builder2v1"
"github.com/spdx/tools-golang/builder/builder2v2"
"github.com/spdx/tools-golang/spdx"
@@ -55,7 +56,7 @@ func Build2_1(packageName string, dirRoot string, config *Config2_1) (*spdx.Docu
return nil, err
}
- ci, err := builder2v1.BuildCreationInfoSection2_1(packageName, pkg.PackageVerificationCode, config.NamespacePrefix, config.CreatorType, config.Creator, config.TestValues)
+ ci, err := builder2v1.BuildCreationInfoSection2_1(config.CreatorType, config.Creator, config.TestValues)
if err != nil {
return nil, err
}
@@ -66,9 +67,14 @@ func Build2_1(packageName string, dirRoot string, config *Config2_1) (*spdx.Docu
}
doc := &spdx.Document2_1{
- CreationInfo: ci,
- Packages: map[spdx.ElementID]*spdx.Package2_1{pkg.PackageSPDXIdentifier: pkg},
- Relationships: []*spdx.Relationship2_1{rln},
+ SPDXVersion: "SPDX-2.1",
+ DataLicense: "CC0-1.0",
+ SPDXIdentifier: spdx.ElementID("DOCUMENT"),
+ DocumentName: packageName,
+ DocumentNamespace: fmt.Sprintf("%s%s-%s", config.NamespacePrefix, packageName, pkg.PackageVerificationCode),
+ CreationInfo: ci,
+ Packages: []*spdx.Package2_1{pkg},
+ Relationships: []*spdx.Relationship2_1{rln},
}
return doc, nil
@@ -119,7 +125,7 @@ func Build2_2(packageName string, dirRoot string, config *Config2_2) (*spdx.Docu
return nil, err
}
- ci, err := builder2v2.BuildCreationInfoSection2_2(packageName, pkg.PackageVerificationCode, config.NamespacePrefix, config.CreatorType, config.Creator, config.TestValues)
+ ci, err := builder2v2.BuildCreationInfoSection2_2(config.CreatorType, config.Creator, config.TestValues)
if err != nil {
return nil, err
}
@@ -130,9 +136,14 @@ func Build2_2(packageName string, dirRoot string, config *Config2_2) (*spdx.Docu
}
doc := &spdx.Document2_2{
- CreationInfo: ci,
- Packages: map[spdx.ElementID]*spdx.Package2_2{pkg.PackageSPDXIdentifier: pkg},
- Relationships: []*spdx.Relationship2_2{rln},
+ SPDXVersion: "SPDX-2.2",
+ DataLicense: "CC0-1.0",
+ SPDXIdentifier: spdx.ElementID("DOCUMENT"),
+ DocumentName: packageName,
+ DocumentNamespace: fmt.Sprintf("%s%s-%s", config.NamespacePrefix, packageName, pkg.PackageVerificationCode),
+ CreationInfo: ci,
+ Packages: []*spdx.Package2_2{pkg},
+ Relationships: []*spdx.Relationship2_2{rln},
}
return doc, nil
diff --git a/builder/build_test.go b/builder/build_test.go
index 62be42b..be4fd42 100644
--- a/builder/build_test.go
+++ b/builder/build_test.go
@@ -21,7 +21,7 @@ func TestBuild2_1CreatesDocument(t *testing.T) {
}
config.TestValues["Created"] = "2018-10-19T04:38:00Z"
- wantVerificationCode := "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"
+ wantVerificationCode := spdx.PackageVerificationCode{Value: "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"}
doc, err := Build2_1("project1", dirRoot, config)
if err != nil {
@@ -35,33 +35,30 @@ func TestBuild2_1CreatesDocument(t *testing.T) {
if doc.CreationInfo == nil {
t.Fatalf("expected non-nil CreationInfo section, got nil")
}
- if doc.CreationInfo.SPDXVersion != "SPDX-2.1" {
- t.Errorf("expected %s, got %s", "SPDX-2.1", doc.CreationInfo.SPDXVersion)
+ if doc.SPDXVersion != "SPDX-2.1" {
+ t.Errorf("expected %s, got %s", "SPDX-2.1", doc.SPDXVersion)
}
- if doc.CreationInfo.DataLicense != "CC0-1.0" {
- t.Errorf("expected %s, got %s", "CC0-1.0", doc.CreationInfo.DataLicense)
+ if doc.DataLicense != "CC0-1.0" {
+ t.Errorf("expected %s, got %s", "CC0-1.0", doc.DataLicense)
}
- if doc.CreationInfo.SPDXIdentifier != spdx.ElementID("DOCUMENT") {
- t.Errorf("expected %s, got %v", "DOCUMENT", doc.CreationInfo.SPDXIdentifier)
+ if doc.SPDXIdentifier != spdx.ElementID("DOCUMENT") {
+ t.Errorf("expected %s, got %v", "DOCUMENT", doc.SPDXIdentifier)
}
- if doc.CreationInfo.DocumentName != "project1" {
- t.Errorf("expected %s, got %s", "project1", doc.CreationInfo.DocumentName)
+ if doc.DocumentName != "project1" {
+ t.Errorf("expected %s, got %s", "project1", doc.DocumentName)
}
wantNamespace := fmt.Sprintf("https://github.com/swinslow/spdx-docs/spdx-go/testdata-project1-%s", wantVerificationCode)
- if doc.CreationInfo.DocumentNamespace != wantNamespace {
- t.Errorf("expected %s, got %s", wantNamespace, doc.CreationInfo.DocumentNamespace)
+ if doc.DocumentNamespace != wantNamespace {
+ t.Errorf("expected %s, got %s", wantNamespace, doc.DocumentNamespace)
}
- if len(doc.CreationInfo.CreatorPersons) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(doc.CreationInfo.CreatorPersons))
+ if len(doc.CreationInfo.Creators) != 2 {
+ t.Fatalf("expected %d, got %d", 2, len(doc.CreationInfo.Creators))
}
- if doc.CreationInfo.CreatorPersons[0] != "John Doe" {
- t.Errorf("expected %s, got %s", "John Doe", doc.CreationInfo.CreatorPersons[0])
+ if doc.CreationInfo.Creators[1].Creator != "John Doe" {
+ t.Errorf("expected %s, got %+v", "John Doe", doc.CreationInfo.Creators[1])
}
- if len(doc.CreationInfo.CreatorTools) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(doc.CreationInfo.CreatorTools))
- }
- if doc.CreationInfo.CreatorTools[0] != "github.com/spdx/tools-golang/builder" {
- t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", doc.CreationInfo.CreatorTools[0])
+ if doc.CreationInfo.Creators[0].Creator != "github.com/spdx/tools-golang/builder" {
+ t.Errorf("expected %s, got %+v", "github.com/spdx/tools-golang/builder", doc.CreationInfo.Creators[0])
}
if doc.CreationInfo.Created != "2018-10-19T04:38:00Z" {
t.Errorf("expected %s, got %s", "2018-10-19T04:38:00Z", doc.CreationInfo.Created)
@@ -74,7 +71,7 @@ func TestBuild2_1CreatesDocument(t *testing.T) {
if len(doc.Packages) != 1 {
t.Fatalf("expected %d, got %d", 1, len(doc.Packages))
}
- pkg := doc.Packages[spdx.ElementID("Package-project1")]
+ pkg := doc.Packages[0]
if pkg == nil {
t.Fatalf("expected non-nil pkg, got nil")
}
@@ -90,7 +87,7 @@ func TestBuild2_1CreatesDocument(t *testing.T) {
if pkg.FilesAnalyzed != true {
t.Errorf("expected %v, got %v", true, pkg.FilesAnalyzed)
}
- if pkg.PackageVerificationCode != wantVerificationCode {
+ if pkg.PackageVerificationCode.Value != wantVerificationCode.Value {
t.Errorf("expected %v, got %v", wantVerificationCode, pkg.PackageVerificationCode)
}
if pkg.PackageLicenseConcluded != "NOASSERTION" {
@@ -119,7 +116,7 @@ func TestBuild2_1CreatesDocument(t *testing.T) {
// emptyfile, file1, file3, folder/file4, lastfile
// check emptyfile.testdata.txt
- fileEmpty := pkg.Files[spdx.ElementID("File0")]
+ fileEmpty := pkg.Files[0]
if fileEmpty == nil {
t.Fatalf("expected non-nil file, got nil")
}
@@ -129,23 +126,32 @@ func TestBuild2_1CreatesDocument(t *testing.T) {
if fileEmpty.FileSPDXIdentifier != spdx.ElementID("File0") {
t.Errorf("expected %v, got %v", "File0", fileEmpty.FileSPDXIdentifier)
}
- if fileEmpty.FileChecksumSHA1 != "da39a3ee5e6b4b0d3255bfef95601890afd80709" {
- t.Errorf("expected %v, got %v", "da39a3ee5e6b4b0d3255bfef95601890afd80709", fileEmpty.FileChecksumSHA1)
- }
- if fileEmpty.FileChecksumSHA256 != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" {
- t.Errorf("expected %v, got %v", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", fileEmpty.FileChecksumSHA256)
- }
- if fileEmpty.FileChecksumMD5 != "d41d8cd98f00b204e9800998ecf8427e" {
- t.Errorf("expected %v, got %v", "d41d8cd98f00b204e9800998ecf8427e", fileEmpty.FileChecksumMD5)
+
+ for _, checksum := range fileEmpty.Checksums {
+ switch checksum.Algorithm {
+ case spdx.SHA1:
+ if checksum.Value != "da39a3ee5e6b4b0d3255bfef95601890afd80709" {
+ t.Errorf("expected %v, got %v", "da39a3ee5e6b4b0d3255bfef95601890afd80709", checksum.Value)
+ }
+ case spdx.SHA256:
+ if checksum.Value != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" {
+ t.Errorf("expected %v, got %v", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", checksum.Value)
+ }
+ case spdx.MD5:
+ if checksum.Value != "d41d8cd98f00b204e9800998ecf8427e" {
+ t.Errorf("expected %v, got %v", "d41d8cd98f00b204e9800998ecf8427e", checksum.Value)
+ }
+ }
}
+
if fileEmpty.LicenseConcluded != "NOASSERTION" {
t.Errorf("expected %v, got %v", "NOASSERTION", fileEmpty.LicenseConcluded)
}
- if len(fileEmpty.LicenseInfoInFile) != 1 {
- t.Errorf("expected %v, got %v", 1, len(fileEmpty.LicenseInfoInFile))
+ if len(fileEmpty.LicenseInfoInFiles) != 1 {
+ t.Errorf("expected %v, got %v", 1, len(fileEmpty.LicenseInfoInFiles))
} else {
- if fileEmpty.LicenseInfoInFile[0] != "NOASSERTION" {
- t.Errorf("expected %v, got %v", "NOASSERTION", fileEmpty.LicenseInfoInFile[0])
+ if fileEmpty.LicenseInfoInFiles[0] != "NOASSERTION" {
+ t.Errorf("expected %v, got %v", "NOASSERTION", fileEmpty.LicenseInfoInFiles[0])
}
}
if fileEmpty.FileCopyrightText != "NOASSERTION" {
@@ -153,7 +159,7 @@ func TestBuild2_1CreatesDocument(t *testing.T) {
}
// check file1.testdata.txt
- file1 := pkg.Files[spdx.ElementID("File1")]
+ file1 := pkg.Files[1]
if file1 == nil {
t.Fatalf("expected non-nil file, got nil")
}
@@ -163,23 +169,31 @@ func TestBuild2_1CreatesDocument(t *testing.T) {
if file1.FileSPDXIdentifier != spdx.ElementID("File1") {
t.Errorf("expected %v, got %v", "File1", file1.FileSPDXIdentifier)
}
- if file1.FileChecksumSHA1 != "024f870eb6323f532515f7a09d5646a97083b819" {
- t.Errorf("expected %v, got %v", "024f870eb6323f532515f7a09d5646a97083b819", file1.FileChecksumSHA1)
- }
- if file1.FileChecksumSHA256 != "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf" {
- t.Errorf("expected %v, got %v", "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf", file1.FileChecksumSHA256)
- }
- if file1.FileChecksumMD5 != "37c8208479dfe42d2bb29debd6e32d4a" {
- t.Errorf("expected %v, got %v", "37c8208479dfe42d2bb29debd6e32d4a", file1.FileChecksumMD5)
+
+ for _, checksum := range file1.Checksums {
+ switch checksum.Algorithm {
+ case spdx.SHA1:
+ if checksum.Value != "024f870eb6323f532515f7a09d5646a97083b819" {
+ t.Errorf("expected %v, got %v", "024f870eb6323f532515f7a09d5646a97083b819", checksum.Value)
+ }
+ case spdx.SHA256:
+ if checksum.Value != "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf" {
+ t.Errorf("expected %v, got %v", "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf", checksum.Value)
+ }
+ case spdx.MD5:
+ if checksum.Value != "37c8208479dfe42d2bb29debd6e32d4a" {
+ t.Errorf("expected %v, got %v", "37c8208479dfe42d2bb29debd6e32d4a", checksum.Value)
+ }
+ }
}
if file1.LicenseConcluded != "NOASSERTION" {
t.Errorf("expected %v, got %v", "NOASSERTION", file1.LicenseConcluded)
}
- if len(file1.LicenseInfoInFile) != 1 {
- t.Errorf("expected %v, got %v", 1, len(file1.LicenseInfoInFile))
+ if len(file1.LicenseInfoInFiles) != 1 {
+ t.Errorf("expected %v, got %v", 1, len(file1.LicenseInfoInFiles))
} else {
- if file1.LicenseInfoInFile[0] != "NOASSERTION" {
- t.Errorf("expected %v, got %v", "NOASSERTION", file1.LicenseInfoInFile[0])
+ if file1.LicenseInfoInFiles[0] != "NOASSERTION" {
+ t.Errorf("expected %v, got %v", "NOASSERTION", file1.LicenseInfoInFiles[0])
}
}
if file1.FileCopyrightText != "NOASSERTION" {
@@ -187,7 +201,7 @@ func TestBuild2_1CreatesDocument(t *testing.T) {
}
// check file3.testdata.txt
- file3 := pkg.Files[spdx.ElementID("File2")]
+ file3 := pkg.Files[2]
if file3 == nil {
t.Fatalf("expected non-nil file, got nil")
}
@@ -197,23 +211,31 @@ func TestBuild2_1CreatesDocument(t *testing.T) {
if file3.FileSPDXIdentifier != spdx.ElementID("File2") {
t.Errorf("expected %v, got %v", "File2", file3.FileSPDXIdentifier)
}
- if file3.FileChecksumSHA1 != "a46114b70e163614f01c64adf44cdd438f158fce" {
- t.Errorf("expected %v, got %v", "a46114b70e163614f01c64adf44cdd438f158fce", file3.FileChecksumSHA1)
- }
- if file3.FileChecksumSHA256 != "9fc181b9892720a15df1a1e561860318db40621bd4040ccdf18e110eb01d04b4" {
- t.Errorf("expected %v, got %v", "9fc181b9892720a15df1a1e561860318db40621bd4040ccdf18e110eb01d04b4", file3.FileChecksumSHA256)
- }
- if file3.FileChecksumMD5 != "3e02d3ab9c58eec6911dbba37570934f" {
- t.Errorf("expected %v, got %v", "3e02d3ab9c58eec6911dbba37570934f", file3.FileChecksumMD5)
+
+ for _, checksum := range file3.Checksums {
+ switch checksum.Algorithm {
+ case spdx.SHA1:
+ if checksum.Value != "a46114b70e163614f01c64adf44cdd438f158fce" {
+ t.Errorf("expected %v, got %v", "a46114b70e163614f01c64adf44cdd438f158fce", checksum.Value)
+ }
+ case spdx.SHA256:
+ if checksum.Value != "9fc181b9892720a15df1a1e561860318db40621bd4040ccdf18e110eb01d04b4" {
+ t.Errorf("expected %v, got %v", "9fc181b9892720a15df1a1e561860318db40621bd4040ccdf18e110eb01d04b4", checksum.Value)
+ }
+ case spdx.MD5:
+ if checksum.Value != "3e02d3ab9c58eec6911dbba37570934f" {
+ t.Errorf("expected %v, got %v", "3e02d3ab9c58eec6911dbba37570934f", checksum.Value)
+ }
+ }
}
if file3.LicenseConcluded != "NOASSERTION" {
t.Errorf("expected %v, got %v", "NOASSERTION", file3.LicenseConcluded)
}
- if len(file3.LicenseInfoInFile) != 1 {
- t.Errorf("expected %v, got %v", 1, len(file3.LicenseInfoInFile))
+ if len(file3.LicenseInfoInFiles) != 1 {
+ t.Errorf("expected %v, got %v", 1, len(file3.LicenseInfoInFiles))
} else {
- if file3.LicenseInfoInFile[0] != "NOASSERTION" {
- t.Errorf("expected %v, got %v", "NOASSERTION", file3.LicenseInfoInFile[0])
+ if file3.LicenseInfoInFiles[0] != "NOASSERTION" {
+ t.Errorf("expected %v, got %v", "NOASSERTION", file3.LicenseInfoInFiles[0])
}
}
if file3.FileCopyrightText != "NOASSERTION" {
@@ -221,7 +243,7 @@ func TestBuild2_1CreatesDocument(t *testing.T) {
}
// check folder1/file4.testdata.txt
- file4 := pkg.Files[spdx.ElementID("File3")]
+ file4 := pkg.Files[3]
if file4 == nil {
t.Fatalf("expected non-nil file, got nil")
}
@@ -231,23 +253,31 @@ func TestBuild2_1CreatesDocument(t *testing.T) {
if file4.FileSPDXIdentifier != spdx.ElementID("File3") {
t.Errorf("expected %v, got %v", "File3", file4.FileSPDXIdentifier)
}
- if file4.FileChecksumSHA1 != "e623d7d7d782a7c8323c4d436acee4afab34320f" {
- t.Errorf("expected %v, got %v", "e623d7d7d782a7c8323c4d436acee4afab34320f", file4.FileChecksumSHA1)
- }
- if file4.FileChecksumSHA256 != "574fa42c5e0806c0f8906a44884166540206f021527729407cd5326838629c59" {
- t.Errorf("expected %v, got %v", "574fa42c5e0806c0f8906a44884166540206f021527729407cd5326838629c59", file4.FileChecksumSHA256)
- }
- if file4.FileChecksumMD5 != "96e6a25d35df5b1c477710ef4d0c7210" {
- t.Errorf("expected %v, got %v", "96e6a25d35df5b1c477710ef4d0c7210", file4.FileChecksumMD5)
+
+ for _, checksum := range file4.Checksums {
+ switch checksum.Algorithm {
+ case spdx.SHA1:
+ if checksum.Value != "e623d7d7d782a7c8323c4d436acee4afab34320f" {
+ t.Errorf("expected %v, got %v", "e623d7d7d782a7c8323c4d436acee4afab34320f", checksum.Value)
+ }
+ case spdx.SHA256:
+ if checksum.Value != "574fa42c5e0806c0f8906a44884166540206f021527729407cd5326838629c59" {
+ t.Errorf("expected %v, got %v", "574fa42c5e0806c0f8906a44884166540206f021527729407cd5326838629c59", checksum.Value)
+ }
+ case spdx.MD5:
+ if checksum.Value != "96e6a25d35df5b1c477710ef4d0c7210" {
+ t.Errorf("expected %v, got %v", "96e6a25d35df5b1c477710ef4d0c7210", checksum.Value)
+ }
+ }
}
if file4.LicenseConcluded != "NOASSERTION" {
t.Errorf("expected %v, got %v", "NOASSERTION", file4.LicenseConcluded)
}
- if len(file4.LicenseInfoInFile) != 1 {
- t.Errorf("expected %v, got %v", 1, len(file4.LicenseInfoInFile))
+ if len(file4.LicenseInfoInFiles) != 1 {
+ t.Errorf("expected %v, got %v", 1, len(file4.LicenseInfoInFiles))
} else {
- if file4.LicenseInfoInFile[0] != "NOASSERTION" {
- t.Errorf("expected %v, got %v", "NOASSERTION", file4.LicenseInfoInFile[0])
+ if file4.LicenseInfoInFiles[0] != "NOASSERTION" {
+ t.Errorf("expected %v, got %v", "NOASSERTION", file4.LicenseInfoInFiles[0])
}
}
if file4.FileCopyrightText != "NOASSERTION" {
@@ -255,7 +285,7 @@ func TestBuild2_1CreatesDocument(t *testing.T) {
}
// check lastfile.testdata.txt
- lastfile := pkg.Files[spdx.ElementID("File4")]
+ lastfile := pkg.Files[4]
if lastfile == nil {
t.Fatalf("expected non-nil file, got nil")
}
@@ -265,23 +295,31 @@ func TestBuild2_1CreatesDocument(t *testing.T) {
if lastfile.FileSPDXIdentifier != spdx.ElementID("File4") {
t.Errorf("expected %v, got %v", "File4", lastfile.FileSPDXIdentifier)
}
- if lastfile.FileChecksumSHA1 != "26d6221d682d9ba59116f9753a701f34271c8ce1" {
- t.Errorf("expected %v, got %v", "26d6221d682d9ba59116f9753a701f34271c8ce1", lastfile.FileChecksumSHA1)
- }
- if lastfile.FileChecksumSHA256 != "0a4bdaf990e9b330ff72022dd78110ae98b60e08337cf2105b89856373416805" {
- t.Errorf("expected %v, got %v", "0a4bdaf990e9b330ff72022dd78110ae98b60e08337cf2105b89856373416805", lastfile.FileChecksumSHA256)
- }
- if lastfile.FileChecksumMD5 != "f60baa793870d9085461ad6bbab50b7f" {
- t.Errorf("expected %v, got %v", "f60baa793870d9085461ad6bbab50b7f", lastfile.FileChecksumMD5)
+
+ for _, checksum := range lastfile.Checksums {
+ switch checksum.Algorithm {
+ case spdx.SHA1:
+ if checksum.Value != "26d6221d682d9ba59116f9753a701f34271c8ce1" {
+ t.Errorf("expected %v, got %v", "26d6221d682d9ba59116f9753a701f34271c8ce1", checksum.Value)
+ }
+ case spdx.SHA256:
+ if checksum.Value != "0a4bdaf990e9b330ff72022dd78110ae98b60e08337cf2105b89856373416805" {
+ t.Errorf("expected %v, got %v", "0a4bdaf990e9b330ff72022dd78110ae98b60e08337cf2105b89856373416805", checksum.Value)
+ }
+ case spdx.MD5:
+ if checksum.Value != "f60baa793870d9085461ad6bbab50b7f" {
+ t.Errorf("expected %v, got %v", "f60baa793870d9085461ad6bbab50b7f", checksum.Value)
+ }
+ }
}
if lastfile.LicenseConcluded != "NOASSERTION" {
t.Errorf("expected %v, got %v", "NOASSERTION", lastfile.LicenseConcluded)
}
- if len(lastfile.LicenseInfoInFile) != 1 {
- t.Errorf("expected %v, got %v", 1, len(lastfile.LicenseInfoInFile))
+ if len(lastfile.LicenseInfoInFiles) != 1 {
+ t.Errorf("expected %v, got %v", 1, len(lastfile.LicenseInfoInFiles))
} else {
- if lastfile.LicenseInfoInFile[0] != "NOASSERTION" {
- t.Errorf("expected %v, got %v", "NOASSERTION", lastfile.LicenseInfoInFile[0])
+ if lastfile.LicenseInfoInFiles[0] != "NOASSERTION" {
+ t.Errorf("expected %v, got %v", "NOASSERTION", lastfile.LicenseInfoInFiles[0])
}
}
if lastfile.FileCopyrightText != "NOASSERTION" {
@@ -343,7 +381,7 @@ func TestBuild2_1CanIgnoreFiles(t *testing.T) {
if err != nil {
t.Errorf("expected nil error, got %v", err)
}
- pkg := doc.Packages[spdx.ElementID("Package-project1")]
+ pkg := doc.Packages[0]
if pkg == nil {
t.Fatalf("expected non-nil pkg, got nil")
}
@@ -352,31 +390,31 @@ func TestBuild2_1CanIgnoreFiles(t *testing.T) {
}
want := "./dontscan.txt"
- got := pkg.Files[spdx.ElementID("File0")].FileName
+ got := pkg.Files[0].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./keep/keep.txt"
- got = pkg.Files[spdx.ElementID("File1")].FileName
+ got = pkg.Files[1].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./keep.txt"
- got = pkg.Files[spdx.ElementID("File2")].FileName
+ got = pkg.Files[2].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./subdir/keep/dontscan.txt"
- got = pkg.Files[spdx.ElementID("File3")].FileName
+ got = pkg.Files[3].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./subdir/keep/keep.txt"
- got = pkg.Files[spdx.ElementID("File4")].FileName
+ got = pkg.Files[4].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
@@ -394,7 +432,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
}
config.TestValues["Created"] = "2018-10-19T04:38:00Z"
- wantVerificationCode := "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"
+ wantVerificationCode := spdx.PackageVerificationCode{Value: "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"}
doc, err := Build2_2("project1", dirRoot, config)
if err != nil {
@@ -408,33 +446,30 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
if doc.CreationInfo == nil {
t.Fatalf("expected non-nil CreationInfo section, got nil")
}
- if doc.CreationInfo.SPDXVersion != "SPDX-2.2" {
- t.Errorf("expected %s, got %s", "SPDX-2.2", doc.CreationInfo.SPDXVersion)
+ if doc.SPDXVersion != "SPDX-2.2" {
+ t.Errorf("expected %s, got %s", "SPDX-2.2", doc.SPDXVersion)
}
- if doc.CreationInfo.DataLicense != "CC0-1.0" {
- t.Errorf("expected %s, got %s", "CC0-1.0", doc.CreationInfo.DataLicense)
+ if doc.DataLicense != "CC0-1.0" {
+ t.Errorf("expected %s, got %s", "CC0-1.0", doc.DataLicense)
}
- if doc.CreationInfo.SPDXIdentifier != spdx.ElementID("DOCUMENT") {
- t.Errorf("expected %s, got %v", "DOCUMENT", doc.CreationInfo.SPDXIdentifier)
+ if doc.SPDXIdentifier != spdx.ElementID("DOCUMENT") {
+ t.Errorf("expected %s, got %v", "DOCUMENT", doc.SPDXIdentifier)
}
- if doc.CreationInfo.DocumentName != "project1" {
- t.Errorf("expected %s, got %s", "project1", doc.CreationInfo.DocumentName)
+ if doc.DocumentName != "project1" {
+ t.Errorf("expected %s, got %s", "project1", doc.DocumentName)
}
wantNamespace := fmt.Sprintf("https://github.com/swinslow/spdx-docs/spdx-go/testdata-project1-%s", wantVerificationCode)
- if doc.CreationInfo.DocumentNamespace != wantNamespace {
- t.Errorf("expected %s, got %s", wantNamespace, doc.CreationInfo.DocumentNamespace)
- }
- if len(doc.CreationInfo.CreatorPersons) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(doc.CreationInfo.CreatorPersons))
+ if doc.DocumentNamespace != wantNamespace {
+ t.Errorf("expected %s, got %s", wantNamespace, doc.DocumentNamespace)
}
- if doc.CreationInfo.CreatorPersons[0] != "John Doe" {
- t.Errorf("expected %s, got %s", "John Doe", doc.CreationInfo.CreatorPersons[0])
+ if len(doc.CreationInfo.Creators) != 2 {
+ t.Fatalf("expected %d, got %d", 2, len(doc.CreationInfo.Creators))
}
- if len(doc.CreationInfo.CreatorTools) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(doc.CreationInfo.CreatorTools))
+ if doc.CreationInfo.Creators[1].Creator != "John Doe" {
+ t.Errorf("expected %s, got %+v", "John Doe", doc.CreationInfo.Creators[1])
}
- if doc.CreationInfo.CreatorTools[0] != "github.com/spdx/tools-golang/builder" {
- t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", doc.CreationInfo.CreatorTools[0])
+ if doc.CreationInfo.Creators[0].Creator != "github.com/spdx/tools-golang/builder" {
+ t.Errorf("expected %s, got %+v", "github.com/spdx/tools-golang/builder", doc.CreationInfo.Creators[0])
}
if doc.CreationInfo.Created != "2018-10-19T04:38:00Z" {
t.Errorf("expected %s, got %s", "2018-10-19T04:38:00Z", doc.CreationInfo.Created)
@@ -447,7 +482,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
if len(doc.Packages) != 1 {
t.Fatalf("expected %d, got %d", 1, len(doc.Packages))
}
- pkg := doc.Packages[spdx.ElementID("Package-project1")]
+ pkg := doc.Packages[0]
if pkg == nil {
t.Fatalf("expected non-nil pkg, got nil")
}
@@ -463,7 +498,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
if pkg.FilesAnalyzed != true {
t.Errorf("expected %v, got %v", true, pkg.FilesAnalyzed)
}
- if pkg.PackageVerificationCode != wantVerificationCode {
+ if pkg.PackageVerificationCode.Value != wantVerificationCode.Value {
t.Errorf("expected %v, got %v", wantVerificationCode, pkg.PackageVerificationCode)
}
if pkg.PackageLicenseConcluded != "NOASSERTION" {
@@ -492,7 +527,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
// emptyfile, file1, file3, folder/file4, lastfile
// check emptyfile.testdata.txt
- fileEmpty := pkg.Files[spdx.ElementID("File0")]
+ fileEmpty := pkg.Files[0]
if fileEmpty == nil {
t.Fatalf("expected non-nil file, got nil")
}
@@ -502,7 +537,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
if fileEmpty.FileSPDXIdentifier != spdx.ElementID("File0") {
t.Errorf("expected %v, got %v", "File0", fileEmpty.FileSPDXIdentifier)
}
- for _, checksum := range fileEmpty.FileChecksums {
+ for _, checksum := range fileEmpty.Checksums {
switch checksum.Algorithm {
case spdx.SHA1:
if checksum.Value != "da39a3ee5e6b4b0d3255bfef95601890afd80709" {
@@ -521,11 +556,11 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
if fileEmpty.LicenseConcluded != "NOASSERTION" {
t.Errorf("expected %v, got %v", "NOASSERTION", fileEmpty.LicenseConcluded)
}
- if len(fileEmpty.LicenseInfoInFile) != 1 {
- t.Errorf("expected %v, got %v", 1, len(fileEmpty.LicenseInfoInFile))
+ if len(fileEmpty.LicenseInfoInFiles) != 1 {
+ t.Errorf("expected %v, got %v", 1, len(fileEmpty.LicenseInfoInFiles))
} else {
- if fileEmpty.LicenseInfoInFile[0] != "NOASSERTION" {
- t.Errorf("expected %v, got %v", "NOASSERTION", fileEmpty.LicenseInfoInFile[0])
+ if fileEmpty.LicenseInfoInFiles[0] != "NOASSERTION" {
+ t.Errorf("expected %v, got %v", "NOASSERTION", fileEmpty.LicenseInfoInFiles[0])
}
}
if fileEmpty.FileCopyrightText != "NOASSERTION" {
@@ -533,7 +568,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
}
// check file1.testdata.txt
- file1 := pkg.Files[spdx.ElementID("File1")]
+ file1 := pkg.Files[1]
if file1 == nil {
t.Fatalf("expected non-nil file, got nil")
}
@@ -543,7 +578,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
if file1.FileSPDXIdentifier != spdx.ElementID("File1") {
t.Errorf("expected %v, got %v", "File1", file1.FileSPDXIdentifier)
}
- for _, checksum := range file1.FileChecksums {
+ for _, checksum := range file1.Checksums {
switch checksum.Algorithm {
case spdx.SHA1:
if checksum.Value != "024f870eb6323f532515f7a09d5646a97083b819" {
@@ -562,11 +597,11 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
if file1.LicenseConcluded != "NOASSERTION" {
t.Errorf("expected %v, got %v", "NOASSERTION", file1.LicenseConcluded)
}
- if len(file1.LicenseInfoInFile) != 1 {
- t.Errorf("expected %v, got %v", 1, len(file1.LicenseInfoInFile))
+ if len(file1.LicenseInfoInFiles) != 1 {
+ t.Errorf("expected %v, got %v", 1, len(file1.LicenseInfoInFiles))
} else {
- if file1.LicenseInfoInFile[0] != "NOASSERTION" {
- t.Errorf("expected %v, got %v", "NOASSERTION", file1.LicenseInfoInFile[0])
+ if file1.LicenseInfoInFiles[0] != "NOASSERTION" {
+ t.Errorf("expected %v, got %v", "NOASSERTION", file1.LicenseInfoInFiles[0])
}
}
if file1.FileCopyrightText != "NOASSERTION" {
@@ -574,7 +609,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
}
// check file3.testdata.txt
- file3 := pkg.Files[spdx.ElementID("File2")]
+ file3 := pkg.Files[2]
if file3 == nil {
t.Fatalf("expected non-nil file, got nil")
}
@@ -584,7 +619,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
if file3.FileSPDXIdentifier != spdx.ElementID("File2") {
t.Errorf("expected %v, got %v", "File2", file3.FileSPDXIdentifier)
}
- for _, checksum := range file3.FileChecksums {
+ for _, checksum := range file3.Checksums {
switch checksum.Algorithm {
case spdx.SHA1:
if checksum.Value != "a46114b70e163614f01c64adf44cdd438f158fce" {
@@ -603,11 +638,11 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
if file3.LicenseConcluded != "NOASSERTION" {
t.Errorf("expected %v, got %v", "NOASSERTION", file3.LicenseConcluded)
}
- if len(file3.LicenseInfoInFile) != 1 {
- t.Errorf("expected %v, got %v", 1, len(file3.LicenseInfoInFile))
+ if len(file3.LicenseInfoInFiles) != 1 {
+ t.Errorf("expected %v, got %v", 1, len(file3.LicenseInfoInFiles))
} else {
- if file3.LicenseInfoInFile[0] != "NOASSERTION" {
- t.Errorf("expected %v, got %v", "NOASSERTION", file3.LicenseInfoInFile[0])
+ if file3.LicenseInfoInFiles[0] != "NOASSERTION" {
+ t.Errorf("expected %v, got %v", "NOASSERTION", file3.LicenseInfoInFiles[0])
}
}
if file3.FileCopyrightText != "NOASSERTION" {
@@ -615,7 +650,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
}
// check folder1/file4.testdata.txt
- file4 := pkg.Files[spdx.ElementID("File3")]
+ file4 := pkg.Files[3]
if file4 == nil {
t.Fatalf("expected non-nil file, got nil")
}
@@ -625,7 +660,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
if file4.FileSPDXIdentifier != spdx.ElementID("File3") {
t.Errorf("expected %v, got %v", "File3", file4.FileSPDXIdentifier)
}
- for _, checksum := range file4.FileChecksums {
+ for _, checksum := range file4.Checksums {
switch checksum.Algorithm {
case spdx.SHA1:
if checksum.Value != "e623d7d7d782a7c8323c4d436acee4afab34320f" {
@@ -644,11 +679,11 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
if file4.LicenseConcluded != "NOASSERTION" {
t.Errorf("expected %v, got %v", "NOASSERTION", file4.LicenseConcluded)
}
- if len(file4.LicenseInfoInFile) != 1 {
- t.Errorf("expected %v, got %v", 1, len(file4.LicenseInfoInFile))
+ if len(file4.LicenseInfoInFiles) != 1 {
+ t.Errorf("expected %v, got %v", 1, len(file4.LicenseInfoInFiles))
} else {
- if file4.LicenseInfoInFile[0] != "NOASSERTION" {
- t.Errorf("expected %v, got %v", "NOASSERTION", file4.LicenseInfoInFile[0])
+ if file4.LicenseInfoInFiles[0] != "NOASSERTION" {
+ t.Errorf("expected %v, got %v", "NOASSERTION", file4.LicenseInfoInFiles[0])
}
}
if file4.FileCopyrightText != "NOASSERTION" {
@@ -656,7 +691,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
}
// check lastfile.testdata.txt
- lastfile := pkg.Files[spdx.ElementID("File4")]
+ lastfile := pkg.Files[4]
if lastfile == nil {
t.Fatalf("expected non-nil file, got nil")
}
@@ -666,7 +701,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
if lastfile.FileSPDXIdentifier != spdx.ElementID("File4") {
t.Errorf("expected %v, got %v", "File4", lastfile.FileSPDXIdentifier)
}
- for _, checksum := range lastfile.FileChecksums {
+ for _, checksum := range lastfile.Checksums {
switch checksum.Algorithm {
case spdx.SHA1:
if checksum.Value != "26d6221d682d9ba59116f9753a701f34271c8ce1" {
@@ -685,11 +720,11 @@ func TestBuild2_2CreatesDocument(t *testing.T) {
if lastfile.LicenseConcluded != "NOASSERTION" {
t.Errorf("expected %v, got %v", "NOASSERTION", lastfile.LicenseConcluded)
}
- if len(lastfile.LicenseInfoInFile) != 1 {
- t.Errorf("expected %v, got %v", 1, len(lastfile.LicenseInfoInFile))
+ if len(lastfile.LicenseInfoInFiles) != 1 {
+ t.Errorf("expected %v, got %v", 1, len(lastfile.LicenseInfoInFiles))
} else {
- if lastfile.LicenseInfoInFile[0] != "NOASSERTION" {
- t.Errorf("expected %v, got %v", "NOASSERTION", lastfile.LicenseInfoInFile[0])
+ if lastfile.LicenseInfoInFiles[0] != "NOASSERTION" {
+ t.Errorf("expected %v, got %v", "NOASSERTION", lastfile.LicenseInfoInFiles[0])
}
}
if lastfile.FileCopyrightText != "NOASSERTION" {
@@ -751,7 +786,7 @@ func TestBuild2_2CanIgnoreFiles(t *testing.T) {
if err != nil {
t.Errorf("expected nil error, got %v", err)
}
- pkg := doc.Packages[spdx.ElementID("Package-project1")]
+ pkg := doc.Packages[0]
if pkg == nil {
t.Fatalf("expected non-nil pkg, got nil")
}
@@ -760,31 +795,31 @@ func TestBuild2_2CanIgnoreFiles(t *testing.T) {
}
want := "./dontscan.txt"
- got := pkg.Files[spdx.ElementID("File0")].FileName
+ got := pkg.Files[0].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./keep/keep.txt"
- got = pkg.Files[spdx.ElementID("File1")].FileName
+ got = pkg.Files[1].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./keep.txt"
- got = pkg.Files[spdx.ElementID("File2")].FileName
+ got = pkg.Files[2].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./subdir/keep/dontscan.txt"
- got = pkg.Files[spdx.ElementID("File3")].FileName
+ got = pkg.Files[3].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./subdir/keep/keep.txt"
- got = pkg.Files[spdx.ElementID("File4")].FileName
+ got = pkg.Files[4].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
diff --git a/builder/builder2v1/build_creation_info.go b/builder/builder2v1/build_creation_info.go
index 1d8c77f..c838b92 100644
--- a/builder/builder2v1/build_creation_info.go
+++ b/builder/builder2v1/build_creation_info.go
@@ -3,7 +3,6 @@
package builder2v1
import (
- "fmt"
"time"
"github.com/spdx/tools-golang/spdx"
@@ -11,29 +10,21 @@ import (
// BuildCreationInfoSection2_1 creates an SPDX Package (version 2.1), returning that
// package or error if any is encountered. Arguments:
-// - packageName: name of package / directory
-// - code: verification code from Package
-// - namespacePrefix: prefix for DocumentNamespace (packageName and code will be added)
// - creatorType: one of Person, Organization or Tool
// - creator: creator string
// - testValues: for testing only; call with nil when using in production
-func BuildCreationInfoSection2_1(packageName string, code string, namespacePrefix string, creatorType string, creator string, testValues map[string]string) (*spdx.CreationInfo2_1, error) {
+func BuildCreationInfoSection2_1(creatorType string, creator string, testValues map[string]string) (*spdx.CreationInfo2_1, error) {
// build creator slices
- cPersons := []string{}
- cOrganizations := []string{}
- cTools := []string{}
- // add builder as a tool
- cTools = append(cTools, "github.com/spdx/tools-golang/builder")
-
- switch creatorType {
- case "Person":
- cPersons = append(cPersons, creator)
- case "Organization":
- cOrganizations = append(cOrganizations, creator)
- case "Tool":
- cTools = append(cTools, creator)
- default:
- cPersons = append(cPersons, creator)
+ creators := []spdx.Creator{
+ // add builder as a tool
+ {
+ Creator: "github.com/spdx/tools-golang/builder",
+ CreatorType: "Tool",
+ },
+ {
+ Creator: creator,
+ CreatorType: creatorType,
+ },
}
// use test Created time if passing test values
@@ -45,15 +36,8 @@ func BuildCreationInfoSection2_1(packageName string, code string, namespacePrefi
}
ci := &spdx.CreationInfo2_1{
- SPDXVersion: "SPDX-2.1",
- DataLicense: "CC0-1.0",
- SPDXIdentifier: spdx.ElementID("DOCUMENT"),
- DocumentName: packageName,
- DocumentNamespace: fmt.Sprintf("%s%s-%s", namespacePrefix, packageName, code),
- CreatorPersons: cPersons,
- CreatorOrganizations: cOrganizations,
- CreatorTools: cTools,
- Created: created,
+ Creators: creators,
+ Created: created,
}
return ci, nil
}
diff --git a/builder/builder2v1/build_creation_info_test.go b/builder/builder2v1/build_creation_info_test.go
index b45f2f0..9684fde 100644
--- a/builder/builder2v1/build_creation_info_test.go
+++ b/builder/builder2v1/build_creation_info_test.go
@@ -3,24 +3,17 @@
package builder2v1
import (
- "fmt"
"testing"
-
- "github.com/spdx/tools-golang/spdx"
)
// ===== CreationInfo section builder tests =====
func TestBuilder2_1CanBuildCreationInfoSection(t *testing.T) {
-
- namespacePrefix := "https://github.com/swinslow/spdx-docs/spdx-go/testdata-whatever-"
creatorType := "Organization"
creator := "Jane Doe LLC"
testValues := make(map[string]string)
testValues["Created"] = "2018-10-20T16:48:00Z"
- packageName := "project1"
- verificationCode := "TESTCODE"
- ci, err := BuildCreationInfoSection2_1(packageName, verificationCode, namespacePrefix, creatorType, creator, testValues)
+ ci, err := BuildCreationInfoSection2_1(creatorType, creator, testValues)
if err != nil {
t.Fatalf("expected nil error, got %v", err)
}
@@ -28,36 +21,14 @@ func TestBuilder2_1CanBuildCreationInfoSection(t *testing.T) {
if ci == nil {
t.Fatalf("expected non-nil CreationInfo, got nil")
}
- if ci.SPDXVersion != "SPDX-2.1" {
- t.Errorf("expected %s, got %s", "SPDX-2.1", ci.SPDXVersion)
- }
- if ci.DataLicense != "CC0-1.0" {
- t.Errorf("expected %s, got %s", "CC0-1.0", ci.DataLicense)
- }
- if ci.SPDXIdentifier != spdx.ElementID("DOCUMENT") {
- t.Errorf("expected %s, got %v", "DOCUMENT", ci.SPDXIdentifier)
- }
- if ci.DocumentName != "project1" {
- t.Errorf("expected %s, got %s", "project1", ci.DocumentName)
- }
- wantNamespace := fmt.Sprintf("https://github.com/swinslow/spdx-docs/spdx-go/testdata-whatever-project1-%s", verificationCode)
- if ci.DocumentNamespace != wantNamespace {
- t.Errorf("expected %s, got %s", wantNamespace, ci.DocumentNamespace)
- }
- if len(ci.CreatorPersons) != 0 {
- t.Fatalf("expected %d, got %d", 0, len(ci.CreatorPersons))
- }
- if len(ci.CreatorOrganizations) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(ci.CreatorOrganizations))
+ if len(ci.Creators) != 2 {
+ t.Fatalf("expected %d, got %d", 2, len(ci.Creators))
}
- if ci.CreatorOrganizations[0] != "Jane Doe LLC" {
- t.Errorf("expected %s, got %s", "Jane Doe LLC", ci.CreatorOrganizations[0])
+ if ci.Creators[1].Creator != "Jane Doe LLC" {
+ t.Errorf("expected %s, got %s", "Jane Doe LLC", ci.Creators[1].Creator)
}
- if len(ci.CreatorTools) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(ci.CreatorTools))
- }
- if ci.CreatorTools[0] != "github.com/spdx/tools-golang/builder" {
- t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.CreatorTools[0])
+ if ci.Creators[0].Creator != "github.com/spdx/tools-golang/builder" {
+ t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.Creators[0].Creator)
}
if ci.Created != "2018-10-20T16:48:00Z" {
t.Errorf("expected %s, got %s", "2018-10-20T16:48:00Z", ci.Created)
@@ -65,15 +36,12 @@ func TestBuilder2_1CanBuildCreationInfoSection(t *testing.T) {
}
func TestBuilder2_1CanBuildCreationInfoSectionWithCreatorPerson(t *testing.T) {
- namespacePrefix := "https://github.com/swinslow/spdx-docs/spdx-go/testdata-whatever-"
creatorType := "Person"
creator := "John Doe"
testValues := make(map[string]string)
testValues["Created"] = "2018-10-20T16:48:00Z"
- packageName := "project1"
- verificationCode := "TESTCODE"
- ci, err := BuildCreationInfoSection2_1(packageName, verificationCode, namespacePrefix, creatorType, creator, testValues)
+ ci, err := BuildCreationInfoSection2_1(creatorType, creator, testValues)
if err != nil {
t.Fatalf("expected nil error, got %v", err)
}
@@ -81,33 +49,24 @@ func TestBuilder2_1CanBuildCreationInfoSectionWithCreatorPerson(t *testing.T) {
if ci == nil {
t.Fatalf("expected non-nil CreationInfo, got nil")
}
- if len(ci.CreatorPersons) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(ci.CreatorPersons))
- }
- if ci.CreatorPersons[0] != "John Doe" {
- t.Errorf("expected %s, got %s", "John Doe", ci.CreatorPersons[0])
+ if len(ci.Creators) != 2 {
+ t.Fatalf("expected %d, got %d", 2, len(ci.Creators))
}
- if len(ci.CreatorOrganizations) != 0 {
- t.Fatalf("expected %d, got %d", 0, len(ci.CreatorOrganizations))
+ if ci.Creators[1].Creator != "John Doe" {
+ t.Errorf("expected %s, got %s", "John Doe", ci.Creators[1].Creator)
}
- if len(ci.CreatorTools) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(ci.CreatorTools))
- }
- if ci.CreatorTools[0] != "github.com/spdx/tools-golang/builder" {
- t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.CreatorTools[0])
+ if ci.Creators[0].Creator != "github.com/spdx/tools-golang/builder" {
+ t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.Creators[0].Creator)
}
}
func TestBuilder2_1CanBuildCreationInfoSectionWithCreatorTool(t *testing.T) {
- namespacePrefix := "https://github.com/swinslow/spdx-docs/spdx-go/testdata-whatever-"
creatorType := "Tool"
creator := "some-other-tool-2.1"
testValues := make(map[string]string)
testValues["Created"] = "2018-10-20T16:48:00Z"
- packageName := "project1"
- verificationCode := "TESTCODE"
- ci, err := BuildCreationInfoSection2_1(packageName, verificationCode, namespacePrefix, creatorType, creator, testValues)
+ ci, err := BuildCreationInfoSection2_1(creatorType, creator, testValues)
if err != nil {
t.Fatalf("expected nil error, got %v", err)
}
@@ -115,33 +74,24 @@ func TestBuilder2_1CanBuildCreationInfoSectionWithCreatorTool(t *testing.T) {
if ci == nil {
t.Fatalf("expected non-nil CreationInfo, got nil")
}
- if len(ci.CreatorPersons) != 0 {
- t.Fatalf("expected %d, got %d", 0, len(ci.CreatorPersons))
- }
- if len(ci.CreatorOrganizations) != 0 {
- t.Fatalf("expected %d, got %d", 0, len(ci.CreatorOrganizations))
+ if len(ci.Creators) != 2 {
+ t.Fatalf("expected %d, got %d", 2, len(ci.Creators))
}
- if len(ci.CreatorTools) != 2 {
- t.Fatalf("expected %d, got %d", 2, len(ci.CreatorTools))
+ if ci.Creators[0].Creator != "github.com/spdx/tools-golang/builder" {
+ t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.Creators[0])
}
- if ci.CreatorTools[0] != "github.com/spdx/tools-golang/builder" {
- t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.CreatorTools[0])
- }
- if ci.CreatorTools[1] != "some-other-tool-2.1" {
- t.Errorf("expected %s, got %s", "some-other-tool-2.1", ci.CreatorTools[1])
+ if ci.Creators[1].Creator != "some-other-tool-2.1" {
+ t.Errorf("expected %s, got %s", "some-other-tool-2.1", ci.Creators[1])
}
}
func TestBuilder2_1CanBuildCreationInfoSectionWithInvalidPerson(t *testing.T) {
- namespacePrefix := "https://github.com/swinslow/spdx-docs/spdx-go/testdata-whatever-"
creatorType := "Whatever"
creator := "John Doe"
testValues := make(map[string]string)
testValues["Created"] = "2018-10-20T16:48:00Z"
- packageName := "project1"
- verificationCode := "TESTCODE"
- ci, err := BuildCreationInfoSection2_1(packageName, verificationCode, namespacePrefix, creatorType, creator, testValues)
+ ci, err := BuildCreationInfoSection2_1(creatorType, creator, testValues)
if err != nil {
t.Fatalf("expected nil error, got %v", err)
}
@@ -149,19 +99,13 @@ func TestBuilder2_1CanBuildCreationInfoSectionWithInvalidPerson(t *testing.T) {
if ci == nil {
t.Fatalf("expected non-nil CreationInfo, got nil")
}
- if len(ci.CreatorPersons) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(ci.CreatorPersons))
- }
- if ci.CreatorPersons[0] != "John Doe" {
- t.Errorf("expected %s, got %s", "John Doe", ci.CreatorPersons[0])
- }
- if len(ci.CreatorOrganizations) != 0 {
- t.Fatalf("expected %d, got %d", 0, len(ci.CreatorOrganizations))
+ if len(ci.Creators) != 2 {
+ t.Fatalf("expected %d, got %d", 2, len(ci.Creators))
}
- if len(ci.CreatorTools) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(ci.CreatorTools))
+ if ci.Creators[1].Creator != "John Doe" {
+ t.Errorf("expected %s, got %s", "John Doe", ci.Creators[1])
}
- if ci.CreatorTools[0] != "github.com/spdx/tools-golang/builder" {
- t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.CreatorTools[0])
+ if ci.Creators[0].Creator != "github.com/spdx/tools-golang/builder" {
+ t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.Creators[0])
}
}
diff --git a/builder/builder2v1/build_file.go b/builder/builder2v1/build_file.go
index b47268c..7e9e52e 100644
--- a/builder/builder2v1/build_file.go
+++ b/builder/builder2v1/build_file.go
@@ -32,11 +32,22 @@ func BuildFileSection2_1(filePath string, prefix string, fileNumber int) (*spdx.
f := &spdx.File2_1{
FileName: filePath,
FileSPDXIdentifier: spdx.ElementID(i),
- FileChecksumSHA1: ssha1,
- FileChecksumSHA256: ssha256,
- FileChecksumMD5: smd5,
+ Checksums: []spdx.Checksum{
+ {
+ Algorithm: spdx.SHA1,
+ Value: ssha1,
+ },
+ {
+ Algorithm: spdx.SHA256,
+ Value: ssha256,
+ },
+ {
+ Algorithm: spdx.MD5,
+ Value: smd5,
+ },
+ },
LicenseConcluded: "NOASSERTION",
- LicenseInfoInFile: []string{"NOASSERTION"},
+ LicenseInfoInFiles: []string{"NOASSERTION"},
FileCopyrightText: "NOASSERTION",
}
diff --git a/builder/builder2v1/build_file_test.go b/builder/builder2v1/build_file_test.go
index 6ef157a..cea297b 100644
--- a/builder/builder2v1/build_file_test.go
+++ b/builder/builder2v1/build_file_test.go
@@ -28,23 +28,32 @@ func TestBuilder2_1CanBuildFileSection(t *testing.T) {
if file1.FileSPDXIdentifier != spdx.ElementID("File17") {
t.Errorf("expected %v, got %v", "File17", file1.FileSPDXIdentifier)
}
- if file1.FileChecksumSHA1 != "024f870eb6323f532515f7a09d5646a97083b819" {
- t.Errorf("expected %v, got %v", "024f870eb6323f532515f7a09d5646a97083b819", file1.FileChecksumSHA1)
- }
- if file1.FileChecksumSHA256 != "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf" {
- t.Errorf("expected %v, got %v", "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf", file1.FileChecksumSHA256)
- }
- if file1.FileChecksumMD5 != "37c8208479dfe42d2bb29debd6e32d4a" {
- t.Errorf("expected %v, got %v", "37c8208479dfe42d2bb29debd6e32d4a", file1.FileChecksumMD5)
+
+ for _, checksum := range file1.Checksums {
+ switch checksum.Algorithm {
+ case spdx.SHA1:
+ if checksum.Value != "024f870eb6323f532515f7a09d5646a97083b819" {
+ t.Errorf("expected %v, got %v", "024f870eb6323f532515f7a09d5646a97083b819", checksum.Value)
+ }
+ case spdx.SHA256:
+ if checksum.Value != "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf" {
+ t.Errorf("expected %v, got %v", "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf", checksum.Value)
+ }
+ case spdx.MD5:
+ if checksum.Value != "37c8208479dfe42d2bb29debd6e32d4a" {
+ t.Errorf("expected %v, got %v", "37c8208479dfe42d2bb29debd6e32d4a", checksum.Value)
+ }
+ }
}
+
if file1.LicenseConcluded != "NOASSERTION" {
t.Errorf("expected %v, got %v", "NOASSERTION", file1.LicenseConcluded)
}
- if len(file1.LicenseInfoInFile) != 1 {
- t.Errorf("expected %v, got %v", 1, len(file1.LicenseInfoInFile))
+ if len(file1.LicenseInfoInFiles) != 1 {
+ t.Errorf("expected %v, got %v", 1, len(file1.LicenseInfoInFiles))
} else {
- if file1.LicenseInfoInFile[0] != "NOASSERTION" {
- t.Errorf("expected %v, got %v", "NOASSERTION", file1.LicenseInfoInFile[0])
+ if file1.LicenseInfoInFiles[0] != "NOASSERTION" {
+ t.Errorf("expected %v, got %v", "NOASSERTION", file1.LicenseInfoInFiles[0])
}
}
if file1.FileCopyrightText != "NOASSERTION" {
diff --git a/builder/builder2v1/build_package.go b/builder/builder2v1/build_package.go
index e59e676..f39bb53 100644
--- a/builder/builder2v1/build_package.go
+++ b/builder/builder2v1/build_package.go
@@ -35,7 +35,7 @@ func BuildPackageSection2_1(packageName string, dirRoot string, pathsIgnore []st
dirRootLen = len(dirRoot)
}
- files := map[spdx.ElementID]*spdx.File2_1{}
+ files := []*spdx.File2_1{}
fileNumber := 0
for _, fp := range filepaths {
newFilePatch := ""
@@ -48,7 +48,7 @@ func BuildPackageSection2_1(packageName string, dirRoot string, pathsIgnore []st
if err != nil {
return nil, err
}
- files[newFile.FileSPDXIdentifier] = newFile
+ files = append(files, newFile)
fileNumber++
}
// get the verification code
diff --git a/builder/builder2v1/build_package_test.go b/builder/builder2v1/build_package_test.go
index 7128834..1458637 100644
--- a/builder/builder2v1/build_package_test.go
+++ b/builder/builder2v1/build_package_test.go
@@ -13,7 +13,7 @@ func TestBuilder2_1CanBuildPackageSection(t *testing.T) {
packageName := "project1"
dirRoot := "../../testdata/project1/"
- wantVerificationCode := "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"
+ wantVerificationCode := spdx.PackageVerificationCode{Value: "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"}
pkg, err := BuildPackageSection2_1(packageName, dirRoot, nil)
if err != nil {
@@ -38,7 +38,7 @@ func TestBuilder2_1CanBuildPackageSection(t *testing.T) {
if pkg.IsFilesAnalyzedTagPresent != true {
t.Errorf("expected %v, got %v", true, pkg.IsFilesAnalyzedTagPresent)
}
- if pkg.PackageVerificationCode != wantVerificationCode {
+ if pkg.PackageVerificationCode.Value != wantVerificationCode.Value {
t.Errorf("expected %v, got %v", wantVerificationCode, pkg.PackageVerificationCode)
}
if pkg.PackageLicenseConcluded != "NOASSERTION" {
@@ -61,7 +61,7 @@ func TestBuilder2_1CanBuildPackageSection(t *testing.T) {
if len(pkg.Files) != 5 {
t.Fatalf("expected %d, got %d", 5, len(pkg.Files))
}
- fileEmpty := pkg.Files[spdx.ElementID("File0")]
+ fileEmpty := pkg.Files[0]
if fileEmpty == nil {
t.Fatalf("expected non-nil file, got nil")
}
@@ -71,23 +71,30 @@ func TestBuilder2_1CanBuildPackageSection(t *testing.T) {
if fileEmpty.FileSPDXIdentifier != spdx.ElementID("File0") {
t.Errorf("expected %v, got %v", "File0", fileEmpty.FileSPDXIdentifier)
}
- if fileEmpty.FileChecksumSHA1 != "da39a3ee5e6b4b0d3255bfef95601890afd80709" {
- t.Errorf("expected %v, got %v", "da39a3ee5e6b4b0d3255bfef95601890afd80709", fileEmpty.FileChecksumSHA1)
- }
- if fileEmpty.FileChecksumSHA256 != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" {
- t.Errorf("expected %v, got %v", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", fileEmpty.FileChecksumSHA256)
- }
- if fileEmpty.FileChecksumMD5 != "d41d8cd98f00b204e9800998ecf8427e" {
- t.Errorf("expected %v, got %v", "d41d8cd98f00b204e9800998ecf8427e", fileEmpty.FileChecksumMD5)
+ for _, checksum := range fileEmpty.Checksums {
+ switch checksum.Algorithm {
+ case spdx.SHA1:
+ if checksum.Value != "da39a3ee5e6b4b0d3255bfef95601890afd80709" {
+ t.Errorf("expected %v, got %v", "da39a3ee5e6b4b0d3255bfef95601890afd80709", checksum.Value)
+ }
+ case spdx.SHA256:
+ if checksum.Value != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" {
+ t.Errorf("expected %v, got %v", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", checksum.Value)
+ }
+ case spdx.MD5:
+ if checksum.Value != "d41d8cd98f00b204e9800998ecf8427e" {
+ t.Errorf("expected %v, got %v", "d41d8cd98f00b204e9800998ecf8427e", checksum.Value)
+ }
+ }
}
if fileEmpty.LicenseConcluded != "NOASSERTION" {
t.Errorf("expected %v, got %v", "NOASSERTION", fileEmpty.LicenseConcluded)
}
- if len(fileEmpty.LicenseInfoInFile) != 1 {
- t.Errorf("expected %v, got %v", 1, len(fileEmpty.LicenseInfoInFile))
+ if len(fileEmpty.LicenseInfoInFiles) != 1 {
+ t.Errorf("expected %v, got %v", 1, len(fileEmpty.LicenseInfoInFiles))
} else {
- if fileEmpty.LicenseInfoInFile[0] != "NOASSERTION" {
- t.Errorf("expected %v, got %v", "NOASSERTION", fileEmpty.LicenseInfoInFile[0])
+ if fileEmpty.LicenseInfoInFiles[0] != "NOASSERTION" {
+ t.Errorf("expected %v, got %v", "NOASSERTION", fileEmpty.LicenseInfoInFiles[0])
}
}
if fileEmpty.FileCopyrightText != "NOASSERTION" {
@@ -118,31 +125,31 @@ func TestBuilder2_1CanIgnoreFiles(t *testing.T) {
}
want := "./dontscan.txt"
- got := pkg.Files[spdx.ElementID("File0")].FileName
+ got := pkg.Files[0].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./keep/keep.txt"
- got = pkg.Files[spdx.ElementID("File1")].FileName
+ got = pkg.Files[1].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./keep.txt"
- got = pkg.Files[spdx.ElementID("File2")].FileName
+ got = pkg.Files[2].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./subdir/keep/dontscan.txt"
- got = pkg.Files[spdx.ElementID("File3")].FileName
+ got = pkg.Files[3].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./subdir/keep/keep.txt"
- got = pkg.Files[spdx.ElementID("File4")].FileName
+ got = pkg.Files[4].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
diff --git a/builder/builder2v2/build_creation_info.go b/builder/builder2v2/build_creation_info.go
index 89e1b3c..c24d2d3 100644
--- a/builder/builder2v2/build_creation_info.go
+++ b/builder/builder2v2/build_creation_info.go
@@ -3,7 +3,6 @@
package builder2v2
import (
- "fmt"
"time"
"github.com/spdx/tools-golang/spdx"
@@ -17,23 +16,18 @@ import (
// - creatorType: one of Person, Organization or Tool
// - creator: creator string
// - testValues: for testing only; call with nil when using in production
-func BuildCreationInfoSection2_2(packageName string, code string, namespacePrefix string, creatorType string, creator string, testValues map[string]string) (*spdx.CreationInfo2_2, error) {
+func BuildCreationInfoSection2_2(creatorType string, creator string, testValues map[string]string) (*spdx.CreationInfo2_2, error) {
// build creator slices
- cPersons := []string{}
- cOrganizations := []string{}
- cTools := []string{}
- // add builder as a tool
- cTools = append(cTools, "github.com/spdx/tools-golang/builder")
-
- switch creatorType {
- case "Person":
- cPersons = append(cPersons, creator)
- case "Organization":
- cOrganizations = append(cOrganizations, creator)
- case "Tool":
- cTools = append(cTools, creator)
- default:
- cPersons = append(cPersons, creator)
+ creators := []spdx.Creator{
+ // add builder as a tool
+ {
+ Creator: "github.com/spdx/tools-golang/builder",
+ CreatorType: "Tool",
+ },
+ {
+ Creator: creator,
+ CreatorType: creatorType,
+ },
}
// use test Created time if passing test values
@@ -45,15 +39,8 @@ func BuildCreationInfoSection2_2(packageName string, code string, namespacePrefi
}
ci := &spdx.CreationInfo2_2{
- SPDXVersion: "SPDX-2.2",
- DataLicense: "CC0-1.0",
- SPDXIdentifier: spdx.ElementID("DOCUMENT"),
- DocumentName: packageName,
- DocumentNamespace: fmt.Sprintf("%s%s-%s", namespacePrefix, packageName, code),
- CreatorPersons: cPersons,
- CreatorOrganizations: cOrganizations,
- CreatorTools: cTools,
- Created: created,
+ Creators: creators,
+ Created: created,
}
return ci, nil
}
diff --git a/builder/builder2v2/build_creation_info_test.go b/builder/builder2v2/build_creation_info_test.go
index 188bd74..48a0654 100644
--- a/builder/builder2v2/build_creation_info_test.go
+++ b/builder/builder2v2/build_creation_info_test.go
@@ -3,24 +3,17 @@
package builder2v2
import (
- "fmt"
"testing"
-
- "github.com/spdx/tools-golang/spdx"
)
// ===== CreationInfo section builder tests =====
func TestBuilder2_2CanBuildCreationInfoSection(t *testing.T) {
-
- namespacePrefix := "https://github.com/swinslow/spdx-docs/spdx-go/testdata-whatever-"
creatorType := "Organization"
creator := "Jane Doe LLC"
testValues := make(map[string]string)
testValues["Created"] = "2018-10-20T16:48:00Z"
- packageName := "project1"
- verificationCode := "TESTCODE"
- ci, err := BuildCreationInfoSection2_2(packageName, verificationCode, namespacePrefix, creatorType, creator, testValues)
+ ci, err := BuildCreationInfoSection2_2(creatorType, creator, testValues)
if err != nil {
t.Fatalf("expected nil error, got %v", err)
}
@@ -28,36 +21,14 @@ func TestBuilder2_2CanBuildCreationInfoSection(t *testing.T) {
if ci == nil {
t.Fatalf("expected non-nil CreationInfo, got nil")
}
- if ci.SPDXVersion != "SPDX-2.2" {
- t.Errorf("expected %s, got %s", "SPDX-2.2", ci.SPDXVersion)
- }
- if ci.DataLicense != "CC0-1.0" {
- t.Errorf("expected %s, got %s", "CC0-1.0", ci.DataLicense)
- }
- if ci.SPDXIdentifier != spdx.ElementID("DOCUMENT") {
- t.Errorf("expected %s, got %v", "DOCUMENT", ci.SPDXIdentifier)
- }
- if ci.DocumentName != "project1" {
- t.Errorf("expected %s, got %s", "project1", ci.DocumentName)
- }
- wantNamespace := fmt.Sprintf("https://github.com/swinslow/spdx-docs/spdx-go/testdata-whatever-project1-%s", verificationCode)
- if ci.DocumentNamespace != wantNamespace {
- t.Errorf("expected %s, got %s", wantNamespace, ci.DocumentNamespace)
- }
- if len(ci.CreatorPersons) != 0 {
- t.Fatalf("expected %d, got %d", 0, len(ci.CreatorPersons))
- }
- if len(ci.CreatorOrganizations) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(ci.CreatorOrganizations))
+ if len(ci.Creators) != 2 {
+ t.Fatalf("expected %d, got %d", 2, len(ci.Creators))
}
- if ci.CreatorOrganizations[0] != "Jane Doe LLC" {
- t.Errorf("expected %s, got %s", "Jane Doe LLC", ci.CreatorOrganizations[0])
+ if ci.Creators[1].Creator != "Jane Doe LLC" {
+ t.Errorf("expected %s, got %s", "Jane Doe LLC", ci.Creators[0].Creator)
}
- if len(ci.CreatorTools) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(ci.CreatorTools))
- }
- if ci.CreatorTools[0] != "github.com/spdx/tools-golang/builder" {
- t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.CreatorTools[0])
+ if ci.Creators[0].Creator != "github.com/spdx/tools-golang/builder" {
+ t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.Creators[1].Creator)
}
if ci.Created != "2018-10-20T16:48:00Z" {
t.Errorf("expected %s, got %s", "2018-10-20T16:48:00Z", ci.Created)
@@ -65,15 +36,12 @@ func TestBuilder2_2CanBuildCreationInfoSection(t *testing.T) {
}
func TestBuilder2_2CanBuildCreationInfoSectionWithCreatorPerson(t *testing.T) {
- namespacePrefix := "https://github.com/swinslow/spdx-docs/spdx-go/testdata-whatever-"
creatorType := "Person"
creator := "John Doe"
testValues := make(map[string]string)
testValues["Created"] = "2018-10-20T16:48:00Z"
- packageName := "project1"
- verificationCode := "TESTCODE"
- ci, err := BuildCreationInfoSection2_2(packageName, verificationCode, namespacePrefix, creatorType, creator, testValues)
+ ci, err := BuildCreationInfoSection2_2(creatorType, creator, testValues)
if err != nil {
t.Fatalf("expected nil error, got %v", err)
}
@@ -81,33 +49,24 @@ func TestBuilder2_2CanBuildCreationInfoSectionWithCreatorPerson(t *testing.T) {
if ci == nil {
t.Fatalf("expected non-nil CreationInfo, got nil")
}
- if len(ci.CreatorPersons) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(ci.CreatorPersons))
- }
- if ci.CreatorPersons[0] != "John Doe" {
- t.Errorf("expected %s, got %s", "John Doe", ci.CreatorPersons[0])
+ if len(ci.Creators) != 2 {
+ t.Fatalf("expected %d, got %d", 2, len(ci.Creators))
}
- if len(ci.CreatorOrganizations) != 0 {
- t.Fatalf("expected %d, got %d", 0, len(ci.CreatorOrganizations))
+ if ci.Creators[1].Creator != "John Doe" {
+ t.Errorf("expected %s, got %s", "John Doe", ci.Creators[0].Creator)
}
- if len(ci.CreatorTools) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(ci.CreatorTools))
- }
- if ci.CreatorTools[0] != "github.com/spdx/tools-golang/builder" {
- t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.CreatorTools[0])
+ if ci.Creators[0].Creator != "github.com/spdx/tools-golang/builder" {
+ t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.Creators[1].Creator)
}
}
func TestBuilder2_2CanBuildCreationInfoSectionWithCreatorTool(t *testing.T) {
- namespacePrefix := "https://github.com/swinslow/spdx-docs/spdx-go/testdata-whatever-"
creatorType := "Tool"
creator := "some-other-tool-2.1"
testValues := make(map[string]string)
testValues["Created"] = "2018-10-20T16:48:00Z"
- packageName := "project1"
- verificationCode := "TESTCODE"
- ci, err := BuildCreationInfoSection2_2(packageName, verificationCode, namespacePrefix, creatorType, creator, testValues)
+ ci, err := BuildCreationInfoSection2_2(creatorType, creator, testValues)
if err != nil {
t.Fatalf("expected nil error, got %v", err)
}
@@ -115,33 +74,24 @@ func TestBuilder2_2CanBuildCreationInfoSectionWithCreatorTool(t *testing.T) {
if ci == nil {
t.Fatalf("expected non-nil CreationInfo, got nil")
}
- if len(ci.CreatorPersons) != 0 {
- t.Fatalf("expected %d, got %d", 0, len(ci.CreatorPersons))
- }
- if len(ci.CreatorOrganizations) != 0 {
- t.Fatalf("expected %d, got %d", 0, len(ci.CreatorOrganizations))
+ if len(ci.Creators) != 2 {
+ t.Fatalf("expected %d, got %d", 2, len(ci.Creators))
}
- if len(ci.CreatorTools) != 2 {
- t.Fatalf("expected %d, got %d", 2, len(ci.CreatorTools))
+ if ci.Creators[0].Creator != "github.com/spdx/tools-golang/builder" {
+ t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.Creators[0])
}
- if ci.CreatorTools[0] != "github.com/spdx/tools-golang/builder" {
- t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.CreatorTools[0])
- }
- if ci.CreatorTools[1] != "some-other-tool-2.1" {
- t.Errorf("expected %s, got %s", "some-other-tool-2.1", ci.CreatorTools[1])
+ if ci.Creators[1].Creator != "some-other-tool-2.1" {
+ t.Errorf("expected %s, got %s", "some-other-tool-2.1", ci.Creators[1])
}
}
func TestBuilder2_2CanBuildCreationInfoSectionWithInvalidPerson(t *testing.T) {
- namespacePrefix := "https://github.com/swinslow/spdx-docs/spdx-go/testdata-whatever-"
creatorType := "Whatever"
creator := "John Doe"
testValues := make(map[string]string)
testValues["Created"] = "2018-10-20T16:48:00Z"
- packageName := "project1"
- verificationCode := "TESTCODE"
- ci, err := BuildCreationInfoSection2_2(packageName, verificationCode, namespacePrefix, creatorType, creator, testValues)
+ ci, err := BuildCreationInfoSection2_2(creatorType, creator, testValues)
if err != nil {
t.Fatalf("expected nil error, got %v", err)
}
@@ -149,19 +99,13 @@ func TestBuilder2_2CanBuildCreationInfoSectionWithInvalidPerson(t *testing.T) {
if ci == nil {
t.Fatalf("expected non-nil CreationInfo, got nil")
}
- if len(ci.CreatorPersons) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(ci.CreatorPersons))
- }
- if ci.CreatorPersons[0] != "John Doe" {
- t.Errorf("expected %s, got %s", "John Doe", ci.CreatorPersons[0])
- }
- if len(ci.CreatorOrganizations) != 0 {
- t.Fatalf("expected %d, got %d", 0, len(ci.CreatorOrganizations))
+ if len(ci.Creators) != 2 {
+ t.Fatalf("expected %d, got %d", 2, len(ci.Creators))
}
- if len(ci.CreatorTools) != 1 {
- t.Fatalf("expected %d, got %d", 1, len(ci.CreatorTools))
+ if ci.Creators[1].Creator != "John Doe" {
+ t.Errorf("expected %s, got %s", "John Doe", ci.Creators[1])
}
- if ci.CreatorTools[0] != "github.com/spdx/tools-golang/builder" {
- t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.CreatorTools[0])
+ if ci.Creators[0].Creator != "github.com/spdx/tools-golang/builder" {
+ t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.Creators[0])
}
}
diff --git a/builder/builder2v2/build_file.go b/builder/builder2v2/build_file.go
index ec59f6a..efdd979 100644
--- a/builder/builder2v2/build_file.go
+++ b/builder/builder2v2/build_file.go
@@ -32,23 +32,23 @@ func BuildFileSection2_2(filePath string, prefix string, fileNumber int) (*spdx.
f := &spdx.File2_2{
FileName: filePath,
FileSPDXIdentifier: spdx.ElementID(i),
- FileChecksums: map[spdx.ChecksumAlgorithm]spdx.Checksum{
- spdx.SHA1: spdx.Checksum{
+ Checksums: []spdx.Checksum{
+ {
Algorithm: spdx.SHA1,
Value: ssha1,
},
- spdx.SHA256: spdx.Checksum{
+ {
Algorithm: spdx.SHA256,
Value: ssha256,
},
- spdx.MD5: spdx.Checksum{
+ {
Algorithm: spdx.MD5,
Value: smd5,
},
},
- LicenseConcluded: "NOASSERTION",
- LicenseInfoInFile: []string{"NOASSERTION"},
- FileCopyrightText: "NOASSERTION",
+ LicenseConcluded: "NOASSERTION",
+ LicenseInfoInFiles: []string{"NOASSERTION"},
+ FileCopyrightText: "NOASSERTION",
}
return f, nil
diff --git a/builder/builder2v2/build_file_test.go b/builder/builder2v2/build_file_test.go
index 8a1767e..74a6a6a 100644
--- a/builder/builder2v2/build_file_test.go
+++ b/builder/builder2v2/build_file_test.go
@@ -28,7 +28,8 @@ func TestBuilder2_2CanBuildFileSection(t *testing.T) {
if file1.FileSPDXIdentifier != spdx.ElementID("File17") {
t.Errorf("expected %v, got %v", "File17", file1.FileSPDXIdentifier)
}
- for _, checksum := range file1.FileChecksums {
+
+ for _, checksum := range file1.Checksums {
switch checksum.Algorithm {
case spdx.SHA1:
if checksum.Value != "024f870eb6323f532515f7a09d5646a97083b819" {
@@ -44,14 +45,15 @@ func TestBuilder2_2CanBuildFileSection(t *testing.T) {
}
}
}
+
if file1.LicenseConcluded != "NOASSERTION" {
t.Errorf("expected %v, got %v", "NOASSERTION", file1.LicenseConcluded)
}
- if len(file1.LicenseInfoInFile) != 1 {
- t.Errorf("expected %v, got %v", 1, len(file1.LicenseInfoInFile))
+ if len(file1.LicenseInfoInFiles) != 1 {
+ t.Errorf("expected %v, got %v", 1, len(file1.LicenseInfoInFiles))
} else {
- if file1.LicenseInfoInFile[0] != "NOASSERTION" {
- t.Errorf("expected %v, got %v", "NOASSERTION", file1.LicenseInfoInFile[0])
+ if file1.LicenseInfoInFiles[0] != "NOASSERTION" {
+ t.Errorf("expected %v, got %v", "NOASSERTION", file1.LicenseInfoInFiles[0])
}
}
if file1.FileCopyrightText != "NOASSERTION" {
diff --git a/builder/builder2v2/build_package.go b/builder/builder2v2/build_package.go
index 640f9c7..9c460da 100644
--- a/builder/builder2v2/build_package.go
+++ b/builder/builder2v2/build_package.go
@@ -35,7 +35,7 @@ func BuildPackageSection2_2(packageName string, dirRoot string, pathsIgnore []st
dirRootLen = len(dirRoot)
}
- files := map[spdx.ElementID]*spdx.File2_2{}
+ files := []*spdx.File2_2{}
fileNumber := 0
for _, fp := range filepaths {
newFilePatch := ""
@@ -48,7 +48,7 @@ func BuildPackageSection2_2(packageName string, dirRoot string, pathsIgnore []st
if err != nil {
return nil, err
}
- files[newFile.FileSPDXIdentifier] = newFile
+ files = append(files, newFile)
fileNumber++
}
diff --git a/builder/builder2v2/build_package_test.go b/builder/builder2v2/build_package_test.go
index 85f402e..3ab88d2 100644
--- a/builder/builder2v2/build_package_test.go
+++ b/builder/builder2v2/build_package_test.go
@@ -13,7 +13,7 @@ func TestBuilder2_2CanBuildPackageSection(t *testing.T) {
packageName := "project1"
dirRoot := "../../testdata/project1/"
- wantVerificationCode := "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"
+ wantVerificationCode := spdx.PackageVerificationCode{Value: "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"}
pkg, err := BuildPackageSection2_2(packageName, dirRoot, nil)
if err != nil {
@@ -38,7 +38,7 @@ func TestBuilder2_2CanBuildPackageSection(t *testing.T) {
if pkg.IsFilesAnalyzedTagPresent != true {
t.Errorf("expected %v, got %v", true, pkg.IsFilesAnalyzedTagPresent)
}
- if pkg.PackageVerificationCode != wantVerificationCode {
+ if pkg.PackageVerificationCode.Value != wantVerificationCode.Value {
t.Errorf("expected %v, got %v", wantVerificationCode, pkg.PackageVerificationCode)
}
if pkg.PackageLicenseConcluded != "NOASSERTION" {
@@ -61,7 +61,7 @@ func TestBuilder2_2CanBuildPackageSection(t *testing.T) {
if len(pkg.Files) != 5 {
t.Fatalf("expected %d, got %d", 5, len(pkg.Files))
}
- fileEmpty := pkg.Files[spdx.ElementID("File0")]
+ fileEmpty := pkg.Files[0]
if fileEmpty == nil {
t.Fatalf("expected non-nil file, got nil")
}
@@ -71,7 +71,7 @@ func TestBuilder2_2CanBuildPackageSection(t *testing.T) {
if fileEmpty.FileSPDXIdentifier != spdx.ElementID("File0") {
t.Errorf("expected %v, got %v", "File0", fileEmpty.FileSPDXIdentifier)
}
- for _, checksum := range fileEmpty.FileChecksums {
+ for _, checksum := range fileEmpty.Checksums {
switch checksum.Algorithm {
case spdx.SHA1:
if checksum.Value != "da39a3ee5e6b4b0d3255bfef95601890afd80709" {
@@ -90,11 +90,11 @@ func TestBuilder2_2CanBuildPackageSection(t *testing.T) {
if fileEmpty.LicenseConcluded != "NOASSERTION" {
t.Errorf("expected %v, got %v", "NOASSERTION", fileEmpty.LicenseConcluded)
}
- if len(fileEmpty.LicenseInfoInFile) != 1 {
- t.Errorf("expected %v, got %v", 1, len(fileEmpty.LicenseInfoInFile))
+ if len(fileEmpty.LicenseInfoInFiles) != 1 {
+ t.Errorf("expected %v, got %v", 1, len(fileEmpty.LicenseInfoInFiles))
} else {
- if fileEmpty.LicenseInfoInFile[0] != "NOASSERTION" {
- t.Errorf("expected %v, got %v", "NOASSERTION", fileEmpty.LicenseInfoInFile[0])
+ if fileEmpty.LicenseInfoInFiles[0] != "NOASSERTION" {
+ t.Errorf("expected %v, got %v", "NOASSERTION", fileEmpty.LicenseInfoInFiles[0])
}
}
if fileEmpty.FileCopyrightText != "NOASSERTION" {
@@ -125,31 +125,31 @@ func TestBuilder2_2CanIgnoreFiles(t *testing.T) {
}
want := "./dontscan.txt"
- got := pkg.Files[spdx.ElementID("File0")].FileName
+ got := pkg.Files[0].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./keep/keep.txt"
- got = pkg.Files[spdx.ElementID("File1")].FileName
+ got = pkg.Files[1].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./keep.txt"
- got = pkg.Files[spdx.ElementID("File2")].FileName
+ got = pkg.Files[2].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./subdir/keep/dontscan.txt"
- got = pkg.Files[spdx.ElementID("File3")].FileName
+ got = pkg.Files[3].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
want = "./subdir/keep/keep.txt"
- got = pkg.Files[spdx.ElementID("File4")].FileName
+ got = pkg.Files[4].FileName
if want != got {
t.Errorf("expected %v, got %v", want, got)
}