-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpurlvalidator_test.go
More file actions
84 lines (66 loc) · 1.89 KB
/
purlvalidator_test.go
File metadata and controls
84 lines (66 loc) · 1.89 KB
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
/*
Copyright (c) nexB Inc. and others. All rights reserved.
ScanCode is a trademark of nexB Inc.
SPDX-License-Identifier: Apache-2.0
See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
See https://github.com/aboutcode-org/purl-validator-go for support or download.
See https://aboutcode.org for more information about nexB OSS projects.
*/
package purlvalidator
import (
"log"
"os"
"testing"
"github.com/blevesearch/vellum"
)
var testValidator *vellum.FST
func TestMain(m *testing.M) {
setup()
code := m.Run()
os.Exit(code)
}
func setup() {
fstData, err := os.ReadFile("testdata/testpurls.fst")
if err != nil {
panic(err)
}
testValidator, err = vellum.Load(fstData)
if err != nil {
log.Fatal(err)
}
}
// `testpurls.fst` only contains following purls:
// - pkg:nuget/FluentUtils.EnumExtensions
// - pkg:nuget/FluentUtils.FromCompositeAttribute
// - pkg:nuget/FluentUtils.MediatR.Pagination
// - pkg:nuget/FluentUtils.MediatR.Pagination.AspNetCore
func TestNonexistentPurl(t *testing.T) {
purl := "pkg:nuget/nonexistent"
result, _ := validate_purl(purl, testValidator)
expected := false
if result != expected {
t.Errorf("Validate(\"%s\") = %t; expected %t", purl, result, expected)
}
}
func TestValidPurl(t *testing.T) {
purl := "pkg:nuget/FluentUtils.FromCompositeAttribute"
result, _ := validate_purl(purl, testValidator)
expected := true
if result != expected {
t.Errorf("validate_purl(\"%s\") = %t; expected %t", purl, result, expected)
}
}
func TestErrorForInvalidPurl(t *testing.T) {
purl := "test:nuget/FluentUtils.FromCompositeAttribute"
_, err := validate_purl(purl, testValidator)
if err == nil {
t.Errorf("expected error but got nil")
}
}
func TestErrorForUnsupportedPurl(t *testing.T) {
purl := "pkg:nuget/EnterpriseLibrary.Common@6.0.1304"
_, err := validate_purl(purl, testValidator)
if err == nil {
t.Errorf("expected error but got nil")
}
}