1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
package saver2v1
import (
"bytes"
"testing"
"github.com/spdx/tools-golang/spdx"
)
// ===== Other License section Saver tests =====
func TestSaver2_1OtherLicenseSavesText(t *testing.T) {
ol := &spdx.OtherLicense2_1{
LicenseIdentifier: "LicenseRef-1",
ExtractedText: `License 1 text
blah blah blah
blah blah blah blah`,
LicenseName: "License 1",
LicenseCrossReferences: []string{
"http://example.com/License1/",
"http://example.com/License1AnotherURL/",
},
LicenseComment: "this is a license comment",
}
// what we want to get, as a buffer of bytes
want := bytes.NewBufferString(`LicenseID: LicenseRef-1
ExtractedText: <text>License 1 text
blah blah blah
blah blah blah blah</text>
LicenseName: License 1
LicenseCrossReference: http://example.com/License1/
LicenseCrossReference: http://example.com/License1AnotherURL/
LicenseComment: this is a license comment
`)
// render as buffer of bytes
var got bytes.Buffer
err := renderOtherLicense2_1(ol, &got)
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}
// check that they match
c := bytes.Compare(want.Bytes(), got.Bytes())
if c != 0 {
t.Errorf("Expected %v, got %v", want.String(), got.String())
}
}
func TestSaver2_1OtherLicenseOmitsOptionalFieldsIfEmpty(t *testing.T) {
ol := &spdx.OtherLicense2_1{
LicenseIdentifier: "LicenseRef-1",
ExtractedText: `License 1 text
blah blah blah
blah blah blah blah`,
LicenseName: "License 1",
}
// what we want to get, as a buffer of bytes
want := bytes.NewBufferString(`LicenseID: LicenseRef-1
ExtractedText: <text>License 1 text
blah blah blah
blah blah blah blah</text>
LicenseName: License 1
`)
// render as buffer of bytes
var got bytes.Buffer
err := renderOtherLicense2_1(ol, &got)
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}
// check that they match
c := bytes.Compare(want.Bytes(), got.Bytes())
if c != 0 {
t.Errorf("Expected %v, got %v", want.String(), got.String())
}
}
|