xref: /aosp_15_r20/external/spdx-tools/tvsaver/saver2v1/save_review_test.go (revision ba677afa8f67bb56cbc794f4d0e378e0da058e16)
1*ba677afaSXin Li// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
2*ba677afaSXin Li
3*ba677afaSXin Lipackage saver2v1
4*ba677afaSXin Li
5*ba677afaSXin Liimport (
6*ba677afaSXin Li	"bytes"
7*ba677afaSXin Li	"testing"
8*ba677afaSXin Li
9*ba677afaSXin Li	"github.com/spdx/tools-golang/spdx/v2_1"
10*ba677afaSXin Li)
11*ba677afaSXin Li
12*ba677afaSXin Li// ===== Review section Saver tests =====
13*ba677afaSXin Lifunc TestSaver2_1ReviewSavesText(t *testing.T) {
14*ba677afaSXin Li	rev := &v2_1.Review{
15*ba677afaSXin Li		Reviewer:      "John Doe",
16*ba677afaSXin Li		ReviewerType:  "Person",
17*ba677afaSXin Li		ReviewDate:    "2018-10-14T10:28:00Z",
18*ba677afaSXin Li		ReviewComment: "this is a review comment",
19*ba677afaSXin Li	}
20*ba677afaSXin Li
21*ba677afaSXin Li	// what we want to get, as a buffer of bytes
22*ba677afaSXin Li	want := bytes.NewBufferString(`Reviewer: Person: John Doe
23*ba677afaSXin LiReviewDate: 2018-10-14T10:28:00Z
24*ba677afaSXin LiReviewComment: this is a review comment
25*ba677afaSXin Li
26*ba677afaSXin Li`)
27*ba677afaSXin Li
28*ba677afaSXin Li	// render as buffer of bytes
29*ba677afaSXin Li	var got bytes.Buffer
30*ba677afaSXin Li	err := renderReview2_1(rev, &got)
31*ba677afaSXin Li	if err != nil {
32*ba677afaSXin Li		t.Errorf("Expected nil error, got %v", err)
33*ba677afaSXin Li	}
34*ba677afaSXin Li
35*ba677afaSXin Li	// check that they match
36*ba677afaSXin Li	c := bytes.Compare(want.Bytes(), got.Bytes())
37*ba677afaSXin Li	if c != 0 {
38*ba677afaSXin Li		t.Errorf("Expected %v, got %v", want.String(), got.String())
39*ba677afaSXin Li	}
40*ba677afaSXin Li}
41*ba677afaSXin Li
42*ba677afaSXin Lifunc TestSaver2_1ReviewOmitsOptionalFieldsIfEmpty(t *testing.T) {
43*ba677afaSXin Li	rev := &v2_1.Review{
44*ba677afaSXin Li		Reviewer:     "John Doe",
45*ba677afaSXin Li		ReviewerType: "Person",
46*ba677afaSXin Li		ReviewDate:   "2018-10-14T10:28:00Z",
47*ba677afaSXin Li	}
48*ba677afaSXin Li
49*ba677afaSXin Li	// what we want to get, as a buffer of bytes
50*ba677afaSXin Li	want := bytes.NewBufferString(`Reviewer: Person: John Doe
51*ba677afaSXin LiReviewDate: 2018-10-14T10:28:00Z
52*ba677afaSXin Li
53*ba677afaSXin Li`)
54*ba677afaSXin Li
55*ba677afaSXin Li	// render as buffer of bytes
56*ba677afaSXin Li	var got bytes.Buffer
57*ba677afaSXin Li	err := renderReview2_1(rev, &got)
58*ba677afaSXin Li	if err != nil {
59*ba677afaSXin Li		t.Errorf("Expected nil error, got %v", err)
60*ba677afaSXin Li	}
61*ba677afaSXin Li
62*ba677afaSXin Li	// check that they match
63*ba677afaSXin Li	c := bytes.Compare(want.Bytes(), got.Bytes())
64*ba677afaSXin Li	if c != 0 {
65*ba677afaSXin Li		t.Errorf("Expected %v, got %v", want.String(), got.String())
66*ba677afaSXin Li	}
67*ba677afaSXin Li}
68*ba677afaSXin Li
69*ba677afaSXin Lifunc TestSaver2_1ReviewWrapsMultiLine(t *testing.T) {
70*ba677afaSXin Li	rev := &v2_1.Review{
71*ba677afaSXin Li		Reviewer:     "John Doe",
72*ba677afaSXin Li		ReviewerType: "Person",
73*ba677afaSXin Li		ReviewDate:   "2018-10-14T10:28:00Z",
74*ba677afaSXin Li		ReviewComment: `this is a
75*ba677afaSXin Limulti-line review comment`,
76*ba677afaSXin Li	}
77*ba677afaSXin Li
78*ba677afaSXin Li	// what we want to get, as a buffer of bytes
79*ba677afaSXin Li	want := bytes.NewBufferString(`Reviewer: Person: John Doe
80*ba677afaSXin LiReviewDate: 2018-10-14T10:28:00Z
81*ba677afaSXin LiReviewComment: <text>this is a
82*ba677afaSXin Limulti-line review comment</text>
83*ba677afaSXin Li
84*ba677afaSXin Li`)
85*ba677afaSXin Li
86*ba677afaSXin Li	// render as buffer of bytes
87*ba677afaSXin Li	var got bytes.Buffer
88*ba677afaSXin Li	err := renderReview2_1(rev, &got)
89*ba677afaSXin Li	if err != nil {
90*ba677afaSXin Li		t.Errorf("Expected nil error, got %v", err)
91*ba677afaSXin Li	}
92*ba677afaSXin Li
93*ba677afaSXin Li	// check that they match
94*ba677afaSXin Li	c := bytes.Compare(want.Bytes(), got.Bytes())
95*ba677afaSXin Li	if c != 0 {
96*ba677afaSXin Li		t.Errorf("Expected %v, got %v", want.String(), got.String())
97*ba677afaSXin Li	}
98*ba677afaSXin Li}
99