Skip to content

Commit

Permalink
adding meta feature
Browse files Browse the repository at this point in the history
  • Loading branch information
asiermarques committed Nov 15, 2020
1 parent b492d3c commit 48ce636
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ components: ""
technologies: ""
---
# My new a
# My new ADR
```

**Supersede an ADR with another new ADR**
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,7 +23,7 @@ Feature: create an ADR File

When the user specify the <title> 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
Expand All @@ -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 |
61 changes: 61 additions & 0 deletions docs/features/3. create_an_adr_file_with_meta.feature
Original file line number Diff line number Diff line change
@@ -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?
"""


51 changes: 49 additions & 2 deletions docs/features/features_definition_steps/create_file_steps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion domain/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
4 changes: 2 additions & 2 deletions domain/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

func TestCreateMetaContent(t *testing.T) {
expectedString := `---
param1: ""
param2: ""
param1: ""
param2: ""
---
`

Expand Down
2 changes: 1 addition & 1 deletion e2e_tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

cd ./docs/features/features_definition_steps
cd ./docs/features/features_definition_steps || exit
godog ../
cd ../../..
12 changes: 6 additions & 6 deletions infrastructure/cmd/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 48ce636

Please sign in to comment.