-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from mocktools/develop
Golang smtpmock v2.1.0
- Loading branch information
Showing
13 changed files
with
173 additions
and
14 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
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
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,29 @@ | ||
package smtpmock | ||
|
||
// NOOP command handler | ||
type handlerNoop struct { | ||
*handler | ||
} | ||
|
||
// NOOP command handler builder. Returns pointer to new handlerNoop structure | ||
func newHandlerNoop(session sessionInterface, message *Message, configuration *configuration) *handlerNoop { | ||
return &handlerNoop{&handler{session: session, message: message, configuration: configuration}} | ||
} | ||
|
||
// NOOP handler methods | ||
|
||
// Main NOOP handler runner | ||
func (handler *handlerNoop) run(request string) { | ||
if handler.isInvalidRequest(request) { | ||
return | ||
} | ||
|
||
handler.message.noop = true | ||
configuration := handler.configuration | ||
handler.session.writeResponse(configuration.msgNoopReceived, configuration.responseDelayNoop) | ||
} | ||
|
||
// Invalid NOOP command predicate. Returns true when request is invalid, otherwise returns false | ||
func (handler *handlerNoop) isInvalidRequest(request string) bool { | ||
return !matchRegex(request, validNoopCmdRegexPattern) | ||
} |
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,54 @@ | ||
package smtpmock | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewHandlerNoop(t *testing.T) { | ||
t.Run("returns new handleNoop", func(t *testing.T) { | ||
session, message, configuration := new(session), new(Message), new(configuration) | ||
handler := newHandlerNoop(session, message, configuration) | ||
|
||
assert.Same(t, session, handler.session) | ||
assert.Same(t, message, handler.message) | ||
assert.Same(t, configuration, handler.configuration) | ||
}) | ||
} | ||
|
||
func TestHandlerNoopRun(t *testing.T) { | ||
t.Run("when successful NOOP request", func(t *testing.T) { | ||
request, session, message, configuration := "NOOP", new(sessionMock), new(Message), createConfiguration() | ||
receivedMessage := configuration.msgNoopReceived | ||
handler := newHandlerNoop(session, message, configuration) | ||
session.On("writeResponse", receivedMessage, configuration.responseDelayQuit).Once().Return(nil) | ||
handler.run(request) | ||
|
||
assert.True(t, message.noop) | ||
}) | ||
|
||
t.Run("when failure NOOP request", func(t *testing.T) { | ||
request, session, message, configuration := "NOOP ", new(sessionMock), new(Message), createConfiguration() | ||
handler := newHandlerNoop(session, message, configuration) | ||
handler.run(request) | ||
|
||
assert.False(t, message.noop) | ||
}) | ||
} | ||
|
||
func TestHandlerNoopIsInvalidRequest(t *testing.T) { | ||
handler := newHandlerNoop(new(session), new(Message), new(configuration)) | ||
|
||
t.Run("when request includes invalid NOOP command", func(t *testing.T) { | ||
request := "NOOP " | ||
|
||
assert.True(t, handler.isInvalidRequest(request)) | ||
}) | ||
|
||
t.Run("when request includes valid NOOP command", func(t *testing.T) { | ||
request := "NOOP" | ||
|
||
assert.False(t, handler.isInvalidRequest(request)) | ||
}) | ||
} |
Oops, something went wrong.