Skip to content

Commit

Permalink
JsonParser : JsonParser test coverage increased
Browse files Browse the repository at this point in the history
Signed-off-by: Ujjwal Agarwal <ujjwalcoding012@gmail.com>
  • Loading branch information
specter25 committed Aug 13, 2021
1 parent dbd63ea commit f679856
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
12 changes: 5 additions & 7 deletions jsonloader/parser2v2/parse_files_test.go
Expand Up @@ -197,13 +197,11 @@ func TestJSONSpdxDocument_parseJsonFiles2_2(t *testing.T) {
t.Errorf("JSONSpdxDocument.parseJsonFiles2_2() error = %v, wantErr %v", err, tt.wantErr)
}

// if !reflect.DeepEqual(tt.args.doc.UnpackagedFiles, tt.want) {
// t.Errorf("Load2_2() = %v, want %v", tt.args.doc.UnpackagedFiles, tt.want)
// }

for k, v := range tt.want {
if !reflect.DeepEqual(tt.args.doc.UnpackagedFiles[k], v) {
t.Errorf("Load2_2() = %v, want %v", tt.args.doc.UnpackagedFiles[k], v)
if !tt.wantErr {
for k, v := range tt.want {
if !reflect.DeepEqual(tt.args.doc.UnpackagedFiles[k], v) {
t.Errorf("Load2_2() = %v, want %v", tt.args.doc.UnpackagedFiles[k], v)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion jsonloader/parser2v2/parse_other_license.go
Expand Up @@ -34,7 +34,7 @@ func (spec JSONSpdxDocument) parseJsonOtherLicenses2_2(key string, value interfa
}
}
default:
return fmt.Errorf("received unknown tag %v in Annotation section", k)
return fmt.Errorf("received unknown tag %v in Licenses section", k)
}
}
doc.OtherLicenses = append(doc.OtherLicenses, &license)
Expand Down
31 changes: 27 additions & 4 deletions jsonloader/parser2v2/parse_other_license_test.go
Expand Up @@ -45,9 +45,20 @@ func TestJSONSpdxDocument_parseJsonOtherLicenses2_2(t *testing.T) {
},
}

otherLicensestest2 := []byte(`{
"hasExtractedLicensingInfos":[{
"extractedText" : "\"THE BEER-WARE LICENSE\" (Revision 42):\nphk@FreeBSD.ORG wrote this file. As long as you retain this notice you\ncan do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp </\nLicenseName: Beer-Ware License (Version 42)\nLicenseCrossReference: http://people.freebsd.org/~phk/\nLicenseComment: \nThe beerware license has a couple of other standard variants.",
"licensd" : "LicenseRef-Beerware-4.2"
}]
}
`)

var specs JSONSpdxDocument
json.Unmarshal(jsonData, &specs)

var specs2 JSONSpdxDocument
json.Unmarshal(otherLicensestest2, &specs2)

type args struct {
key string
value interface{}
Expand All @@ -72,19 +83,31 @@ func TestJSONSpdxDocument_parseJsonOtherLicenses2_2(t *testing.T) {
want: otherLicensestest1,
wantErr: false,
},
{
name: "failure test --> unknown tag",
spec: specs2,
args: args{
key: "hasExtractedLicensingInfos",
value: specs2["hasExtractedLicensingInfos"],
doc: &spdxDocument2_2{},
},
want: nil,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.spec.parseJsonOtherLicenses2_2(tt.args.key, tt.args.value, tt.args.doc); (err != nil) != tt.wantErr {
t.Errorf("JSONSpdxDocument.parseJsonOtherLicenses2_2() error = %v, wantErr %v", err, tt.wantErr)
}

for i := 0; i < len(tt.want); i++ {
if !reflect.DeepEqual(tt.args.doc.OtherLicenses[i], tt.want[i]) {
t.Errorf("Load2_2() = %v, want %v", tt.args.doc.OtherLicenses[i], tt.want[i])
if !tt.wantErr {
for i := 0; i < len(tt.want); i++ {
if !reflect.DeepEqual(tt.args.doc.OtherLicenses[i], tt.want[i]) {
t.Errorf("Load2_2() = %v, want %v", tt.args.doc.OtherLicenses[i], tt.want[i])
}
}
}

})
}
}

0 comments on commit f679856

Please sign in to comment.