Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
majori committed Mar 7, 2023
1 parent e24aad1 commit 92e64d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
33 changes: 15 additions & 18 deletions cmd/cmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"math/big"
"io"
"math/big"
"os"
"path/filepath"
"strings"
Expand All @@ -20,9 +20,9 @@ import (

"github.com/cucumber/godog"
"github.com/futurice/jalapeno/pkg/recipe"
"github.com/ory/dockertest"
"github.com/go-yaml/yaml"
"github.com/gofrs/uuid"
"github.com/ory/dockertest"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -62,8 +62,8 @@ func TestFeatures(t *testing.T) {
s.Step(`^I execute recipe "([^"]*)"$`, iExecuteRecipe)
s.Step(`^the project directory should contain file "([^"]*)"$`, theProjectDirectoryShouldContainFile)
s.Step(`^the project directory should contain file "([^"]*)" with "([^"]*)"$`, theProjectDirectoryShouldContainFileWith)
s.Step(`^the rendered recipe file should have property "([^"]*)" that is a valid UUID$`, theRenderedRecipeFileShouldHavePropertyThatIsAValidUUID)
s.Step(`^the rendered recipe file should have property "([^"]*)" with value "([^"]*)"$`, theRenderedRecipeFileShouldHavePropertyWithValue)
s.Step(`^the rendered recipe file contains a recipe in index (\d) which should have property "([^"]*)" that is a valid UUID$`, theRenderedRecipeFileShouldHavePropertyThatIsAValidUUID)
s.Step(`^the rendered recipe file contains a recipe in index (\d) which should have property "([^"]*)" with value "([^"]*)"$`, theRenderedRecipeFileShouldHavePropertyWithValue)
s.Step(`^execution of the recipe has succeeded$`, executionOfTheRecipeHasSucceeded)
s.Step(`^execution of the recipe has failed with error "([^"]*)"$`, executionOfTheRecipeHasFailedWithError)
s.Step(`^I change recipe "([^"]*)" to version "([^"]*)"$`, iChangeRecipeToVersion)
Expand Down Expand Up @@ -314,37 +314,34 @@ func theProjectDirectoryShouldContainFileWith(ctx context.Context, filename, sea
return nil
}

func theRenderedRecipeFileShouldHavePropertyThatIsAValidUUID(ctx context.Context, propertyName string) error {
func theRenderedRecipeFileShouldHavePropertyThatIsAValidUUID(ctx context.Context, index int, propertyName string) error {
recipes, err := readRenderedRecipeFile(ctx)
if err != nil {
return err
}
var exists bool
for i := 0; i < len(recipes); i++ {
var value string
value, exists = (recipes[i])[propertyName].(string)
if exists {
if _, err := uuid.FromString(value); err != nil {
return fmt.Errorf("found UUID but it does not parse: %w", err)
}
break

value, exists := (recipes[index])[propertyName].(string)
if exists {
if _, err := uuid.FromString(value); err != nil {
return fmt.Errorf("found UUID but it does not parse: %w", err)
}
}
if !exists {
} else {
return fmt.Errorf("recipe file does not have property %s", propertyName)
}

if err != nil {
return err
}

return nil
}

func theRenderedRecipeFileShouldHavePropertyWithValue(ctx context.Context, propertyName, expectedValue string) error {
func theRenderedRecipeFileShouldHavePropertyWithValue(ctx context.Context, index int, propertyName, expectedValue string) error {
recipes, err := readRenderedRecipeFile(ctx)
if err != nil {
return err
}
value, exists := (recipes[0])[propertyName].(string)
value, exists := (recipes[index])[propertyName].(string)
if !exists {
return fmt.Errorf("recipe file does not have property %s", propertyName)
}
Expand Down
8 changes: 4 additions & 4 deletions features/execute-recipes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Feature: Execute recipes
When I execute recipe "foo"
Then execution of the recipe has succeeded
And the project directory should contain file "README.md"
And the rendered recipe file should have property "name" with value "foo"
And the rendered recipe file should have property "anchor" that is a valid UUID
And the rendered recipe file contains a recipe in index 0 which should have property "name" with value "foo"
And the rendered recipe file contains a recipe in index 0 which should have property "anchor" that is a valid UUID

Scenario: Execute multiple recipes
Given a project directory
Expand All @@ -23,8 +23,8 @@ Feature: Execute recipes
And no errors were printed
And the project directory should contain file "README.md"
And the project directory should contain file "Taskfile.yml"
And the rendered recipe file should have property "name" with value "foo"
And the rendered recipe file should have property "name" with value "bar"
And the rendered recipe file contains a recipe in index 0 which should have property "name" with value "foo"
And the rendered recipe file contains a recipe in index 1 which should have property "name" with value "bar"

Scenario: New recipe conflicts with the previous recipe
Given a project directory
Expand Down

0 comments on commit 92e64d6

Please sign in to comment.