mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
chore: two small lint fixes (#506)
* chore: faster hash to string conv Signed-off-by: James Hillyerd <james@hillyerd.com> * chore: require NoError in integration test setup Signed-off-by: James Hillyerd <james@hillyerd.com> --------- Signed-off-by: James Hillyerd <james@hillyerd.com>
This commit is contained in:
@@ -2,7 +2,7 @@ package stringutil
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"fmt"
|
"encoding/hex"
|
||||||
"io"
|
"io"
|
||||||
"net/mail"
|
"net/mail"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -13,10 +13,11 @@ import (
|
|||||||
func HashMailboxName(mailbox string) string {
|
func HashMailboxName(mailbox string) string {
|
||||||
h := sha1.New()
|
h := sha1.New()
|
||||||
if _, err := io.WriteString(h, mailbox); err != nil {
|
if _, err := io.WriteString(h, mailbox); err != nil {
|
||||||
// This shouldn't ever happen
|
// This should never happen.
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%x", h.Sum(nil))
|
|
||||||
|
return hex.EncodeToString(h.Sum(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
// StringAddress converts an Address to a UTF-8 string.
|
// StringAddress converts an Address to a UTF-8 string.
|
||||||
|
|||||||
@@ -6,14 +6,17 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/inbucket/inbucket/v3/pkg/stringutil"
|
"github.com/inbucket/inbucket/v3/pkg/stringutil"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHashMailboxName(t *testing.T) {
|
func TestHashMailboxName(t *testing.T) {
|
||||||
want := "1d6e1cf70ec6f9ab28d3ea4b27a49a77654d370e"
|
want := "da39a3ee5e6b4b0d3255bfef95601890afd80709"
|
||||||
got := stringutil.HashMailboxName("mail")
|
got := stringutil.HashMailboxName("")
|
||||||
if got != want {
|
assert.Equal(t, want, got, "for empty string")
|
||||||
t.Errorf("Got %q, want %q", got, want)
|
|
||||||
}
|
want = "1d6e1cf70ec6f9ab28d3ea4b27a49a77654d370e"
|
||||||
|
got = stringutil.HashMailboxName("mail")
|
||||||
|
assert.Equal(t, want, got, "for 'mail'")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStringAddressList(t *testing.T) {
|
func TestStringAddressList(t *testing.T) {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ type IntegrationSuite struct {
|
|||||||
|
|
||||||
func (s *IntegrationSuite) SetupSuite() {
|
func (s *IntegrationSuite) SetupSuite() {
|
||||||
stopServer, err := startServer()
|
stopServer, err := startServer()
|
||||||
s.NoError(err)
|
s.Require().NoError(err)
|
||||||
s.stopServer = stopServer
|
s.stopServer = stopServer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user