-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: covers the themes list command
- Loading branch information
Showing
4 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ doc.html | |
doc.md | ||
collection.json | ||
.cover | ||
*.coverprofile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package commands_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"testing" | ||
) | ||
|
||
func TestCommands(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Commands Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package commands_test | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
|
||
. "github.com/aubm/postmanerator/commands" | ||
"github.com/aubm/postmanerator/configuration" | ||
. "github.com/aubm/postmanerator/themes/tests" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("ListThemes", func() { | ||
|
||
var ( | ||
mockStdOut *bytes.Buffer | ||
mockThemesManager *MockThemesManager | ||
listThemesCommand *ListThemes | ||
) | ||
|
||
BeforeEach(func() { | ||
mockStdOut = new(bytes.Buffer) | ||
mockThemesManager = &MockThemesManager{} | ||
mockConfig := &configuration.Configuration{Out: mockStdOut} | ||
listThemesCommand = &ListThemes{ | ||
Config: mockConfig, | ||
Themes: mockThemesManager, | ||
} | ||
}) | ||
|
||
Describe("Is", func() { | ||
|
||
It("should be OK", func() { | ||
Expect(listThemesCommand.Is("cmd_themes_list")).To(BeTrue()) | ||
}) | ||
|
||
It("should be KO", func() { | ||
Expect(listThemesCommand.Is("cmd_default")).To(BeFalse()) | ||
}) | ||
|
||
}) | ||
|
||
Describe("Do", func() { | ||
|
||
var returnedError error | ||
|
||
JustBeforeEach(func() { | ||
returnedError = listThemesCommand.Do() | ||
}) | ||
|
||
Context("when the manager responds with a list of themes", func() { | ||
|
||
BeforeEach(func() { | ||
mockThemesManager.On("List").Return([]string{"default", "markdown"}, nil) | ||
}) | ||
|
||
It("should not return an error", func() { | ||
Expect(returnedError).To(BeNil()) | ||
}) | ||
|
||
It("should print the themes in the output", func() { | ||
Expect(mockStdOut.String()).To(Equal("default\nmarkdown\n")) | ||
}) | ||
|
||
}) | ||
|
||
Context("when the manager responds with an error", func() { | ||
|
||
var managerError = errors.New("something bad happened") | ||
|
||
BeforeEach(func() { | ||
mockThemesManager.On("List").Return([]string{}, managerError) | ||
}) | ||
|
||
It("should return an error", func() { | ||
Expect(returnedError).NotTo(BeNil()) | ||
Expect(returnedError).To(Equal(managerError)) | ||
}) | ||
|
||
It("should not write anything in the output", func() { | ||
Expect(mockStdOut.String()).To(BeZero()) | ||
}) | ||
|
||
}) | ||
|
||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package tests | ||
|
||
import "github.com/stretchr/testify/mock" | ||
|
||
type MockThemesManager struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *MockThemesManager) List() ([]string, error) { | ||
args := m.Called() | ||
return args.Get(0).([]string), args.Error(1) | ||
} |