From 48ce63671cc68c1a63065104e1c6f3be7cc14b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asier=20Marqu=C3=A9s?= Date: Sun, 15 Nov 2020 20:57:43 +0100 Subject: [PATCH] adding meta feature --- README.md | 2 +- ...le.feature => 2. create_adr_files.feature} | 19 +++--- .../3. create_an_adr_file_with_meta.feature | 61 +++++++++++++++++++ .../create_file_steps_test.go | 51 +++++++++++++++- domain/template.go | 2 +- domain/template_test.go | 4 +- e2e_tests.sh | 2 +- infrastructure/cmd/create_test.go | 12 ++-- 8 files changed, 130 insertions(+), 23 deletions(-) rename docs/features/{2. create_an_adr_file.feature => 2. create_adr_files.feature} (75%) create mode 100644 docs/features/3. create_an_adr_file_with_meta.feature diff --git a/README.md b/README.md index 0e7159f..b684d4a 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ components: "" technologies: "" --- -# My new a +# My new ADR ``` **Supersede an ADR with another new ADR** diff --git a/docs/features/2. create_an_adr_file.feature b/docs/features/2. create_adr_files.feature similarity index 75% rename from docs/features/2. create_an_adr_file.feature rename to docs/features/2. create_adr_files.feature index dcfe98e..f3cd591 100644 --- a/docs/features/2. create_an_adr_file.feature +++ b/docs/features/2. create_adr_files.feature @@ -1,4 +1,4 @@ -Feature: create an ADR File +Feature: create ADR files In order to have registered context about architecture decisions As an ADR writer @@ -23,7 +23,7 @@ Feature: create an ADR File When the user specify the title And the create command is executed - Then a <filename> is created + Then the <filename> ADR file is created And the adr has an id <id> And the adr has a <status> status And the adr file content has the <title_in_file> title @@ -41,13 +41,12 @@ Feature: create an ADR File Given there is not any config file When the user specify the <title> title - And the create command is executed - Then a <filename> is created - And the adr has an id <id> - And the adr has a <status> status - And the adr file content has the <title_in_file> title + And the create command is executed + Then the <filename> ADR file is created + And the adr has a <status> status + And the adr file content has the <title_in_file> title Examples: - | title | filename | id | status | title_in_file | - | New adr | 0001-new-adr.md | 1 | proposed | 1. New adr | - | New adr | 0002-new-adr.md | 2 | proposed | 2. New adr | + | title | filename | status | title_in_file | + | New adr | 0001-new-adr.md | proposed | 1. New adr | + | New adr | 0002-new-adr.md | proposed | 2. New adr | diff --git a/docs/features/3. create_an_adr_file_with_meta.feature b/docs/features/3. create_an_adr_file_with_meta.feature new file mode 100644 index 0000000..e91c1f7 --- /dev/null +++ b/docs/features/3. create_an_adr_file_with_meta.feature @@ -0,0 +1,61 @@ +Feature: create an ADR File with meta + + In order to have better integration with other tools + As an ADR writer + I want to add meta information to the ADR files + + + Background: + + ADRGen allows creating meta parameters in ADR Files with the command + + adrgen create "My ADR file" -m "param1, param2" + + This command creates the ADR file with a Markdown meta section on the top of the file and adds the + specified params to it, for example: + + --- + param1: "" + param2: "" + --- + + # My ADR file + + + Scenario: create an ADR file with meta params + + Given there is not any config file + And there is no ADR files + When the user specify the My architecture decision title + And the meta parameters param1, param2 are specified + And the create command is executed + Then the 0001-my-architecture-decision.md ADR file is created + And has the following content: + """ + --- + param1: "" + param2: "" + --- + + # 1. My architecture decision + + Date: {date} + + ## Status + + Status: proposed + + ## Context + + What is the issue that we're seeing that is motivating this decision or change? + + ## Decision + + What is the change that we're proposing and/or doing? + + ## Consequences + + What becomes easier or more difficult to do because of this change? + """ + + diff --git a/docs/features/features_definition_steps/create_file_steps_test.go b/docs/features/features_definition_steps/create_file_steps_test.go index 2d95066..d688930 100644 --- a/docs/features/features_definition_steps/create_file_steps_test.go +++ b/docs/features/features_definition_steps/create_file_steps_test.go @@ -7,12 +7,14 @@ import ( "regexp" "strconv" "strings" + "time" "github.com/cucumber/godog" "github.com/cucumber/messages-go/v10" ) var userTitle string +var userMetaParams string var createdFilename string var createdFilenameWithPath string @@ -88,10 +90,15 @@ func theAdrHasAnId(adrId int) error { } func theCreateCommandIsExecuted() error { + metaCommandFlag := "" + if userMetaParams != "" { + metaCommandFlag = fmt.Sprintf("-m \"%s\"", userMetaParams) + } + output, err := exec.Command( "/bin/sh", "-c", - fmt.Sprintf("cd ../e2e/tests; ../bin/adrgen create \"%s\"", userTitle), + fmt.Sprintf("cd ../e2e/tests; ../bin/adrgen create \"%s\" %s", userTitle, metaCommandFlag), ).CombinedOutput() if err != nil { return fmt.Errorf("error executing the create command: %s %s", err, output) @@ -187,16 +194,56 @@ func thereIsNotAnyConfigFile() error { return nil } +func hasTheFollowingContent(content *messages.PickleStepArgument_PickleDocString) error { + output, err := exec.Command( + "/bin/sh", + "-c", + fmt.Sprintf("cd ../e2e/tests; cat \"%s\"", createdFilenameWithPath), + ).CombinedOutput() + if err != nil { + return fmt.Errorf("%s file not found: %s %s", createdFilenameWithPath, err, output) + } + + currentTime := time.Now() + date := currentTime.Format("02-01-2006") + + expected := strings.TrimSpace(content.Content) + expected = strings.Replace(expected, "{date}", date, 1) + + returned := strings.TrimSpace(string(output)) + + if returned != expected { + return fmt.Errorf("expected:\n%s\n\nreturned:\n%s", expected, returned) + } + + return nil +} + +func thereIsNoADRFiles() error { + exec.Command("/bin/sh", "-c", "rm ../e2e/tests/*.md" ).CombinedOutput() + return nil +} + +func theMetaParametersAreSpecified(params string) error { + userMetaParams = params + return nil +} + + + func CreateFeatureContext(s *godog.ScenarioContext) { - s.Step(`^a (.+) is created$`, aNewFileIsCreated) + s.Step(`^the (.+) ADR file is created$`, aNewFileIsCreated) s.Step(`^the adr file content has the (.+) title$`, theAdrFileContentHasTheTitle) + s.Step(`^the meta parameters (.+) are specified$`, theMetaParametersAreSpecified) s.Step(`^the adr has a (.+) status$`, theAdrHasTheStatus) s.Step(`^the adr has an id (\d+)$`, theAdrHasAnId) s.Step(`^the create command is executed$`, theCreateCommandIsExecuted) s.Step(`^the user specify the (.+) title$`, theUserSpecifyTheTitle) + s.Step(`^has the following content:$`, hasTheFollowingContent) s.Step( `^there is a config file created with this configuration$`, thereIsAConfigFileCreatedWithThisConfiguration, ) s.Step(`^there is not any config file$`, thereIsNotAnyConfigFile) + s.Step(`^there is no ADR files$`, thereIsNoADRFiles) } diff --git a/domain/template.go b/domain/template.go index e0dd1b4..655692d 100644 --- a/domain/template.go +++ b/domain/template.go @@ -93,7 +93,7 @@ func (s privateTemplateService) RenderDefaultTemplateContent(data TemplateData) func (s privateTemplateService) RenderMetaContent(parameters []string) string { if len(parameters) > 0 { - valueSeparator := ": \"\" \n" + valueSeparator := ": \"\"\n" return fmt.Sprintf("---\n%s---\n", strings.Join(parameters, valueSeparator)+valueSeparator) } return "" diff --git a/domain/template_test.go b/domain/template_test.go index 8c4c42d..afe5a2f 100644 --- a/domain/template_test.go +++ b/domain/template_test.go @@ -7,8 +7,8 @@ import ( func TestCreateMetaContent(t *testing.T) { expectedString := `--- -param1: "" -param2: "" +param1: "" +param2: "" --- ` diff --git a/e2e_tests.sh b/e2e_tests.sh index 0a82c6e..b4d7efc 100755 --- a/e2e_tests.sh +++ b/e2e_tests.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -cd ./docs/features/features_definition_steps +cd ./docs/features/features_definition_steps || exit godog ../ cd ../../.. \ No newline at end of file diff --git a/infrastructure/cmd/create_test.go b/infrastructure/cmd/create_test.go index ed94b86..b9940fd 100644 --- a/infrastructure/cmd/create_test.go +++ b/infrastructure/cmd/create_test.go @@ -61,9 +61,9 @@ func Test_ExecuteCreateCommand(t *testing.T) { content, _ := getFileContent(fileWithMeta) expectedContent := `--- -param1: "" -param2: "" -param3: "" +param1: "" +param2: "" +param3: "" --- ` + templateService.RenderDefaultTemplateContent(domain.TemplateData{Date: date, Title: "4. ADR title 3", Status: "proposed"}) if content != expectedContent { @@ -104,9 +104,9 @@ func Test_ExecuteCreateCommandWithConfig(t *testing.T) { content, _ := getFileContent(fileWithMeta) expectedContent := `--- -param1: "" -param2: "" -param3: "" +param1: "" +param2: "" +param3: "" --- ` + templateService.RenderDefaultTemplateContent(domain.TemplateData{Date: date, Title: "4. ADR title 3", Status: "proposed"}) if content != expectedContent {