aboutsummaryrefslogtreecommitdiff
path: root/builder/builder2v2/build_creation_info_test.go
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/builder2v2/build_creation_info_test.go
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/builder2v2/build_creation_info_test.go')
-rw-r--r--builder/builder2v2/build_creation_info_test.go112
1 files changed, 28 insertions, 84 deletions
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])
}
}