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