diff options
author | RishabhBhatnagar <bhatnagarrishabh4@gmail.com> | 2020-01-09 20:39:55 +0530 |
---|---|---|
committer | RishabhBhatnagar <bhatnagarrishabh4@gmail.com> | 2020-01-09 21:04:37 +0530 |
commit | cd59ee66408a908f7ef94548814514f6bc9fc906 (patch) | |
tree | 550b146d4de0cc00a4784147f7d8f2a7bc93cffe /tvsaver/saver2v1/save_annotation_test.go | |
parent | f4fef41a45620391fca6481f4700b89de170ab88 (diff) | |
download | spdx-tools-cd59ee66408a908f7ef94548814514f6bc9fc906.tar.gz |
Create Go Module
- Unpack directory v0 to move all the content to the root directory.
- ./v0/* converted to ./*
- all the test cases were fixed to remove one directory less indexing for test files
- add go.mod
- go version 1.13 is used to have a relatively stable versioning system
Signed-off-by: RishabhBhatnagar <bhatnagarrishabh4@gmail.com>
Diffstat (limited to 'tvsaver/saver2v1/save_annotation_test.go')
-rw-r--r-- | tvsaver/saver2v1/save_annotation_test.go | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/tvsaver/saver2v1/save_annotation_test.go b/tvsaver/saver2v1/save_annotation_test.go new file mode 100644 index 0000000..077e9f8 --- /dev/null +++ b/tvsaver/saver2v1/save_annotation_test.go @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package saver2v1 + +import ( + "bytes" + "testing" + + "github.com/spdx/tools-golang/spdx" +) + +// ===== Annotation section Saver tests ===== +func TestSaver2_1AnnotationSavesTextForPerson(t *testing.T) { + ann := &spdx.Annotation2_1{ + Annotator: "John Doe", + AnnotatorType: "Person", + AnnotationDate: "2018-10-10T17:52:00Z", + AnnotationType: "REVIEW", + AnnotationSPDXIdentifier: "SPDXRef-DOCUMENT", + AnnotationComment: "This is an annotation about the SPDX document", + } + + // what we want to get, as a buffer of bytes + // no trailing blank newline + want := bytes.NewBufferString(`Annotator: Person: John Doe +AnnotationDate: 2018-10-10T17:52:00Z +AnnotationType: REVIEW +SPDXREF: SPDXRef-DOCUMENT +AnnotationComment: This is an annotation about the SPDX document +`) + + // render as buffer of bytes + var got bytes.Buffer + err := renderAnnotation2_1(ann, &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_1AnnotationSavesTextForOrganization(t *testing.T) { + ann := &spdx.Annotation2_1{ + Annotator: "John Doe, Inc.", + AnnotatorType: "Organization", + AnnotationDate: "2018-10-10T17:52:00Z", + AnnotationType: "REVIEW", + AnnotationSPDXIdentifier: "SPDXRef-DOCUMENT", + AnnotationComment: "This is an annotation about the SPDX document", + } + + // what we want to get, as a buffer of bytes + // no trailing blank newline + want := bytes.NewBufferString(`Annotator: Organization: John Doe, Inc. +AnnotationDate: 2018-10-10T17:52:00Z +AnnotationType: REVIEW +SPDXREF: SPDXRef-DOCUMENT +AnnotationComment: This is an annotation about the SPDX document +`) + + // render as buffer of bytes + var got bytes.Buffer + err := renderAnnotation2_1(ann, &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_1AnnotationSavesTextForTool(t *testing.T) { + ann := &spdx.Annotation2_1{ + Annotator: "magictool-1.1", + AnnotatorType: "Tool", + AnnotationDate: "2018-10-10T17:52:00Z", + AnnotationType: "REVIEW", + AnnotationSPDXIdentifier: "SPDXRef-DOCUMENT", + AnnotationComment: "This is an annotation about the SPDX document", + } + + // what we want to get, as a buffer of bytes + // no trailing blank newline + want := bytes.NewBufferString(`Annotator: Tool: magictool-1.1 +AnnotationDate: 2018-10-10T17:52:00Z +AnnotationType: REVIEW +SPDXREF: SPDXRef-DOCUMENT +AnnotationComment: This is an annotation about the SPDX document +`) + + // render as buffer of bytes + var got bytes.Buffer + err := renderAnnotation2_1(ann, &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()) + } +} + +// note that the annotation has no optional or multiple fields |