aboutsummaryrefslogtreecommitdiff
path: root/jsonloader/jsonloader_test.go
blob: e90a6a58e7c56a99e38331f35d698a95134bc56d (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
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later

package jsonloader

import (
	"bytes"
	"fmt"
	"io"
	"os"
	"reflect"
	"testing"

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

func TestLoad2_2(t *testing.T) {

	file, err := os.Open("./parser2v2/jsonfiles/jsonloadertest.json")
	if err != nil {
		panic(fmt.Errorf("error opening File: %s", err))
	}

	type args struct {
		content io.Reader
	}
	tests := []struct {
		name    string
		args    args
		want    *spdx.Document2_2
		wantErr bool
	}{
		// TODO: Add test cases.
		{
			name: "success test",
			args: args{
				content: file,
			},
			want: &spdx.Document2_2{
				CreationInfo: &spdx.CreationInfo2_2{
					DataLicense:                "CC0-1.0",
					SPDXVersion:                "SPDX-2.2",
					SPDXIdentifier:             "DOCUMENT",
					DocumentName:               "SPDX-Tools-v2.0",
					ExternalDocumentReferences: make(map[string]spdx.ExternalDocumentRef2_2),
				},
			},
			wantErr: false,
		},
		{
			name: "fail - invalidjson ",
			args: args{
				content: bytes.NewReader([]byte(`{"Hello":"HI",}`)),
			},
			want:    nil,
			wantErr: true,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got, err := Load2_2(tt.args.content)
			if (err != nil) != tt.wantErr {
				t.Errorf("Load2_2() error = %v, wantErr %v", err, tt.wantErr)
				return
			}
			if !tt.wantErr && !reflect.DeepEqual(got.CreationInfo, tt.want.CreationInfo) {
				t.Errorf("Load2_2() = %v, want %v", got.CreationInfo, tt.want.CreationInfo)
			}
		})
	}
}