Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dependency injection #38

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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