Skip to content

Commit f47e8b9

Browse files
committed
feat: support checking if versions exist in Hackage
Signed-off-by: Gareth Jones <[email protected]>
1 parent 361f8f8 commit f47e8b9

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
@@ -145,7 +145,7 @@ func VersionsExistInEcosystem(pkg string, versions []string, ecosystem string) e
145145
case "GSD":
146146
return nil
147147
case "Hackage":
148-
return nil
148+
return versionsExistInHackage(pkg, versions)
149149
case "Hex":
150150
return nil
151151
case "Linux":

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,70 @@ func Test_versionsExistInGo(t *testing.T) {
3838
}
3939
}
4040

41+
func Test_versionsExistInHackage(t *testing.T) {
42+
t.Parallel()
43+
44+
type args struct {
45+
pkg string
46+
versions []string
47+
}
48+
tests := []struct {
49+
name string
50+
args args
51+
wantErr bool
52+
}{
53+
{
54+
name: "multiple_versions_which_all_exist",
55+
args: args{
56+
pkg: "aeson",
57+
versions: []string{"0.1.0.0", "1.4.7.1", "2.2.2.0"},
58+
},
59+
wantErr: false,
60+
},
61+
{
62+
name: "multiple_versions_with_one_that_does_not_exist",
63+
args: args{
64+
pkg: "aeson",
65+
versions: []string{"1.1", "2.0.0-beta1", "3.1.5", "2.2.2.2"},
66+
},
67+
wantErr: true,
68+
},
69+
{
70+
name: "an_invalid_version",
71+
args: args{
72+
pkg: "aeson",
73+
versions: []string{"!"},
74+
},
75+
wantErr: true,
76+
},
77+
{
78+
name: "an_invalid_package",
79+
args: args{
80+
pkg: "!",
81+
versions: []string{"1.0.0"},
82+
},
83+
wantErr: true,
84+
},
85+
{
86+
name: "a_package_that_does_not_exit",
87+
args: args{
88+
pkg: "not-a-real-package-hopefully",
89+
versions: []string{"1.0.0"},
90+
},
91+
wantErr: true,
92+
},
93+
}
94+
for _, tt := range tests {
95+
t.Run(tt.name, func(t *testing.T) {
96+
t.Parallel()
97+
98+
if err := versionsExistInHackage(tt.args.pkg, tt.args.versions); (err != nil) != tt.wantErr {
99+
t.Errorf("versionsExistInHackage() error = %v, wantErr %v", err, tt.wantErr)
100+
}
101+
})
102+
}
103+
}
104+
41105
func Test_versionsExistInNpm(t *testing.T) {
42106
t.Parallel()
43107

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,18 @@ func goVersionsExist(versions []string) error {
186186
return nil
187187
}
188188

189+
// Confirm that all specified versions of a package exist in RubyGems.
190+
func versionsExistInHackage(pkg string, versions []string) error {
191+
packageInstanceURL := fmt.Sprintf("%s/%s.json", EcosystemBaseURLs["Hackage"], pkg)
192+
193+
return versionsExistInGeneric(
194+
pkg, versions,
195+
"Hackage",
196+
packageInstanceURL,
197+
"@keys", "@this",
198+
)
199+
}
200+
189201
// Confirm that all specified versions of a package exist in RubyGems.
190202
func versionsExistInNpm(pkg string, versions []string) error {
191203
packageInstanceURL := fmt.Sprintf("%s/%s", EcosystemBaseURLs["npm"], pkg)

0 commit comments

Comments
 (0)