Skip to content

Commit

Permalink
wip adr create e2e testing
Browse files Browse the repository at this point in the history
  • Loading branch information
asiermarques committed Nov 15, 2020
1 parent c5468b7 commit 793b99c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 24 deletions.
10 changes: 5 additions & 5 deletions docs/features/create_an_adr_file.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Feature: create an ADR File

Given there is a config file created with this configuration
| default_status | directory | template_file | id_digit_number |
| proposed | adrs | adrs/template.md | 2 |
| custom | ./adrs | ./adrs/template.md | 2 |

When the user specify the <title> title
And the command is executed
Expand All @@ -30,10 +30,10 @@ Feature: create an ADR File

Examples:
| title | filename | id | status | title_in_file |
| New adr | 01-new-adr.md | 1 | proposed | 1. New adr |
| New adr | 02-new-adr.md | 2 | proposed | 2. New adr |
| New adr | 03-new-adr.md | 3 | proposed | 3. New adr |
| New adr | 04-new-adr.md | 4 | proposed | 4. New adr |
| New adr | 01-new-adr.md | 1 | custom | 1. New adr |
| New adr | 02-new-adr.md | 2 | custom | 2. New adr |
| New adr | 03-new-adr.md | 3 | custom | 3. New adr |
| New adr | 04-new-adr.md | 4 | custom | 4. New adr |


Scenario Outline: create adr files without configuration
Expand Down
76 changes: 59 additions & 17 deletions docs/features/features_definition_steps/create_file_steps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package features_definition_steps
import (
"fmt"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
Expand All @@ -13,24 +14,26 @@ import (

var userTitle string
var createdFilename string
var createdFilenameWithPath string
var directory string

func aNewFileIsCreated(filename string) error {
output, err := exec.Command(
"/bin/sh",
"-c",
fmt.Sprintf("cd ../e2e/tests; ls \"%s\"", filename),
fmt.Sprintf("cd ../e2e/tests; ls \"%s\"", filepath.Join(directory, filename)),
).CombinedOutput()
if err != nil {
return fmt.Errorf("file was not created: %s %s", err, output)
}

createdFilename = filename
createdFilenameWithPath = filepath.Join(directory, filename)
return nil
}

func theAdrFileContentHasTheTitle(titleInContent string) error {
titleInContent = "# " + titleInContent
searchCommand := fmt.Sprintf(`grep -E "^# (.+)$" %s`, createdFilename)
searchCommand := fmt.Sprintf(`grep -E "^# (.+)$" %s`, createdFilenameWithPath)

output, err := exec.Command(
"/bin/sh",
Expand All @@ -50,7 +53,7 @@ func theAdrFileContentHasTheTitle(titleInContent string) error {
}

func theAdrHasTheStatus(status string) error {
searchCommand := fmt.Sprintf(`grep -E "^Status: (.+)$" %s`, createdFilename)
searchCommand := fmt.Sprintf(`grep -E "^Status: (.+)$" %s`, createdFilenameWithPath)

output, err := exec.Command(
"/bin/sh",
Expand Down Expand Up @@ -94,7 +97,6 @@ func theCommandIsExecuted() error {
if err != nil {
return fmt.Errorf("error executing the create command: %s %s", err, output)
}
fmt.Println(string(output))

return nil
}
Expand All @@ -108,23 +110,26 @@ func thereIsAConfigFileCreatedWithThisConfiguration(
table *messages.PickleStepArgument_PickleTable,
) error {
row := table.GetRows()[1]
content := fmt.Sprintf(`default_meta: []
content := fmt.Sprintf(`
default_meta: []
default_status: %s
directory: %s
id_digit_number: %s
supported_statuses:
- proposed
- accepted
- rejected
- superseded
- amended
- deprecated
- proposed
- accepted
- rejected
- superseded
- amended
- deprecated
- custom
template_file: %s
id_digit_number: %s
`,
row.GetCells()[0].Value,
row.GetCells()[1].Value,
row.GetCells()[2].Value,
row.GetCells()[3].Value,
row.GetCells()[0].Value,
row.GetCells()[1].Value,
row.GetCells()[3].Value,
row.GetCells()[2].Value,
)

configFile := "adrgen.config.yml"
Expand All @@ -139,10 +144,47 @@ id_digit_number: %s
return fmt.Errorf("error generating the config file: %s %s", err, output)
}

templateContent := `# {title}
Date: {date}
## Status
Status: {status}
## 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?
`


output, err = exec.Command("/bin/sh", "-c", fmt.Sprintf(
"cd ../e2e/tests; mkdir %s; touch %s;echo \"%s\" > %s",
row.GetCells()[1].Value,
row.GetCells()[2].Value,
templateContent,
row.GetCells()[2].Value,
)).CombinedOutput()
if err != nil {
return fmt.Errorf("error generating the config file: %s %s", err, output)
}

directory = row.GetCells()[1].Value

return nil
}

func thereIsNotAnyConfigFile() error {
exec.Command("/bin/sh", "-c", "rm ../e2e/tests/adrgen.config.yml" ).CombinedOutput()
directory = ""
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/asiermarques/adrgen v0.1.0-beta
github.com/cucumber/godog v0.10.0
github.com/cucumber/messages-go/v10 v10.0.3
github.com/gosimple/slug v1.9.0 // indirect
github.com/gosimple/slug v1.9.0
github.com/spf13/cobra v1.1.1
github.com/spf13/viper v1.7.1 // indirect
github.com/spf13/viper v1.7.1
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqCl
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
Expand Down Expand Up @@ -80,6 +81,7 @@ github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OI
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gosimple/slug v1.9.0 h1:r5vDcYrFz9BmfIAMC829un9hq7hKM4cHUrsv36LbEqs=
Expand All @@ -102,6 +104,7 @@ github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
Expand All @@ -115,10 +118,12 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
Expand All @@ -130,6 +135,7 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
Expand All @@ -149,6 +155,7 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
Expand Down Expand Up @@ -177,7 +184,9 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
Expand Down Expand Up @@ -322,6 +331,7 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
Expand Down

0 comments on commit 793b99c

Please sign in to comment.