xref: /aosp_15_r20/external/spdx-tools/builder/builder2v3/build_creation_info_test.go (revision ba677afa8f67bb56cbc794f4d0e378e0da058e16)
1// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
2
3package builder2v3
4
5import (
6	"testing"
7)
8
9// ===== CreationInfo section builder tests =====
10func TestBuilder2_3CanBuildCreationInfoSection(t *testing.T) {
11	creatorType := "Organization"
12	creator := "Jane Doe LLC"
13	testValues := make(map[string]string)
14	testValues["Created"] = "2018-10-20T16:48:00Z"
15
16	ci, err := BuildCreationInfoSection2_3(creatorType, creator, testValues)
17	if err != nil {
18		t.Fatalf("expected nil error, got %v", err)
19	}
20
21	if ci == nil {
22		t.Fatalf("expected non-nil CreationInfo, got nil")
23	}
24	if len(ci.Creators) != 2 {
25		t.Fatalf("expected %d, got %d", 2, len(ci.Creators))
26	}
27	if ci.Creators[1].Creator != "Jane Doe LLC" {
28		t.Errorf("expected %s, got %s", "Jane Doe LLC", ci.Creators[0].Creator)
29	}
30	if ci.Creators[0].Creator != "github.com/spdx/tools-golang/builder" {
31		t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.Creators[1].Creator)
32	}
33	if ci.Created != "2018-10-20T16:48:00Z" {
34		t.Errorf("expected %s, got %s", "2018-10-20T16:48:00Z", ci.Created)
35	}
36}
37
38func TestBuilder2_3CanBuildCreationInfoSectionWithCreatorPerson(t *testing.T) {
39	creatorType := "Person"
40	creator := "John Doe"
41	testValues := make(map[string]string)
42	testValues["Created"] = "2018-10-20T16:48:00Z"
43
44	ci, err := BuildCreationInfoSection2_3(creatorType, creator, testValues)
45	if err != nil {
46		t.Fatalf("expected nil error, got %v", err)
47	}
48
49	if ci == nil {
50		t.Fatalf("expected non-nil CreationInfo, got nil")
51	}
52	if len(ci.Creators) != 2 {
53		t.Fatalf("expected %d, got %d", 2, len(ci.Creators))
54	}
55	if ci.Creators[1].Creator != "John Doe" {
56		t.Errorf("expected %s, got %s", "John Doe", ci.Creators[0].Creator)
57	}
58	if ci.Creators[0].Creator != "github.com/spdx/tools-golang/builder" {
59		t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.Creators[1].Creator)
60	}
61}
62
63func TestBuilder2_3CanBuildCreationInfoSectionWithCreatorTool(t *testing.T) {
64	creatorType := "Tool"
65	creator := "some-other-tool-2.1"
66	testValues := make(map[string]string)
67	testValues["Created"] = "2018-10-20T16:48:00Z"
68
69	ci, err := BuildCreationInfoSection2_3(creatorType, creator, testValues)
70	if err != nil {
71		t.Fatalf("expected nil error, got %v", err)
72	}
73
74	if ci == nil {
75		t.Fatalf("expected non-nil CreationInfo, got nil")
76	}
77	if len(ci.Creators) != 2 {
78		t.Fatalf("expected %d, got %d", 2, len(ci.Creators))
79	}
80	if ci.Creators[0].Creator != "github.com/spdx/tools-golang/builder" {
81		t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.Creators[0])
82	}
83	if ci.Creators[1].Creator != "some-other-tool-2.1" {
84		t.Errorf("expected %s, got %s", "some-other-tool-2.1", ci.Creators[1])
85	}
86}
87
88func TestBuilder2_3CanBuildCreationInfoSectionWithInvalidPerson(t *testing.T) {
89	creatorType := "Whatever"
90	creator := "John Doe"
91	testValues := make(map[string]string)
92	testValues["Created"] = "2018-10-20T16:48:00Z"
93
94	ci, err := BuildCreationInfoSection2_3(creatorType, creator, testValues)
95	if err != nil {
96		t.Fatalf("expected nil error, got %v", err)
97	}
98
99	if ci == nil {
100		t.Fatalf("expected non-nil CreationInfo, got nil")
101	}
102	if len(ci.Creators) != 2 {
103		t.Fatalf("expected %d, got %d", 2, len(ci.Creators))
104	}
105	if ci.Creators[1].Creator != "John Doe" {
106		t.Errorf("expected %s, got %s", "John Doe", ci.Creators[1])
107	}
108	if ci.Creators[0].Creator != "github.com/spdx/tools-golang/builder" {
109		t.Errorf("expected %s, got %s", "github.com/spdx/tools-golang/builder", ci.Creators[0])
110	}
111}
112