Skip to content

refactor: make generic #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tools/osv-linter/internal/pkgchecker/ecosystems.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func VersionsExistInEcosystem(pkg string, versions []string, ecosystem string) e
case "CRAN":
return nil
case "crates.io":
return nil
return versionsExistInCrates(pkg, versions)
case "Debian":
return nil
case "GIT":
Expand All @@ -145,7 +145,7 @@ func VersionsExistInEcosystem(pkg string, versions []string, ecosystem string) e
case "GSD":
return nil
case "Hackage":
return nil
return versionsExistInHackage(pkg, versions)
case "Hex":
return nil
case "Linux":
Expand All @@ -155,7 +155,7 @@ func VersionsExistInEcosystem(pkg string, versions []string, ecosystem string) e
case "MinimOS":
return nil
case "npm":
return nil
return versionsExistInNpm(pkg, versions)
case "NuGet":
return nil
case "openSUSE":
Expand Down
166 changes: 166 additions & 0 deletions tools/osv-linter/internal/pkgchecker/ecosystems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,70 @@ package pkgchecker

import "testing"

func Test_versionsExistInCrates(t *testing.T) {
t.Parallel()

type args struct {
pkg string
versions []string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "multiple_versions_which_all_exist",
args: args{
pkg: "defmt",
versions: []string{"0.0.0", "0.3.0", "0.3.100-rc.1", "1.0.0-rc.1", "1.0.1"},
},
wantErr: false,
},
{
name: "multiple_versions_with_one_that_does_not_exist",
args: args{
pkg: "defmt",
versions: []string{"1.1", "0.3.6-beta", "1.1.2"},
},
wantErr: true,
},
{
name: "an_invalid_version",
args: args{
pkg: "defmt",
versions: []string{"!"},
},
wantErr: true,
},
{
name: "an_invalid_package",
args: args{
pkg: "!",
versions: []string{"1.0.0"},
},
wantErr: true,
},
{
name: "a_package_that_does_not_exit",
args: args{
pkg: "not-a-real-package-hopefully",
versions: []string{"1.0.0"},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

if err := versionsExistInCrates(tt.args.pkg, tt.args.versions); (err != nil) != tt.wantErr {
t.Errorf("versionsExistInCrates() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

func Test_versionsExistInGo(t *testing.T) {
type args struct {
pkg string
Expand Down Expand Up @@ -38,6 +102,108 @@ func Test_versionsExistInGo(t *testing.T) {
}
}

func Test_versionsExistInHackage(t *testing.T) {
t.Parallel()

type args struct {
pkg string
versions []string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "multiple_versions_which_all_exist",
args: args{
pkg: "aeson",
versions: []string{"0.1.0.0", "1.4.7.1", "2.2.2.0"},
},
wantErr: false,
},
{
name: "multiple_versions_with_one_that_does_not_exist",
args: args{
pkg: "aeson",
versions: []string{"1.1", "2.0.0-beta1", "3.1.5", "2.2.2.2"},
},
wantErr: true,
},
{
name: "an_invalid_version",
args: args{
pkg: "aeson",
versions: []string{"!"},
},
wantErr: true,
},
{
name: "an_invalid_package",
args: args{
pkg: "!",
versions: []string{"1.0.0"},
},
wantErr: true,
},
{
name: "a_package_that_does_not_exit",
args: args{
pkg: "not-a-real-package-hopefully",
versions: []string{"1.0.0"},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

if err := versionsExistInHackage(tt.args.pkg, tt.args.versions); (err != nil) != tt.wantErr {
t.Errorf("versionsExistInHackage() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

func Test_versionsExistInNpm(t *testing.T) {
t.Parallel()

type args struct {
pkg string
versions []string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "an unreleased package",
args: args{
pkg: "github.com/nanobox-io/golang-nanoauth",
versions: nil,
},
wantErr: false,
},
{
name: "a released package",
args: args{
pkg: "github.com/oauth2-proxy/oauth2-proxy",
versions: []string{"1.1.1"},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := versionsExistInGo(tt.args.pkg, tt.args.versions); (err != nil) != tt.wantErr {
t.Errorf("versionsExistInGo() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

func Test_versionsExistInPackagist(t *testing.T) {
t.Parallel()

Expand Down
Loading
Loading