Skip to content

Commit

Permalink
test: restore old cases for deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Aug 29, 2024
1 parent c9e53ce commit df9ea40
Showing 1 changed file with 235 additions and 0 deletions.
235 changes: 235 additions & 0 deletions pkg/config/config_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,125 @@ func TestConfig_ShouldIgnorePackage(t *testing.T) {
}
}

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

type args struct {
name string
version string
ecosystem string
}
tests := []struct {
name string
config Config
args args
wantOk bool
wantEntry PackageOverrideEntry
}{
{
name: "Version-level entry exists",
config: Config{
PackageOverrides: []PackageOverrideEntry{
{
Name: "lib1",
Version: "1.0.0",
Ecosystem: "Go",
Ignore: true,
EffectiveUntil: time.Time{},
Reason: "abc",
},
},
},
args: args{
name: "lib1",
version: "1.0.0",
ecosystem: "Go",
},
wantOk: true,
wantEntry: PackageOverrideEntry{
Name: "lib1",
Version: "1.0.0",
Ecosystem: "Go",
Ignore: true,
EffectiveUntil: time.Time{},
Reason: "abc",
},
},
{
name: "Package-level entry exists",
config: Config{
PackageOverrides: []PackageOverrideEntry{
{
Name: "lib1",
Ecosystem: "Go",
Ignore: true,
EffectiveUntil: time.Time{},
Reason: "abc",
},
},
},
args: args{
name: "lib1",
version: "1.0.0",
ecosystem: "Go",
},
wantOk: true,
wantEntry: PackageOverrideEntry{
Name: "lib1",
Ecosystem: "Go",
Ignore: true,
EffectiveUntil: time.Time{},
Reason: "abc",
},
},
{
name: "Entry doesn't exist",
config: Config{
PackageOverrides: []PackageOverrideEntry{
{
Name: "lib1",
Version: "2.0.0",
Ecosystem: "Go",
Ignore: false,
EffectiveUntil: time.Time{},
Reason: "abc",
},
{
Name: "lib2",
Version: "2.0.0",
Ignore: true,
Ecosystem: "Go",
EffectiveUntil: time.Time{},
Reason: "abc",
},
},
},
args: args{
name: "lib1",
version: "2.0.0",
ecosystem: "Go",
},
wantOk: false,
wantEntry: PackageOverrideEntry{},
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

gotOk, gotEntry := tt.config.ShouldIgnorePackageVersion(tt.args.name, tt.args.version, tt.args.ecosystem)
if gotOk != tt.wantOk {
t.Errorf("ShouldIgnorePackageVersion() gotOk = %v, wantOk %v", gotOk, tt.wantOk)
}
if !reflect.DeepEqual(gotEntry, tt.wantEntry) {
t.Errorf("ShouldIgnorePackageVersion() gotEntry = %v, wantEntry %v", gotEntry, tt.wantEntry)
}
})
}
}

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

Expand Down Expand Up @@ -765,3 +884,119 @@ func TestConfig_ShouldOverridePackageLicense(t *testing.T) {
})
}
}

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

type args struct {
name string
version string
ecosystem string
}
tests := []struct {
name string
config Config
args args
wantOk bool
wantEntry PackageOverrideEntry
}{
{
name: "Exact version entry exists",
config: Config{
PackageOverrides: []PackageOverrideEntry{
{
Name: "lib1",
Version: "1.0.0",
Ecosystem: "Go",
License: License{
Override: []string{"mit"},
},
Reason: "abc",
},
},
},
args: args{
name: "lib1",
version: "1.0.0",
ecosystem: "Go",
},
wantOk: true,
wantEntry: PackageOverrideEntry{
Name: "lib1",
Version: "1.0.0",
Ecosystem: "Go",
License: License{
Override: []string{"mit"},
},
Reason: "abc",
},
},
{
name: "Version entry doesn't exist",
config: Config{
PackageOverrides: []PackageOverrideEntry{
{
Name: "lib1",
Version: "1.0.0",
Ecosystem: "Go",
License: License{
Override: []string{"mit"},
},
Reason: "abc",
},
},
},
args: args{
name: "lib1",
version: "1.0.1",
ecosystem: "Go",
},
wantOk: false,
wantEntry: PackageOverrideEntry{},
},
{
name: "Name matches",
config: Config{
PackageOverrides: []PackageOverrideEntry{
{
Name: "lib1",
Ecosystem: "Go",
License: License{
Override: []string{"mit"},
},
Reason: "abc",
},
},
},
args: args{
name: "lib1",
version: "1.0.1",
ecosystem: "Go",
},
wantOk: true,
wantEntry: PackageOverrideEntry{
Name: "lib1",
Ecosystem: "Go",
License: License{
Override: []string{"mit"},
},
Reason: "abc",
},
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

gotOk, gotEntry := tt.config.ShouldOverridePackageVersionLicense(tt.args.name, tt.args.version, tt.args.ecosystem)
if gotOk != tt.wantOk {
t.Errorf("ShouldOverridePackageVersionLicense() gotOk = %v, wantOk %v", gotOk, tt.wantOk)
}
if !reflect.DeepEqual(gotEntry, tt.wantEntry) {
t.Errorf("ShouldOverridePackageVersionLicense() gotEntry = %v, wantEntry %v", gotEntry, tt.wantEntry)
}
})
}
}

0 comments on commit df9ea40

Please sign in to comment.