Skip to content

Commit

Permalink
test: create tests for force upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
majori committed Jun 13, 2024
1 parent 632a848 commit 9ffcd5e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/features/upgrade-recipe.feature
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,26 @@ Feature: Upgrade sauce
And I change recipe "foo" template "new.txt" to render "new"
When I upgrade recipe "foo"
Then CLI produced an error "file conflicts"

Scenario: Attempt force upgrade
Given a recipe "foo"
And recipe "foo" generates file "README.md" with content "initial"
And I execute recipe "foo"
And I change recipe "foo" to version "v0.0.2"
And I change recipe "foo" template "README.md" to render "New version"
And I change recipe "foo" template "ANOTHER.md" to render "New version"
When I upgrade recipe "foo" forcefully
Then CLI produced an output "README\.md \(modified\)"
Then CLI produced an output "ANOTHER\.md \(added\)"
And the project directory should contain file "README.md" with "New version"

Scenario: Attempt force upgrade when there is a locally modified file
Given a recipe "foo"
And recipe "foo" generates file "README.md" with content "initial"
And I execute recipe "foo"
And I change recipe "foo" to version "v0.0.2"
And I change recipe "foo" template "README.md" to render "New version"
And I change project file "README.md" to contain "Locally modified"
When I upgrade recipe "foo" forcefully
Then CLI produced an output "README\.md \(modified\)"
And the project directory should contain file "README.md" with "New version"
8 changes: 8 additions & 0 deletions test/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

func AddUpgradeSteps(s *godog.ScenarioContext) {
s.Step(`^I upgrade recipe "([^"]*)"$`, iRunUpgrade)
s.Step(`^I upgrade recipe "([^"]*)" forcefully$`, iRunUpgradeWithForce)
s.Step(`^I upgrade recipe from the local OCI repository "([^"]*)"$`, iRunUpgradeFromRemoteRecipe)
s.Step(`^no conflicts were reported$`, noConflictsWereReported)
s.Step(`^conflicts are reported$`, conflictsAreReported)
Expand Down Expand Up @@ -50,6 +51,13 @@ func iRunUpgrade(ctx context.Context, recipe string) (context.Context, error) {
return executeCLI(ctx, args...)
}

func iRunUpgradeWithForce(ctx context.Context, recipe string) (context.Context, error) {
additionalFlags := ctx.Value(cmdAdditionalFlagsCtxKey{}).(map[string]string)
additionalFlags["force"] = "true"

return iRunUpgrade(ctx, recipe)
}

func iRunUpgradeFromRemoteRecipe(ctx context.Context, repository string) (context.Context, error) {
registry := ctx.Value(ociRegistryCtxKey{}).(OCIRegistry)
url := fmt.Sprintf("oci://%s/%s", registry.Resource.GetHostPort("5000/tcp"), repository)
Expand Down

0 comments on commit 9ffcd5e

Please sign in to comment.