Skip to content

Commit

Permalink
Feature/dependency injection (#38)
Browse files Browse the repository at this point in the history
* fix markdown linting

* add dependency injection example

* update readme with di

* fix markdown code annotation

* fix readme

* one more readme fix
  • Loading branch information
iampeterbanjo authored and SimonWaldherr committed Oct 15, 2018
1 parent ee2994c commit bb5538a
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 77 deletions.
17 changes: 17 additions & 0 deletions beginner/di/dependency_injection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package di

import (
"fmt"
"io"
)

// PrintCheckList to show D.I.
//
// dependency Injection makes testing easier
// by creating functions that get all their
// dependencies are arguments
func PrintCheckList(writer io.Writer, list []string) {
for _, item := range list {
fmt.Fprintln(writer, item)
}
}
30 changes: 30 additions & 0 deletions beginner/di/dependency_injection_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package di

import (
"bytes"
"testing"

. "github.com/smartystreets/goconvey/convey"
)

func TestPrintCheckList(t *testing.T) {
Convey("Given a checklist", t, func() {
buffer := &bytes.Buffer{}
checklist := []string{
"[✓] Get milk",
"[✓] Learn Go",
"[✗] Book holidays",
}

PrintCheckList(buffer, checklist)

got := buffer.String()
want := `[✓] Get milk
[✓] Learn Go
[✗] Book holidays
`
Convey("expect list items to be printed", func() {
So(got, ShouldEqual, want)
})
})
}
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module github.com/iampeterbanjo/golang-examples

require (
github.com/jtolds/gls v4.2.1+incompatible // indirect
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
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 v0.0.0-20180222194500-ef6db91d284a h1:JSvGDIbmil4Ui/dDdFBExb7/cmkNjyX5F97oglmvCDo=
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
Loading

0 comments on commit bb5538a

Please sign in to comment.