diff --git a/cmd/cmds_test.go b/cmd/cmds_test.go index 777e5b81..b2993cb8 100644 --- a/cmd/cmds_test.go +++ b/cmd/cmds_test.go @@ -10,8 +10,8 @@ import ( "crypto/x509/pkix" "encoding/pem" "fmt" - "math/big" "io" + "math/big" "os" "path/filepath" "strings" @@ -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" ) @@ -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) @@ -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) } diff --git a/features/execute-recipes.feature b/features/execute-recipes.feature index 443d0700..b1737ca2 100644 --- a/features/execute-recipes.feature +++ b/features/execute-recipes.feature @@ -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 @@ -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