diff --git a/pkg/patch/cmd_test.go b/pkg/patch/cmd_test.go index d95eef74..0672e81c 100644 --- a/pkg/patch/cmd_test.go +++ b/pkg/patch/cmd_test.go @@ -23,6 +23,11 @@ func TestNewPatchCmd(t *testing.T) { args: []string{"-i", "images/python:3.7-alpine", "-t", "3.7-alpine-patched"}, expected: "required flag(s) \"report\" not set", }, + { + name: "Missing report flag with ignore-errors flag", + args: []string{"-i", "images/python:3.7-alpine", "-t", "3.7-alpine-patched", "--ignore-errors"}, + expected: "required flag(s) \"report\" not set", + }, } // Run test cases diff --git a/pkg/pkgmgr/apk_test.go b/pkg/pkgmgr/apk_test.go index d2157de1..5d2794a9 100644 --- a/pkg/pkgmgr/apk_test.go +++ b/pkg/pkgmgr/apk_test.go @@ -103,17 +103,19 @@ func TestValidateAPKPackageVersions(t *testing.T) { // Define some test cases with inputs and expected outputs testCases := []struct { - name string - updates types.UpdatePackages - cmp VersionComparer - resultsPath string - expectedErr error + name string + updates types.UpdatePackages + cmp VersionComparer + resultsPath string + ignoreErrors bool + expectedErr error }{ { name: "valid updates", updates: []types.UpdatePackage{{Name: "apk-tools", Version: "2.12.7-r0"}, {Name: "busybox", Version: "1.33.1-r8"}}, cmp: apkComparer, resultsPath: "testdata/apk_valid.txt", + ignoreErrors: false, expectedErr: nil, }, { @@ -121,13 +123,23 @@ func TestValidateAPKPackageVersions(t *testing.T) { updates: []types.UpdatePackage{{Name: "apk-tools", Version: "1.0"}, {Name: "busybox", Version: "2.0"}}, cmp: apkComparer, resultsPath: "testdata/apk_invalid.txt", + ignoreErrors: false, expectedErr: fmt.Errorf("2 errors occurred:\n\t* invalid version x.y found for package apk-tools\n\t* invalid version a.b.c found for package busybox"), }, + { + name: "invalid version with ignore errors", + updates: []types.UpdatePackage{{Name: "apk-tools", Version: "1.0"}, {Name: "busybox", Version: "2.0"}}, + cmp: apkComparer, + resultsPath: "testdata/apk_valid.txt", + ignoreErrors: true, + expectedErr: nil, + }, { name: "expected 2 updates, installed 1", updates: []types.UpdatePackage{{Name: "apk-tools", Version: "2.12.7-r0"}}, cmp: apkComparer, resultsPath: "testdata/apk_valid.txt", + ignoreErrors: false, expectedErr: fmt.Errorf("expected 2 updates, installed 1"), }, } @@ -136,7 +148,7 @@ func TestValidateAPKPackageVersions(t *testing.T) { // Use t.Run to run each test case as a subtest t.Run(tc.name, func(t *testing.T) { // Run the function to be tested - err := validateAPKPackageVersions(tc.updates, tc.cmp, tc.resultsPath, false) + err := validateAPKPackageVersions(tc.updates, tc.cmp, tc.resultsPath, tc.ignoreErrors) if tc.expectedErr != nil { if err == nil || errors.Is(err, tc.expectedErr) { t.Errorf("expected error %v, got %v", tc.expectedErr, err) diff --git a/pkg/pkgmgr/rpm_test.go b/pkg/pkgmgr/rpm_test.go index c2f23265..9d816d5e 100644 --- a/pkg/pkgmgr/rpm_test.go +++ b/pkg/pkgmgr/rpm_test.go @@ -260,6 +260,7 @@ func TestValidateRPMPackageVersions(t *testing.T) { updates types.UpdatePackages cmp VersionComparer resultsPath string + ignoreErrors bool expectedError error }{ { @@ -268,8 +269,9 @@ func TestValidateRPMPackageVersions(t *testing.T) { {Name: "openssl", Version: "1.1.1k-21.cm2"}, {Name: "openssl-libs", Version: "1.1.1k-21.cm2"}, }, - cmp: rpmComparer, - resultsPath: "testdata/rpm_valid.txt", + cmp: rpmComparer, + resultsPath: "testdata/rpm_valid.txt", + ignoreErrors: false, }, { name: "downloaded package version lower than required", @@ -279,8 +281,20 @@ func TestValidateRPMPackageVersions(t *testing.T) { }, cmp: rpmComparer, resultsPath: "testdata/rpm_valid.txt", + ignoreErrors: false, expectedError: fmt.Errorf("2 errors occurred:\n\t* downloaded package openssl version 2.1.1k-21.cm2 lower than required 3.1.1k-21.cm2 for update\n\t* downloaded package openssl-libs version 2.1.1k-21.cm2 lower than required 3.1.1k-21.cm2 for update"), // nolint:lll }, + { + name: "downloaded package version lower than required with ignore errors", + updates: types.UpdatePackages{ + {Name: "openssl", Version: "3.1.1k-21.cm2"}, + {Name: "openssl-libs", Version: "3.1.1k-21.cm2"}, + }, + cmp: rpmComparer, + resultsPath: "testdata/rpm_valid.txt", + ignoreErrors: true, + expectedError: nil, + }, { name: "unexpected number of installed packages", updates: types.UpdatePackages{ @@ -294,7 +308,7 @@ func TestValidateRPMPackageVersions(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - err := validateRPMPackageVersions(tc.updates, tc.cmp, tc.resultsPath, false) + err := validateRPMPackageVersions(tc.updates, tc.cmp, tc.resultsPath, tc.ignoreErrors) if tc.expectedError != nil { if err == nil || errors.Is(err, tc.expectedError) { t.Errorf("expected error %v, got %v", tc.expectedError, err)