Skip to content

Commit a4dcf37

Browse files
authored
Technical/Refactor namespaces, codebase (#42)
* Refactored functions/structures/constants scopes * Updated tests * Updated linters config * Configured Codecov reporter * Updated CircleCI config * Updated changelog
1 parent 7f21157 commit a4dcf37

28 files changed

+360
-327
lines changed

.circleci/config.yml

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
version: 2.1
22

33
jobs:
4-
lint:
4+
linters:
55
docker:
6-
- image: golangci/golangci-lint:v1.33-alpine
6+
- image: golangci/golangci-lint:v1.43-alpine
77
steps:
88
- checkout
99
- run: golangci-lint run
@@ -20,16 +20,15 @@ jobs:
2020

2121
- run:
2222
name: Running tests
23-
command: gotestsum --format standard-verbose -- -coverprofile=c.out ./...
23+
command: gotestsum --format standard-verbose -- -coverprofile=coverage_report ./...
2424

2525
- run:
2626
name: Creating coverage reports
2727
command: |
2828
mkdir -p /tmp/artifacts
29-
go tool cover -html=c.out -o coverage.html
30-
mv coverage.html /tmp/artifacts
31-
go tool cover -func=c.out -o coverage.txt
32-
mv coverage.txt /tmp/artifacts
29+
go tool cover -html=coverage_report -o coverage.html
30+
go tool cover -func=coverage_report -o coverage.txt
31+
mv coverage.html coverage.txt /tmp/artifacts
3332
3433
- store_artifacts:
3534
name: Saving coverage artifacts
@@ -40,8 +39,13 @@ jobs:
4039
command: |
4140
tail -1 /tmp/artifacts/coverage.txt | awk '{ exit (($NF == "100.0%") ? 0 : 1) }'
4241
42+
- deploy:
43+
name: Uploading Codecov test coverage report
44+
command: |
45+
bash <(curl -s https://codecov.io/bash) -f coverage_report
46+
4347
workflows:
4448
build:
4549
jobs:
46-
- lint
50+
- linters
4751
- test

.golangci.yml

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1+
linters:
2+
enable:
3+
- gocyclo
4+
- misspell
5+
- revive
6+
17
linters-settings:
8+
gocyclo:
9+
min-complexity: 30
10+
211
govet:
312
disable:
413
- copylocks

.tool-versions

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
golang 1.15.6

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## [0.1.2] - 2021-12-03
6+
7+
### Updated
8+
9+
- Updated functions/structures/consts scopes
10+
- Updated linters config
11+
- Updated CircleCI config
12+
13+
### Fixed
14+
15+
- Linters issues
16+
17+
## [0.1.1] - 2021-11-30
18+
19+
### Fixed
20+
21+
- Fixed typos, linter warnings
22+
523
## [0.1.0] - 2021-11-30
624

725
### Added

README.md

+25-24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![CircleCI](https://circleci.com/gh/mocktools/go-smtp-mock/tree/master.svg?style=svg)](https://circleci.com/gh/mocktools/go-smtp-mock/tree/master)
44
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/mocktools/go-smtp-mock)](https://github.com/mocktools/go-smtp-mock/releases)
5+
[![Codecov](https://codecov.io/gh/mocktools/go-smtp-mock/branch/master/graph/badge.svg)](https://codecov.io/gh/mocktools/go-smtp-mock)
56
[![Go Report Card](https://goreportcard.com/badge/github.com/mocktools/go-smtp-mock)](https://goreportcard.com/report/github.com/mocktools/go-smtp-mock)
67
[![PkgGoDev](https://pkg.go.dev/badge/github.com/mocktools/go-smtp-mock)](https://pkg.go.dev/github.com/mocktools/go-smtp-mock)
78
[![GitHub](https://img.shields.io/github/license/mocktools/go-smtp-mock)](LICENSE.txt)
@@ -16,7 +17,7 @@ Golang SMTP mock. Mimic SMTP server behaviour for your test environment and even
1617
- [Installation](#installation)
1718
- [Usage](#usage)
1819
- [Configuring](#configuring)
19-
- [Starting/stopping server](#starting-stopping-server)
20+
- [Example of usage](#example-of-usage)
2021
- [Contributing](#contributing)
2122
- [License](#license)
2223
- [Code of Conduct](#code-of-conduct)
@@ -115,79 +116,79 @@ smtpmock.ConfigurationAttr{
115116

116117
// Customazing SMTP command handler messages context
117118
// ---------------------------------------------------------------------
118-
// Custom server greeting message. Base on DefaultGreetingMsg by default
119+
// Custom server greeting message. Base on defaultGreetingMsg by default
119120
msgGreeting: "msgGreeting",
120121

121-
// Custom invalid command message. Based on DefaultInvalidCmdMsg by default
122+
// Custom invalid command message. Based on defaultInvalidCmdMsg by default
122123
msgInvalidCmd: "msgInvalidCmd",
123124

124125
// Custom invalid command HELO sequence message.
125-
// Based on DefaultInvalidCmdHeloSequenceMsg by default
126+
// Based on defaultInvalidCmdHeloSequenceMsg by default
126127
msgInvalidCmdHeloSequence: "msgInvalidCmdHeloSequence",
127128

128129
// Custom invalid command HELO argument message.
129-
// Based on DefaultInvalidCmdHeloArgMsg by default
130+
// Based on defaultInvalidCmdHeloArgMsg by default
130131
msgInvalidCmdHeloArg: "msgInvalidCmdHeloArg",
131132

132-
// Custom HELO blacklisted domain message. Based on DefaultQuitMsg by default
133+
// Custom HELO blacklisted domain message. Based on defaultQuitMsg by default
133134
msgHeloBlacklistedDomain: "msgHeloBlacklistedDomain",
134135

135-
// Custom HELO received message. Based on DefaultReceivedMsg by default
136+
// Custom HELO received message. Based on defaultReceivedMsg by default
136137
msgHeloReceived: "msgHeloReceived",
137138

138139
// Custom invalid command MAIL FROM sequence message.
139-
// Based on DefaultInvalidCmdMailfromSequenceMsg by default
140+
// Based on defaultInvalidCmdMailfromSequenceMsg by default
140141
msgInvalidCmdMailfromSequence: "msgInvalidCmdMailfromSequence",
141142

142143
// Custom invalid command MAIL FROM argument message.
143-
// Based on DefaultInvalidCmdMailfromArgMsg by default
144+
// Based on defaultInvalidCmdMailfromArgMsg by default
144145
msgInvalidCmdMailfromArg: "msgInvalidCmdMailfromArg",
145146

146-
// Custom MAIL FROM blacklisted domain message. Based on DefaultQuitMsg by default
147+
// Custom MAIL FROM blacklisted domain message. Based on defaultQuitMsg by default
147148
msgMailfromBlacklistedEmail: "msgMailfromBlacklistedEmail",
148149

149-
// Custom MAIL FROM received message. Based on DefaultReceivedMsg by default
150+
// Custom MAIL FROM received message. Based on defaultReceivedMsg by default
150151
msgMailfromReceived: "msgMailfromReceived",
151152

152153
// Custom invalid command RCPT TO sequence message.
153-
// Based on DefaultInvalidCmdRcpttoSequenceMsg by default
154+
// Based on defaultInvalidCmdRcpttoSequenceMsg by default
154155
msgInvalidCmdRcpttoSequence: "msgInvalidCmdRcpttoSequence",
155156

156157
// Custom invalid command RCPT TO argument message.
157-
// Based on DefaultInvalidCmdRcpttoArgMsg by default
158+
// Based on defaultInvalidCmdRcpttoArgMsg by default
158159
msgInvalidCmdRcpttoArg: "msgInvalidCmdRcpttoArg",
159160

160161
// Custom RCPT TO not registered email message.
161-
// Based on DefaultNotRegistredRcpttoEmailMsg by default
162+
// Based on defaultNotRegistredRcpttoEmailMsg by default
162163
msgRcpttoNotRegisteredEmail: "msgRcpttoNotRegisteredEmail",
163164

164-
// Custom RCPT TO blacklisted email message. Based on DefaultQuitMsg by default
165+
// Custom RCPT TO blacklisted email message. Based on defaultQuitMsg by default
165166
msgRcpttoBlacklistedEmail: "msgRcpttoBlacklistedEmail",
166167

167-
// Custom RCPT TO received message. Based on DefaultReceivedMsg by default
168+
// Custom RCPT TO received message. Based on defaultReceivedMsg by default
168169
msgRcpttoReceived: "msgRcpttoReceived",
169170

170171
// Custom invalid command DATA sequence message.
171-
// Based on DefaultInvalidCmdDataSequenceMsg by default
172+
// Based on defaultInvalidCmdDataSequenceMsg by default
172173
msgInvalidCmdDataSequence: "msgInvalidCmdDataSequence",
173174

174-
// Custom DATA received message. Based on DefaultReadyForReceiveMsg by default
175+
// Custom DATA received message. Based on defaultReadyForReceiveMsg by default
175176
msgDataReceived: "msgDataReceived",
176177

177-
// Custom size is too big message. Based on DefaultMsgSizeIsTooBigMsg by default
178+
// Custom size is too big message. Based on defaultMsgSizeIsTooBigMsg by default
178179
msgMsgSizeIsTooBig: "msgMsgSizeIsTooBig",
179180

180-
// Custom received message body message. Based on DefaultReceivedMsg by default
181+
// Custom received message body message. Based on defaultReceivedMsg by default
181182
msgMsgReceived: "msgMsgReceived",
182183

183-
// Custom quit command message. Based on DefaultQuitMsg by default
184+
// Custom quit command message. Based on defaultQuitMsg by default
184185
msgQuitCmd: "msgQuitCmd",
185186
}
186187
```
187188

188-
### Starting-stopping server
189+
### Example of usage
189190

190-
You have to create your SMTP mock server using `smtpmock.New()` and `smtpmock.ConfigurationAttr` to iterate with it first. Example of usage:
191+
You have to create your SMTP mock server using `smtpmock.New()` and `smtpmock.ConfigurationAttr{}` to iterate with it first.
191192

192193
```go
193194
package main
@@ -203,7 +204,7 @@ import (
203204
func main() {
204205
hostAddress, portNumber := "127.0.0.1", 2525
205206

206-
// You can pass empty ConfigurationAttr{}. It means that smtpmock will use default settings
207+
// You can pass empty smtpmock.ConfigurationAttr{}. It means that smtpmock will use default settings
207208
server := smtpmock.New(smtpmock.ConfigurationAttr{
208209
hostAddress: hostAddress,
209210
portNumber: portNumber,

configuration.go

+46-46
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type configuration struct {
4040
}
4141

4242
// New configuration builder. Returns pointer to valid new configuration structure
43-
func NewConfiguration(config ConfigurationAttr) *configuration {
43+
func newConfiguration(config ConfigurationAttr) *configuration {
4444
config.assignDefaultValues()
4545

4646
return &configuration{
@@ -118,86 +118,86 @@ type ConfigurationAttr struct {
118118
// assigns default values to ConfigurationAttr fields
119119
func (config *ConfigurationAttr) assignDefaultValues() {
120120
// Server defaults
121-
if config.hostAddress == EmptyString {
122-
config.hostAddress = DefaultHostAddress
121+
if config.hostAddress == emptyString {
122+
config.hostAddress = defaultHostAddress
123123
}
124124
if config.portNumber == 0 {
125-
config.portNumber = DefaultPortNuber
125+
config.portNumber = defaultPortNuber
126126
}
127-
if config.msgGreeting == EmptyString {
128-
config.msgGreeting = DefaultGreetingMsg
127+
if config.msgGreeting == emptyString {
128+
config.msgGreeting = defaultGreetingMsg
129129
}
130-
if config.msgInvalidCmd == EmptyString {
131-
config.msgInvalidCmd = DefaultInvalidCmdMsg
130+
if config.msgInvalidCmd == emptyString {
131+
config.msgInvalidCmd = defaultInvalidCmdMsg
132132
}
133-
if config.msgQuitCmd == EmptyString {
134-
config.msgQuitCmd = DefaultQuitMsg
133+
if config.msgQuitCmd == emptyString {
134+
config.msgQuitCmd = defaultQuitMsg
135135
}
136136
if config.sessionTimeout == 0 {
137-
config.sessionTimeout = DefaultSessionTimeout
137+
config.sessionTimeout = defaultSessionTimeout
138138
}
139139

140140
// HELO defaults
141-
if config.msgInvalidCmdHeloSequence == EmptyString {
142-
config.msgInvalidCmdHeloSequence = DefaultInvalidCmdHeloSequenceMsg
141+
if config.msgInvalidCmdHeloSequence == emptyString {
142+
config.msgInvalidCmdHeloSequence = defaultInvalidCmdHeloSequenceMsg
143143
}
144-
if config.msgInvalidCmdHeloArg == EmptyString {
145-
config.msgInvalidCmdHeloArg = DefaultInvalidCmdHeloArgMsg
144+
if config.msgInvalidCmdHeloArg == emptyString {
145+
config.msgInvalidCmdHeloArg = defaultInvalidCmdHeloArgMsg
146146
}
147-
if config.msgHeloBlacklistedDomain == EmptyString {
148-
config.msgHeloBlacklistedDomain = DefaultQuitMsg
147+
if config.msgHeloBlacklistedDomain == emptyString {
148+
config.msgHeloBlacklistedDomain = defaultQuitMsg
149149
}
150-
if config.msgHeloReceived == EmptyString {
151-
config.msgHeloReceived = DefaultReceivedMsg
150+
if config.msgHeloReceived == emptyString {
151+
config.msgHeloReceived = defaultReceivedMsg
152152
}
153153

154154
// MAIL FROM defaults
155-
if config.msgInvalidCmdMailfromSequence == EmptyString {
156-
config.msgInvalidCmdMailfromSequence = DefaultInvalidCmdMailfromSequenceMsg
155+
if config.msgInvalidCmdMailfromSequence == emptyString {
156+
config.msgInvalidCmdMailfromSequence = defaultInvalidCmdMailfromSequenceMsg
157157
}
158-
if config.msgInvalidCmdMailfromArg == EmptyString {
159-
config.msgInvalidCmdMailfromArg = DefaultInvalidCmdMailfromArgMsg
158+
if config.msgInvalidCmdMailfromArg == emptyString {
159+
config.msgInvalidCmdMailfromArg = defaultInvalidCmdMailfromArgMsg
160160
}
161-
if config.msgMailfromBlacklistedEmail == EmptyString {
162-
config.msgMailfromBlacklistedEmail = DefaultQuitMsg
161+
if config.msgMailfromBlacklistedEmail == emptyString {
162+
config.msgMailfromBlacklistedEmail = defaultQuitMsg
163163
}
164-
if config.msgMailfromReceived == EmptyString {
165-
config.msgMailfromReceived = DefaultReceivedMsg
164+
if config.msgMailfromReceived == emptyString {
165+
config.msgMailfromReceived = defaultReceivedMsg
166166
}
167167

168168
// RCPT TO defaults
169-
if config.msgInvalidCmdRcpttoSequence == EmptyString {
170-
config.msgInvalidCmdRcpttoSequence = DefaultInvalidCmdRcpttoSequenceMsg
169+
if config.msgInvalidCmdRcpttoSequence == emptyString {
170+
config.msgInvalidCmdRcpttoSequence = defaultInvalidCmdRcpttoSequenceMsg
171171
}
172-
if config.msgInvalidCmdRcpttoArg == EmptyString {
173-
config.msgInvalidCmdRcpttoArg = DefaultInvalidCmdRcpttoArgMsg
172+
if config.msgInvalidCmdRcpttoArg == emptyString {
173+
config.msgInvalidCmdRcpttoArg = defaultInvalidCmdRcpttoArgMsg
174174
}
175-
if config.msgRcpttoBlacklistedEmail == EmptyString {
176-
config.msgRcpttoBlacklistedEmail = DefaultQuitMsg
175+
if config.msgRcpttoBlacklistedEmail == emptyString {
176+
config.msgRcpttoBlacklistedEmail = defaultQuitMsg
177177
}
178-
if config.msgRcpttoNotRegisteredEmail == EmptyString {
179-
config.msgRcpttoNotRegisteredEmail = DefaultNotRegistredRcpttoEmailMsg
178+
if config.msgRcpttoNotRegisteredEmail == emptyString {
179+
config.msgRcpttoNotRegisteredEmail = defaultNotRegistredRcpttoEmailMsg
180180
}
181-
if config.msgRcpttoReceived == EmptyString {
182-
config.msgRcpttoReceived = DefaultReceivedMsg
181+
if config.msgRcpttoReceived == emptyString {
182+
config.msgRcpttoReceived = defaultReceivedMsg
183183
}
184184

185185
// DATA defaults
186-
if config.msgInvalidCmdDataSequence == EmptyString {
187-
config.msgInvalidCmdDataSequence = DefaultInvalidCmdDataSequenceMsg
186+
if config.msgInvalidCmdDataSequence == emptyString {
187+
config.msgInvalidCmdDataSequence = defaultInvalidCmdDataSequenceMsg
188188
}
189-
if config.msgDataReceived == EmptyString {
190-
config.msgDataReceived = DefaultReadyForReceiveMsg
189+
if config.msgDataReceived == emptyString {
190+
config.msgDataReceived = defaultReadyForReceiveMsg
191191
}
192192

193193
// Message defaults
194194
if config.msqSizeLimit == 0 {
195-
config.msqSizeLimit = DefaultMessageSizeLimit
195+
config.msqSizeLimit = defaultMessageSizeLimit
196196
}
197-
if config.msgMsgSizeIsTooBig == EmptyString {
198-
config.msgMsgSizeIsTooBig = fmt.Sprintf(DefaultMsgSizeIsTooBigMsg+" %d bytes", config.msqSizeLimit)
197+
if config.msgMsgSizeIsTooBig == emptyString {
198+
config.msgMsgSizeIsTooBig = fmt.Sprintf(defaultMsgSizeIsTooBigMsg+" %d bytes", config.msqSizeLimit)
199199
}
200-
if config.msgMsgReceived == EmptyString {
201-
config.msgMsgReceived = DefaultReceivedMsg
200+
if config.msgMsgReceived == emptyString {
201+
config.msgMsgReceived = defaultReceivedMsg
202202
}
203203
}

0 commit comments

Comments
 (0)