aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config_test.go8
-rw-r--r--go.mod11
-rw-r--r--go.sum22
-rw-r--r--mailer_test.go9
-rw-r--r--pkg/twilio/filter_test.go58
5 files changed, 57 insertions, 51 deletions
diff --git a/config_test.go b/config_test.go
index 0ab881a..207f429 100644
--- a/config_test.go
+++ b/config_test.go
@@ -5,13 +5,15 @@ import (
_ "embed"
"testing"
- "github.com/stretchr/testify/assert"
+ "go.awhk.org/core"
)
//go:embed config_example.yaml
var cfg []byte
-func TestConfig(t *testing.T) {
+func TestConfig(s *testing.T) {
+ t := core.T{T: s}
+
_, err := loadConfig(bytes.NewReader(cfg))
- assert.NoError(t, err)
+ t.AssertErrorIs(nil, err)
}
diff --git a/go.mod b/go.mod
index 732c1fe..5afa31e 100644
--- a/go.mod
+++ b/go.mod
@@ -1,11 +1,14 @@
module go.awhk.org/fwdsms
-go 1.16
+go 1.19
require (
+ github.com/google/go-cmp v0.5.9
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
- github.com/stretchr/testify v1.7.0
- go.awhk.org/gosdd v0.2.0
- gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
+ go.awhk.org/core v0.6.1
+ go.awhk.org/gosdd v0.2.1
+ gopkg.in/yaml.v3 v3.0.1
)
+
+require github.com/felixge/httpsnoop v1.0.1 // indirect
diff --git a/go.sum b/go.sum
index fd2148f..b7fdab6 100644
--- a/go.sum
+++ b/go.sum
@@ -1,22 +1,16 @@
-github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
-github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
+github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
+github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
-github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-go.awhk.org/gosdd v0.2.0 h1:fNqC+9LtwfwUxDDq0d8cIoFllbzZmi8+fUIlew5D7vc=
-go.awhk.org/gosdd v0.2.0/go.mod h1:9LeQ9cX4ZghIWv6kF9ljk83NzsZJqQR3/R61DbsU3YI=
-golang.org/x/sys v0.0.0-20210218155724-8ebf48af031b h1:lAZ0/chPUDWwjqosYR0X4M490zQhMsiJ4K3DbA7o+3g=
-golang.org/x/sys v0.0.0-20210218155724-8ebf48af031b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+go.awhk.org/core v0.6.1 h1:lKkmAH/p/kSR7WAUbLzWIWU11wZNmFsrXDJWe8bfsH0=
+go.awhk.org/core v0.6.1/go.mod h1:lOs71woKF5QCNNEFjaACmhEj7U6IEGAFHw0Zo1Fyh50=
+go.awhk.org/gosdd v0.2.1 h1:6vgCRmRfQpHSBgAGsceu4nxArd0hXSw5lv3TZZjKn34=
+go.awhk.org/gosdd v0.2.1/go.mod h1:9LeQ9cX4ZghIWv6kF9ljk83NzsZJqQR3/R61DbsU3YI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
-gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/mailer_test.go b/mailer_test.go
index e1376c3..7da07ae 100644
--- a/mailer_test.go
+++ b/mailer_test.go
@@ -8,12 +8,15 @@ import (
"testing"
"time"
- "github.com/stretchr/testify/assert"
+ "github.com/google/go-cmp/cmp"
+ "go.awhk.org/core"
"go.awhk.org/fwdsms/pkg/twilio"
)
-func TestMailer_newEmail(t *testing.T) {
+func TestMailer_newEmail(s *testing.T) {
+ t := core.T{T: s, Options: []cmp.Option{cmp.AllowUnexported(email{})}}
+
m := newMailer(&Config{
Message: Message{
From: "fwdsms@example.com",
@@ -48,5 +51,5 @@ Hello World!`,
"",
}, "\r\n")),
}
- assert.Equal(t, wants, m.newEmail(sms))
+ t.AssertEqual(wants, m.newEmail(sms))
}
diff --git a/pkg/twilio/filter_test.go b/pkg/twilio/filter_test.go
index 8b406fb..fc66f26 100644
--- a/pkg/twilio/filter_test.go
+++ b/pkg/twilio/filter_test.go
@@ -10,80 +10,84 @@ import (
"strings"
"testing"
- "github.com/stretchr/testify/assert"
+ "go.awhk.org/core"
)
-func TestFilter_CheckRequestSignature(t *testing.T) {
+func TestFilter_CheckRequestSignature(s *testing.T) {
+ t := core.T{T: s}
+
th := &Filter{[]byte("token"), EmptyResponseHandler}
- t.Run("Good Signature (POST)", func(t *testing.T) {
- assert.NoError(t, th.CheckRequestSignature(newRequest(Post)))
+ t.Run("Good Signature (POST)", func(t *core.T) {
+ t.AssertErrorIs(nil, th.CheckRequestSignature(newRequest(Post)))
})
- t.Run("Good Signature (GET)", func(t *testing.T) {
- assert.NoError(t, th.CheckRequestSignature(newRequest(Get)))
+ t.Run("Good Signature (GET)", func(t *core.T) {
+ t.AssertErrorIs(nil, th.CheckRequestSignature(newRequest(Get)))
})
- t.Run("Missing Header", func(t *testing.T) {
+ t.Run("Missing Header", func(t *core.T) {
r := newRequest(Post)
r.Header.Del("X-Twilio-Signature")
- assert.ErrorIs(t, th.CheckRequestSignature(r), ErrMissingHeader)
+ t.AssertErrorIs(ErrMissingHeader, th.CheckRequestSignature(r))
})
- t.Run("Bad Base64", func(t *testing.T) {
+ t.Run("Bad Base64", func(t *core.T) {
r := newRequest(Post)
r.Header.Set("X-Twilio-Signature", "Very suspicious Base64 header.")
- assert.ErrorIs(t, th.CheckRequestSignature(r), ErrBase64)
+ t.AssertErrorIs(ErrBase64, th.CheckRequestSignature(r))
})
- t.Run("Signature Mismatch", func(t *testing.T) {
+ t.Run("Signature Mismatch", func(t *core.T) {
r := newRequest(Post)
r.Header.Set("X-Twilio-Signature", "dpE7iSS3LEQo72hCT34eBRt3UEI=")
- assert.ErrorIs(t, th.CheckRequestSignature(r), ErrSignatureMismatch)
+ t.AssertErrorIs(ErrSignatureMismatch, th.CheckRequestSignature(r))
})
}
-func TestFilter_ServeHTTP(t *testing.T) {
+func TestFilter_ServeHTTP(s *testing.T) {
+ t := core.T{T: s}
+
th := &Filter{[]byte("token"), EmptyResponseHandler}
- t.Run("Good Signature (POST)", func(t *testing.T) {
+ t.Run("Good Signature (POST)", func(t *core.T) {
w := httptest.NewRecorder()
th.ServeHTTP(w, newRequest(Post))
- assert.Equal(t, http.StatusOK, w.Code)
- assert.Equal(t, "text/xml", w.Result().Header.Get("Content-Type"))
- assert.Equal(t, "<Response/>", w.Body.String())
+ t.AssertEqual(http.StatusOK, w.Code)
+ t.AssertEqual("text/xml", w.Result().Header.Get("Content-Type"))
+ t.AssertEqual("<Response/>", w.Body.String())
})
- t.Run("Good Signature (GET)", func(t *testing.T) {
+ t.Run("Good Signature (GET)", func(t *core.T) {
w := httptest.NewRecorder()
th.ServeHTTP(w, newRequest(Get))
- assert.Equal(t, http.StatusOK, w.Code)
- assert.Equal(t, "text/xml", w.Result().Header.Get("Content-Type"))
- assert.Equal(t, "<Response/>", w.Body.String())
+ t.AssertEqual(http.StatusOK, w.Code)
+ t.AssertEqual("text/xml", w.Result().Header.Get("Content-Type"))
+ t.AssertEqual("<Response/>", w.Body.String())
})
- t.Run("Missing Header", func(t *testing.T) {
+ t.Run("Missing Header", func(t *core.T) {
w := httptest.NewRecorder()
r := newRequest(Post)
r.Header.Del("X-Twilio-Signature")
th.ServeHTTP(w, r)
- assert.Equal(t, http.StatusBadRequest, w.Code)
+ t.AssertEqual(http.StatusBadRequest, w.Code)
})
- t.Run("Bad Base64", func(t *testing.T) {
+ t.Run("Bad Base64", func(t *core.T) {
w := httptest.NewRecorder()
r := newRequest(Post)
r.Header.Set("X-Twilio-Signature", "Very suspicious Base64 header.")
th.ServeHTTP(w, r)
- assert.Equal(t, http.StatusBadRequest, w.Code)
+ t.AssertEqual(http.StatusBadRequest, w.Code)
})
- t.Run("Signature Mismatch", func(t *testing.T) {
+ t.Run("Signature Mismatch", func(t *core.T) {
w := httptest.NewRecorder()
r := newRequest(Post)
r.Header.Set("X-Twilio-Signature", "dpE7iSS3LEQo72hCT34eBRt3UEI=")
th.ServeHTTP(w, r)
- assert.Equal(t, http.StatusForbidden, w.Code)
+ t.AssertEqual(http.StatusForbidden, w.Code)
})
}