Skip to content

Commit beadec5

Browse files
committed
feat: support checking versions exist in CRAN
Signed-off-by: Gareth Jones <3151613+G-Rath@users.noreply.github.com>
1 parent 5d0ec32 commit beadec5

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

tools/osv-linter/internal/pkgchecker/ecosystems.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func VersionsExistInEcosystem(pkg string, versions []string, ecosystem string) e
143143
case "Chainguard":
144144
return nil
145145
case "CRAN":
146-
return nil
146+
return versionsExistInCran(pkg, versions)
147147
case "crates.io":
148148
return versionsExistInCrates(pkg, versions)
149149
case "Debian":

tools/osv-linter/internal/pkgchecker/ecosystems_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,70 @@ package pkgchecker
22

33
import "testing"
44

5+
func Test_versionsExistInCran(t *testing.T) {
6+
t.Parallel()
7+
8+
type args struct {
9+
pkg string
10+
versions []string
11+
}
12+
tests := []struct {
13+
name string
14+
args args
15+
wantErr bool
16+
}{
17+
{
18+
name: "multiple_versions_which_all_exist",
19+
args: args{
20+
pkg: "gdata",
21+
versions: []string{"2.7.1", "2.12.0.2", "2.18.0.1", "2.19.0"},
22+
},
23+
wantErr: false,
24+
},
25+
{
26+
name: "multiple_versions_with_one_that_does_not_exist",
27+
args: args{
28+
pkg: "gdata",
29+
versions: []string{"2.4.1", "2.9.1", "2.12.0"},
30+
},
31+
wantErr: true,
32+
},
33+
{
34+
name: "an_invalid_version",
35+
args: args{
36+
pkg: "gdata",
37+
versions: []string{"!"},
38+
},
39+
wantErr: true,
40+
},
41+
{
42+
name: "an_invalid_package",
43+
args: args{
44+
pkg: "!",
45+
versions: []string{"1.0.0"},
46+
},
47+
wantErr: true,
48+
},
49+
{
50+
name: "a_package_that_does_not_exit",
51+
args: args{
52+
pkg: "not-a-real-package-hopefully",
53+
versions: []string{"1.0.0"},
54+
},
55+
wantErr: true,
56+
},
57+
}
58+
for _, tt := range tests {
59+
t.Run(tt.name, func(t *testing.T) {
60+
t.Parallel()
61+
62+
if err := versionsExistInCran(tt.args.pkg, tt.args.versions); (err != nil) != tt.wantErr {
63+
t.Errorf("versionsExistInCran() error = %v, wantErr %v", err, tt.wantErr)
64+
}
65+
})
66+
}
67+
}
68+
569
func Test_versionsExistInCrates(t *testing.T) {
670
t.Parallel()
771

tools/osv-linter/internal/pkgchecker/version_check.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ func versionsExistInGeneric(
8989
return nil
9090
}
9191

92+
// Confirm that all specified versions of a package exist in CRAN.
93+
func versionsExistInCran(pkg string, versions []string) error {
94+
packageInstanceURL := fmt.Sprintf("%s/%s/all", EcosystemBaseURLs["CRAN"], pkg)
95+
96+
return versionsExistInGeneric(
97+
pkg, versions,
98+
"CRAN",
99+
packageInstanceURL,
100+
"versions.@keys",
101+
)
102+
}
103+
92104
// Confirm that all specified versions of a package exist in crates.io.
93105
func versionsExistInCrates(pkg string, versions []string) error {
94106
packageInstanceURL := fmt.Sprintf("%s/%s", EcosystemBaseURLs["crates.io"], pkg)

0 commit comments

Comments
 (0)