Skip to content

Commit

Permalink
fix: retain CheckFrom URL from old sauce
Browse files Browse the repository at this point in the history
  • Loading branch information
majori committed Feb 5, 2024
1 parent 6026de1 commit b1eef93
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
24 changes: 15 additions & 9 deletions internal/cli/cmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,13 @@ func theProjectDirectoryShouldContainFileWith(ctx context.Context, filename, sea
if err != nil {
return err
}
if !strings.Contains(content, searchTerm) {
return fmt.Errorf("substring '%s' not found in file %s", searchTerm, filename)

if matched, err := regexp.MatchString(searchTerm, content); err != nil {
return fmt.Errorf("regexp pattern matching caused an error: %w", err)
} else if !matched {
return fmt.Errorf("the file '%s' did not match the following pattern '%s'", filename, searchTerm)
}

return nil
}

Expand Down Expand Up @@ -394,7 +398,9 @@ func theSauceFileShouldHavePropertyWithValue(ctx context.Context, index int, pro
return fmt.Errorf("sauce file does not have property %s: %w", propertyName, err)
}

if !regexp.MustCompile(expectedValue).MatchString(value.(string)) {
if matched, err := regexp.MatchString(expectedValue, value.(string)); err != nil {
return fmt.Errorf("regexp pattern matching caused an error: %w", err)
} else if !matched {
return fmt.Errorf("expected property %s to match regex '%s', got '%s'", propertyName, expectedValue, value)
}
return nil
Expand All @@ -417,10 +423,10 @@ func recipeIgnoresPattern(ctx context.Context, recipeName, pattern string) (cont
func expectGivenOutput(ctx context.Context, expected string) error {
cmdStdOut := ctx.Value(cmdStdOutCtxKey{}).(*bytes.Buffer)

if matched, err := regexp.MatchString(expected, cmdStdOut.String()); !matched {
return fmt.Errorf("command produced unexpected output: Expected: '%s', Actual: '%s'", expected, strings.TrimSpace(cmdStdOut.String()))
} else if err != nil {
if matched, err := regexp.MatchString(expected, cmdStdOut.String()); err != nil {
return fmt.Errorf("regexp pattern matching caused an error: %w", err)
} else if !matched {
return fmt.Errorf("command produced unexpected output: Expected: '%s', Actual: '%s'", expected, strings.TrimSpace(cmdStdOut.String()))
}

return nil
Expand All @@ -429,10 +435,10 @@ func expectGivenOutput(ctx context.Context, expected string) error {
func expectGivenError(ctx context.Context, expectedError string) error {
cmdStdErr := ctx.Value(cmdStdErrCtxKey{}).(*bytes.Buffer)

if matched, err := regexp.MatchString(expectedError, cmdStdErr.String()); !matched {
return fmt.Errorf("command produced unexpected error: Expected: '%s', Actual: '%s'", expectedError, strings.TrimSpace(cmdStdErr.String()))
} else if err != nil {
if matched, err := regexp.MatchString(expectedError, cmdStdErr.String()); err != nil {
return fmt.Errorf("regexp pattern matching caused an error: %w", err)
} else if !matched {
return fmt.Errorf("command produced unexpected error: Expected: '%s', Actual: '%s'", expectedError, strings.TrimSpace(cmdStdErr.String()))
}

return nil
Expand Down
6 changes: 6 additions & 0 deletions internal/cli/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ func runUpgrade(cmd *cobra.Command, opts upgradeOptions) error {
return err
}

if oldSauce.CheckFrom != "" {
newSauce.CheckFrom = oldSauce.CheckFrom
} else if strings.HasPrefix(opts.RecipeURL, "oci://") {
newSauce.CheckFrom = strings.TrimSuffix(opts.RecipeURL, fmt.Sprintf(":%s", re.Metadata.Version))
}

// read common ignore file if it exists
ignorePatterns := make([]string, 0)
if data, err := os.ReadFile(filepath.Join(opts.Dir, recipe.IgnoreFileName)); err == nil {
Expand Down
7 changes: 4 additions & 3 deletions test/upgrade-recipe.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: Upgrade sauce
And I change recipe "foo" template "README.md" to render "New version"
When I upgrade recipe "foo"
Then no errors were printed
And the project directory should contain file ".jalapeno/sauces.yml" with "version: v0.0.2"
And the project directory should contain file ".jalapeno/sauces.yml" with "version: v0\.0\.2"
And the project directory should contain file "README.md" with "New version"
And no conflicts were reported

Expand All @@ -21,7 +21,7 @@ Feature: Upgrade sauce
And I execute recipe "foo"
When I upgrade recipe "foo"
Then no errors were printed
And the project directory should contain file ".jalapeno/sauces.yml" with "version: v0.0.1"
And the project directory should contain file ".jalapeno/sauces.yml" with "version: v0\.0\.1"
And no conflicts were reported

Scenario: Upgrade sauce from remote recipe
Expand All @@ -35,7 +35,8 @@ Feature: Upgrade sauce
And the recipe "foo" is pushed to the local OCI repository "foo:v0.0.2"
When I upgrade recipe from the local OCI repository "foo:v0.0.2"
Then no errors were printed
And the project directory should contain file ".jalapeno/sauces.yml" with "version: v0.0.2"
And the project directory should contain file ".jalapeno/sauces.yml" with "version: v0\.0\.2"
And the project directory should contain file ".jalapeno/sauces.yml" with "from: oci://localhost:\d+/foo"
And the project directory should contain file "README.md" with "New version"
And no conflicts were reported

Expand Down

0 comments on commit b1eef93

Please sign in to comment.