-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ktr0731
committed
Jan 8, 2018
1 parent
d132aaa
commit 56dd921
Showing
8 changed files
with
103 additions
and
3 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
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,23 @@ | ||
package logger | ||
|
||
import ( | ||
"io" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
|
||
"github.com/ktr0731/evans/config" | ||
"github.com/ktr0731/evans/usecase/port" | ||
) | ||
|
||
func NewStdLogger(config *config.Config) port.Logger { | ||
return log.New(os.Stdout, config.Log.Prefix, log.LstdFlags) | ||
} | ||
|
||
func NewPromptLogger(ui io.Writer, config *config.Config) port.Logger { | ||
return log.New(ui, config.Log.Prefix, log.LstdFlags) | ||
} | ||
|
||
func NewNopLogger() port.Logger { | ||
return log.New(ioutil.Discard, "", log.LstdFlags) | ||
} |
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
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
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
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
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,6 @@ | ||
package port | ||
|
||
type Logger interface { | ||
Printf(format string, v ...interface{}) | ||
Println(v ...interface{}) | ||
} |
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,33 @@ | ||
package usecase | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ktr0731/evans/adapter/presenter" | ||
"github.com/ktr0731/evans/entity" | ||
"github.com/ktr0731/evans/usecase/port" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type serviceEnv struct { | ||
entity.Environment | ||
|
||
usedService string | ||
} | ||
|
||
func (e *serviceEnv) UseService(pkgName string) error { | ||
e.usedService = pkgName | ||
return nil | ||
} | ||
|
||
func TestService(t *testing.T) { | ||
expected := "example_service" | ||
params := &port.ServiceParams{expected} | ||
presenter := &presenter.StubPresenter{} | ||
env := &serviceEnv{} | ||
|
||
_, err := Service(params, presenter, env) | ||
require.NoError(t, err) | ||
assert.Equal(t, expected, env.usedService) | ||
} |