aboutsummaryrefslogtreecommitdiff
path: root/jsonsaver/saver2v2/save_files_test.go
blob: c2e61d8daf5c9b192ad0b64bf941d06fb5b79c0a (plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later

package saver2v2

import (
	"reflect"
	"testing"

	"github.com/spdx/tools-golang/spdx"
)

func Test_renderFiles2_2(t *testing.T) {
	type args struct {
		doc          *spdx.Document2_2
		jsondocument map[string]interface{}
	}
	tests := []struct {
		name    string
		args    args
		want    []interface{}
		wantErr bool
	}{
		// TODO: Add test cases.
		{
			name: "",
			args: args{
				doc: &spdx.Document2_2{
					Annotations: []*spdx.Annotation2_2{
						{
							AnnotationSPDXIdentifier: spdx.DocElementID{DocumentRefID: "", ElementRefID: "File"},
							AnnotationDate:           "2011-01-29T18:30:22Z",
							AnnotationType:           "OTHER",
							AnnotatorType:            "Person",
							Annotator:                "File Commenter",
							AnnotationComment:        "File level annotation",
						},
						{
							AnnotationSPDXIdentifier: spdx.DocElementID{DocumentRefID: "", ElementRefID: "Package"},
							AnnotationDate:           "2011-01-29T18:30:22Z",
							AnnotationType:           "OTHER",
							AnnotatorType:            "Person",
							Annotator:                "Package Commenter",
							AnnotationComment:        "Package level annotation",
						},
						{
							AnnotationSPDXIdentifier: spdx.DocElementID{DocumentRefID: "", ElementRefID: "DOCUMENT"},
							AnnotationDate:           "2010-02-10T00:00:00Z",
							AnnotationType:           "REVIEW",
							AnnotatorType:            "Person",
							Annotator:                "Joe Reviewer",
							AnnotationComment:        "This is just an example.  Some of the non-standard licenses look like they are actually BSD 3 clause licenses",
						},
						{
							AnnotationSPDXIdentifier: spdx.DocElementID{DocumentRefID: "", ElementRefID: "DOCUMENT"},
							AnnotationDate:           "2011-03-13T00:00:00Z",
							AnnotationType:           "REVIEW",
							AnnotatorType:            "Person",
							Annotator:                "Suzanne Reviewer",
							AnnotationComment:        "Another example reviewer.",
						},
						{
							AnnotationSPDXIdentifier: spdx.DocElementID{DocumentRefID: "", ElementRefID: "DOCUMENT"},
							AnnotationDate:           "2010-01-29T18:30:22Z",
							AnnotationType:           "OTHER",
							AnnotatorType:            "Person",
							Annotator:                "Jane Doe ()",
							AnnotationComment:        "Document level annotation",
						},
					},
					UnpackagedFiles: map[spdx.ElementID]*spdx.File2_2{
						"File": {
							FileSPDXIdentifier: "File",
							FileChecksums: map[spdx.ChecksumAlgorithm]spdx.Checksum{
								"SHA1": {
									Algorithm: "SHA1",
									Value:     "d6a770ba38583ed4bb4525bd96e50461655d2758",
								},
								// "MD5": {
								// 	Algorithm: "MD5",
								// 	Value:     "624c1abb3664f4b35547e7c73864ad24",
								// },
							},
							FileComment:          "The concluded license was taken from the package level that the file was .",
							FileCopyrightText:    "Copyright 2008-2010 John Smith",
							FileContributor:      []string{"The Regents of the University of California", "Modified by Paul Mundt lethal@linux-sh.org", "IBM Corporation"},
							FileName:             "./package/foo.c",
							FileType:             []string{"SOURCE"},
							LicenseComments:      "The concluded license was taken from the package level that the file was included in.",
							LicenseConcluded:     "(LGPL-2.0-only OR LicenseRef-2)",
							LicenseInfoInFile:    []string{"GPL-2.0-only", "LicenseRef-2"},
							FileNotice:           "Copyright (c) 2001 Aaron Lehmann aaroni@vitelus.",
							FileAttributionTexts: []string{"text1", "text2 "},
						},
					},
				},
				jsondocument: make(map[string]interface{}),
			},
			want: []interface{}{
				map[string]interface{}{
					"SPDXID": "SPDXRef-File",
					"annotations": []interface{}{
						map[string]interface{}{
							"annotationDate": "2011-01-29T18:30:22Z",
							"annotationType": "OTHER",
							"annotator":      "Person: File Commenter",
							"comment":        "File level annotation",
						},
					},
					"checksums": []interface{}{
						map[string]interface{}{
							"algorithm":     "SHA1",
							"checksumValue": "d6a770ba38583ed4bb4525bd96e50461655d2758",
						},
						// map[string]interface{}{
						// 	"algorithm":     "MD5",
						// 	"checksumValue": "624c1abb3664f4b35547e7c73864ad24",
						// },
					},
					"comment":            "The concluded license was taken from the package level that the file was .",
					"copyrightText":      "Copyright 2008-2010 John Smith",
					"fileContributors":   []string{"The Regents of the University of California", "Modified by Paul Mundt lethal@linux-sh.org", "IBM Corporation"},
					"fileName":           "./package/foo.c",
					"fileTypes":          []string{"SOURCE"},
					"licenseComments":    "The concluded license was taken from the package level that the file was included in.",
					"licenseConcluded":   "(LGPL-2.0-only OR LicenseRef-2)",
					"licenseInfoInFiles": []string{"GPL-2.0-only", "LicenseRef-2"},
					"noticeText":         "Copyright (c) 2001 Aaron Lehmann aaroni@vitelus.",
					"attributionTexts":   []string{"text1", "text2 "},
				},
			},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got, err := renderFiles2_2(tt.args.doc, tt.args.jsondocument)
			if (err != nil) != tt.wantErr {
				t.Errorf("renderFiles2_2() error = %v, wantErr %v", err, tt.wantErr)
			}
			for k, v := range got {
				if !reflect.DeepEqual(v, tt.want[k]) {
					t.Errorf("renderFiles2_2() error = %v, want %v", v, tt.want[k])
				}
			}

		})
	}
}