-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add backwards compatibility validation to package deploy (#1909)
## Description - Adds the latest version of Zarf with no breaking package structure changes to build metadata in packages on `package create` - Validates the running Zarf CLI version is not less (older) than the last non-breaking version in a package on `package deploy`. Zarf will throw a warning to the user if the CLI version is older than the last non-breaking version to warn before deploying packages that are potentially affected by breaking changes. ## Related Issue Fixes #1760 ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Other (security config, docs update, etc) ## Checklist before merging - [x] Test, docs, adr added or updated as needed - [x] [Contributor Guide Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow) followed --------- Co-authored-by: Wayne Starr <[email protected]>
- Loading branch information
1 parent
910846e
commit b6611b3
Showing
10 changed files
with
210 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package packager | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/defenseunicorns/zarf/src/config" | ||
"github.com/defenseunicorns/zarf/src/config/lang" | ||
"github.com/defenseunicorns/zarf/src/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestValidateLastNonBreakingVersion verifies that Zarf validates the lastNonBreakingVersion of packages against the CLI version correctly. | ||
func TestValidateLastNonBreakingVersion(t *testing.T) { | ||
t.Parallel() | ||
|
||
type testCase struct { | ||
name string | ||
cliVersion string | ||
lastNonBreakingVersion string | ||
expectedErrorMessage string | ||
expectedWarningMessage string | ||
returnError bool | ||
throwWarning bool | ||
} | ||
|
||
testCases := []testCase{ | ||
{ | ||
name: "CLI version less than lastNonBreakingVersion", | ||
cliVersion: "v0.26.4", | ||
lastNonBreakingVersion: "v0.27.0", | ||
returnError: false, | ||
throwWarning: true, | ||
expectedWarningMessage: fmt.Sprintf( | ||
lang.CmdPackageDeployValidateLastNonBreakingVersionWarn, | ||
"v0.26.4", | ||
"v0.27.0", | ||
"v0.27.0", | ||
), | ||
}, | ||
{ | ||
name: "invalid semantic version (CLI version)", | ||
cliVersion: "invalidSemanticVersion", | ||
lastNonBreakingVersion: "v0.0.1", | ||
throwWarning: false, | ||
returnError: true, | ||
expectedErrorMessage: "unable to parse Zarf CLI version", | ||
}, | ||
{ | ||
name: "invalid semantic version (lastNonBreakingVersion)", | ||
cliVersion: "v0.0.1", | ||
lastNonBreakingVersion: "invalidSemanticVersion", | ||
throwWarning: false, | ||
returnError: true, | ||
expectedErrorMessage: "unable to parse lastNonBreakingVersion", | ||
}, | ||
{ | ||
name: "CLI version greater than lastNonBreakingVersion", | ||
cliVersion: "v0.28.2", | ||
lastNonBreakingVersion: "v0.27.0", | ||
returnError: false, | ||
throwWarning: false, | ||
}, | ||
{ | ||
name: "CLI version equal to lastNonBreakingVersion", | ||
cliVersion: "v0.27.0", | ||
lastNonBreakingVersion: "v0.27.0", | ||
returnError: false, | ||
throwWarning: false, | ||
}, | ||
{ | ||
name: "empty lastNonBreakingVersion", | ||
cliVersion: "this shouldn't get evaluated when the lastNonBreakingVersion is empty", | ||
lastNonBreakingVersion: "", | ||
returnError: false, | ||
throwWarning: false, | ||
}, | ||
{ | ||
name: "default CLI version in E2E tests", | ||
cliVersion: "UnknownVersion", // This is used as a default version in the E2E tests | ||
lastNonBreakingVersion: "v0.27.0", | ||
returnError: false, | ||
throwWarning: false, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
testCase := testCase | ||
|
||
t.Run(testCase.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
config.CLIVersion = testCase.cliVersion | ||
|
||
p := &Packager{ | ||
cfg: &types.PackagerConfig{ | ||
Pkg: types.ZarfPackage{ | ||
Build: types.ZarfBuildData{ | ||
LastNonBreakingVersion: testCase.lastNonBreakingVersion, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err := p.validateLastNonBreakingVersion() | ||
|
||
switch { | ||
case testCase.returnError: | ||
assert.ErrorContains(t, err, testCase.expectedErrorMessage) | ||
assert.Empty(t, p.warnings, "Expected no warnings for test case: %s", testCase.name) | ||
case testCase.throwWarning: | ||
assert.Contains(t, p.warnings, testCase.expectedWarningMessage) | ||
assert.NoError(t, err, "Expected no error for test case: %s", testCase.name) | ||
default: | ||
assert.NoError(t, err, "Expected no error for test case: %s", testCase.name) | ||
assert.Empty(t, p.warnings, "Expected no warnings for test case: %s", testCase.name) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters