1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 17:47:03 +00:00

chore: fix many cosmetic linter warnings (#486)

* fix whitespace warnings

Signed-off-by: James Hillyerd <james@hillyerd.com>

* fix a number of typos

Signed-off-by: James Hillyerd <james@hillyerd.com>

* fix many cosmetic linter warnings

Signed-off-by: James Hillyerd <james@hillyerd.com>

---------

Signed-off-by: James Hillyerd <james@hillyerd.com>
This commit is contained in:
James Hillyerd
2024-02-15 18:02:26 -08:00
committed by GitHub
parent 864a2ba2d2
commit baa2dbd3a1
19 changed files with 25 additions and 37 deletions

View File

@@ -70,7 +70,7 @@ func outputMbox(headers []*client.MessageHeader) error {
for _, h := range headers { for _, h := range headers {
source, err := h.GetSource() source, err := h.GetSource()
if err != nil { if err != nil {
return fmt.Errorf("Get source REST failed: %v", err) return fmt.Errorf("get source REST failed: %v", err)
} }
fmt.Printf("From %s\n", h.From) fmt.Printf("From %s\n", h.From)

View File

@@ -51,7 +51,7 @@ func (n *mbNaming) Decode(v string) error {
case "domain": case "domain":
*n = DomainNaming *n = DomainNaming
default: default:
return fmt.Errorf("Unknown MailboxNaming strategy: %q", v) return fmt.Errorf("unknown MailboxNaming strategy: %q", v)
} }
return nil return nil
} }

View File

@@ -83,7 +83,7 @@ func (eb *AsyncEventBroker[E]) AsyncTestListener(name string, capacity int) func
return &event, nil return &event, nil
case <-time.After(time.Second * 2): case <-time.After(time.Second * 2):
return nil, errors.New("Timeout waiting for event") return nil, errors.New("timeout waiting for event")
} }
} }
} }

View File

@@ -18,7 +18,7 @@ type Host struct {
// //
// After-events allow extensions to take an action after an event has completed. These events are // After-events allow extensions to take an action after an event has completed. These events are
// processed asynchronously with respect to the rest of Inbuckets operation. However, an event // processed asynchronously with respect to the rest of Inbuckets operation. However, an event
// listener will not be called until the one before it complets. // listener will not be called until the one before it completes.
type Events struct { type Events struct {
AfterMessageDeleted AsyncEventBroker[event.MessageMetadata] AfterMessageDeleted AsyncEventBroker[event.MessageMetadata]
AfterMessageStored AsyncEventBroker[event.MessageMetadata] AfterMessageStored AsyncEventBroker[event.MessageMetadata]

View File

@@ -110,7 +110,7 @@ func (s *StoreManager) Deliver(
// Deliver to each mailbox. // Deliver to each mailbox.
for _, mb := range inbound.Mailboxes { for _, mb := range inbound.Mailboxes {
// Append recipient and timestamp to generated Recieved header. // Append recipient and timestamp to generated Received header.
recvd := fmt.Sprintf("%s for <%s>; %s\r\n", recvdHeader, mb, tstamp) recvd := fmt.Sprintf("%s for <%s>; %s\r\n", recvdHeader, mb, tstamp)
// Deliver message. // Deliver message.

View File

@@ -352,7 +352,7 @@ func TestDeliverBeforeAndAfterMessageStoredEvents(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
// Confirm mailbox names overriden by Before were sent to After event. Order is // Confirm mailbox names overridden by `Before` were sent to `After` event. Order is
// not guaranteed. // not guaranteed.
got1, err := listener() got1, err := listener()
require.NoError(t, err) require.NoError(t, err)

View File

@@ -37,7 +37,7 @@ func (a *Addressing) ExtractMailbox(address string) (string, error) {
} }
if a.Config.MailboxNaming != config.FullNaming { if a.Config.MailboxNaming != config.FullNaming {
return "", fmt.Errorf("Unknown MailboxNaming value: %v", a.Config.MailboxNaming) return "", fmt.Errorf("unknown MailboxNaming value: %v", a.Config.MailboxNaming)
} }
if domain == "" { if domain == "" {

View File

@@ -33,7 +33,6 @@ func TestShouldAcceptDomain(t *testing.T) {
if got != tc.want { if got != tc.want {
t.Errorf("Got %v for %q, want: %v", got, tc.domain, tc.want) t.Errorf("Got %v for %q, want: %v", got, tc.domain, tc.want)
} }
}) })
} }
// Test with default reject. // Test with default reject.
@@ -60,7 +59,6 @@ func TestShouldAcceptDomain(t *testing.T) {
if got != tc.want { if got != tc.want {
t.Errorf("Got %v for %q, want: %v", got, tc.domain, tc.want) t.Errorf("Got %v for %q, want: %v", got, tc.domain, tc.want)
} }
}) })
} }
} }
@@ -90,7 +88,6 @@ func TestShouldStoreDomain(t *testing.T) {
if got != tc.want { if got != tc.want {
t.Errorf("Got store %v for %q, want: %v", got, tc.domain, tc.want) t.Errorf("Got store %v for %q, want: %v", got, tc.domain, tc.want)
} }
}) })
} }
// Test with storage disabled. // Test with storage disabled.
@@ -117,7 +114,6 @@ func TestShouldStoreDomain(t *testing.T) {
if got != tc.want { if got != tc.want {
t.Errorf("Got store %v for %q, want: %v", got, tc.domain, tc.want) t.Errorf("Got store %v for %q, want: %v", got, tc.domain, tc.want)
} }
}) })
} }
} }

View File

@@ -65,16 +65,16 @@ func TestDoTable(t *testing.T) {
uri string uri string
wantMethod string wantMethod string
base *url.URL base *url.URL
wantUrl string wantURL string
wantBody []byte wantBody []byte
}{ }{
{method: "GET", wantMethod: "GET", uri: "/doget", base: baseURL, wantUrl: baseURLStr + "/doget", wantBody: []byte("Test body 1")}, {method: "GET", wantMethod: "GET", uri: "/doget", base: baseURL, wantURL: baseURLStr + "/doget", wantBody: []byte("Test body 1")},
{method: "POST", wantMethod: "POST", uri: "/dopost", base: baseURL, wantUrl: baseURLStr + "/dopost", wantBody: []byte("Test body 2")}, {method: "POST", wantMethod: "POST", uri: "/dopost", base: baseURL, wantURL: baseURLStr + "/dopost", wantBody: []byte("Test body 2")},
{method: "GET", wantMethod: "GET", uri: "/doget", base: baseURLPath, wantUrl: baseURLPathStr + "/doget", wantBody: []byte("Test body 3")}, {method: "GET", wantMethod: "GET", uri: "/doget", base: baseURLPath, wantURL: baseURLPathStr + "/doget", wantBody: []byte("Test body 3")},
{method: "POST", wantMethod: "POST", uri: "/dopost", base: baseURLPath, wantUrl: baseURLPathStr + "/dopost", wantBody: []byte("Test body 4")}, {method: "POST", wantMethod: "POST", uri: "/dopost", base: baseURLPath, wantURL: baseURLPathStr + "/dopost", wantBody: []byte("Test body 4")},
} }
for _, test := range tests { for _, test := range tests {
testname := fmt.Sprintf("%s,%s", test.method, test.wantUrl) testname := fmt.Sprintf("%s,%s", test.method, test.wantURL)
t.Run(testname, func(t *testing.T) { t.Run(testname, func(t *testing.T) {
mth := &mockHTTPClient{} mth := &mockHTTPClient{}
c := &restClient{mth, test.base} c := &restClient{mth, test.base}
@@ -85,8 +85,8 @@ func TestDoTable(t *testing.T) {
if mth.req.Method != test.wantMethod { if mth.req.Method != test.wantMethod {
t.Errorf("req.Method == %q, want %q", mth.req.Method, test.wantMethod) t.Errorf("req.Method == %q, want %q", mth.req.Method, test.wantMethod)
} }
if mth.req.URL.String() != test.wantUrl { if mth.req.URL.String() != test.wantURL {
t.Errorf("req.URL == %q, want %q", mth.req.URL.String(), test.wantUrl) t.Errorf("req.URL == %q, want %q", mth.req.URL.String(), test.wantURL)
} }
if !bytes.Equal(mth.ReqBody(), test.wantBody) { if !bytes.Equal(mth.ReqBody(), test.wantBody) {
t.Errorf("req.Body == %q, want %q", mth.ReqBody(), test.wantBody) t.Errorf("req.Body == %q, want %q", mth.ReqBody(), test.wantBody)

View File

@@ -1,7 +1,9 @@
package rest package rest
import "github.com/gorilla/mux" import (
import "github.com/inbucket/inbucket/v3/pkg/server/web" "github.com/gorilla/mux"
"github.com/inbucket/inbucket/v3/pkg/server/web"
)
// SetupRoutes populates the routes for the REST interface // SetupRoutes populates the routes for the REST interface
func SetupRoutes(r *mux.Router) { func SetupRoutes(r *mux.Router) {

View File

@@ -463,7 +463,7 @@ func (s *Session) transactionHandler(cmd string, args []string) {
s.processDeletes() s.processDeletes()
s.enterState(QUIT) s.enterState(QUIT)
case "NOOP": case "NOOP":
s.send("+OK I have sucessfully done nothing") s.send("+OK I have successfully done nothing")
case "RSET": case "RSET":
// Reset session, don't actually delete anything I told you to // Reset session, don't actually delete anything I told you to
s.logger.Debug().Msgf("Resetting session state on RSET request") s.logger.Debug().Msgf("Resetting session state on RSET request")

View File

@@ -206,7 +206,7 @@ func (s *Server) startSession(id int, conn net.Conn, logger zerolog.Logger) {
ssn.send("252 Cannot VRFY user, but will accept message") ssn.send("252 Cannot VRFY user, but will accept message")
continue continue
case "NOOP": case "NOOP":
ssn.send("250 I have sucessfully done nothing") ssn.send("250 I have successfully done nothing")
continue continue
case "RSET": case "RSET":
// Reset session // Reset session

View File

@@ -222,7 +222,6 @@ func TestReadyStateRejectedDomains(t *testing.T) {
} }
}) })
} }
} }
// Test invalid commands in READY state. // Test invalid commands in READY state.
@@ -255,7 +254,6 @@ func TestReadyStateInvalidCommands(t *testing.T) {
} }
}) })
} }
} }
// Test commands in MAIL state // Test commands in MAIL state
@@ -562,7 +560,6 @@ func TestBeforeMailAcceptedEventResponse(t *testing.T) {
assert.NotNil(t, gotEvent, "BeforeMailListener did not receive Address") assert.NotNil(t, gotEvent, "BeforeMailListener did not receive Address")
}) })
} }
} }
// net.Pipe does not implement deadlines // net.Pipe does not implement deadlines

View File

@@ -51,11 +51,7 @@ type Server struct {
} }
// NewServer sets up things for unit tests or the Start() method. // NewServer sets up things for unit tests or the Start() method.
func NewServer( func NewServer(conf *config.Root, mm message.Manager, mh *msghub.Hub) *Server {
conf *config.Root,
mm message.Manager,
mh *msghub.Hub) *Server {
rootConfig = conf rootConfig = conf
// NewContext() will use this DataStore for the web handlers. // NewContext() will use this DataStore for the web handlers.

View File

@@ -9,7 +9,7 @@ import (
// access in most cases without requiring an infinite number of mutexes. // access in most cases without requiring an infinite number of mutexes.
type HashLock [4096]sync.RWMutex type HashLock [4096]sync.RWMutex
// Get returns a RWMutex based on the first 12 bits of the mailbox hash. Hash must be a hexidecimal // Get returns a RWMutex based on the first 12 bits of the mailbox hash. Hash must be a hexadecimal
// string of three or more characters. // string of three or more characters.
func (h *HashLock) Get(hash string) *sync.RWMutex { func (h *HashLock) Get(hash string) *sync.RWMutex {
if len(hash) < 3 { if len(hash) < 3 {

View File

@@ -36,7 +36,7 @@ func TestHashLock(t *testing.T) {
t.Run(ts, func(t *testing.T) { t.Run(ts, func(t *testing.T) {
l := hl.Get(ts) l := hl.Get(ts)
if l == nil { if l == nil {
t.Errorf("Expeced non-nil lock for hex string %q", ts) t.Errorf("Expected non-nil lock for hex string %q", ts)
} }
}) })
} }

View File

@@ -33,7 +33,7 @@ type mbox struct {
var _ storage.Store = &Store{} var _ storage.Store = &Store{}
// New returns an emtpy memory store. // New returns an empty memory store.
func New(cfg config.Storage, extHost *extension.Host) (storage.Store, error) { func New(cfg config.Storage, extHost *extension.Host) (storage.Store, error) {
s := &Store{ s := &Store{
boxes: make(map[string]*mbox), boxes: make(map[string]*mbox),

View File

@@ -95,11 +95,9 @@ func MatchWithWildcards(p string, s string) bool {
if runePattern[j-1] == '*' { if runePattern[j-1] == '*' {
isMatchingMatrix[0][j] = isMatchingMatrix[0][j-1] isMatchingMatrix[0][j] = isMatchingMatrix[0][j-1]
} }
} }
for i := 1; i <= lenInput; i++ { for i := 1; i <= lenInput; i++ {
for j := 1; j <= lenPattern; j++ { for j := 1; j <= lenPattern; j++ {
if runePattern[j-1] == '*' { if runePattern[j-1] == '*' {
isMatchingMatrix[i][j] = isMatchingMatrix[i-1][j] || isMatchingMatrix[i][j-1] isMatchingMatrix[i][j] = isMatchingMatrix[i-1][j] || isMatchingMatrix[i][j-1]
} }

View File

@@ -30,5 +30,4 @@ func TestSanitizeStyle(t *testing.T) {
} }
}) })
} }
} }