Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 7 additions & 32 deletions announce/email/email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package email_test

import (
"net/mail"
"reflect"
"strings"
"testing"
"time"

"github.com/go-test/deep"
"github.com/kylelemons/godebug/diff"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
email_announce "github.com/mtlynch/screenjournal/v2/announce/email"
"github.com/mtlynch/screenjournal/v2/email"
"github.com/mtlynch/screenjournal/v2/screenjournal"
Expand Down Expand Up @@ -222,20 +221,8 @@ To manage your notifications, visit https://dev.thescreenjournal.com/account/not
announcer := email_announce.New("https://dev.thescreenjournal.com", &sender, tt.store)
announcer.AnnounceNewReview(tt.review)

if len(sender.emailsSent) == len(tt.expectedEmails) {
for i, emailGot := range sender.emailsSent {
emailWant := tt.expectedEmails[i]
if diff := diff.Diff(emailWant.TextBody, emailGot.TextBody); diff != "" {
t.Errorf("email #%d (plaintext): %s", i, diff)
}
if diff := diff.Diff(emailWant.HtmlBody, emailGot.HtmlBody); diff != "" {
t.Errorf("email #%d (html) %s", i, diff)
}
}
}

if got, want := sender.emailsSent, tt.expectedEmails; !reflect.DeepEqual(got, want) {
t.Errorf("unexpected announcement emails, got=%+v, want=%+v", got, want)
if diff := cmp.Diff(tt.expectedEmails, sender.emailsSent, cmpopts.EquateComparable(time.Time{})); diff != "" {
t.Errorf("announcement emails mismatch (-want +got):\n%s", diff)
}
})
}
Expand Down Expand Up @@ -440,20 +427,8 @@ To manage your notifications, visit https://dev.thescreenjournal.com/account/not
announcer := email_announce.New("https://dev.thescreenjournal.com", &sender, tt.store)
announcer.AnnounceNewComment(tt.comment)

if len(sender.emailsSent) == len(tt.expectedEmails) {
for i, emailGot := range sender.emailsSent {
emailWant := tt.expectedEmails[i]
if diff := diff.Diff(emailWant.TextBody, emailGot.TextBody); diff != "" {
t.Errorf("email #%d (plaintext): %s", i, diff)
}
if diff := diff.Diff(emailWant.HtmlBody, emailGot.HtmlBody); diff != "" {
t.Errorf("email #%d (html) %s", i, diff)
}
}
}

if got, want := sender.emailsSent, tt.expectedEmails; !reflect.DeepEqual(got, want) {
t.Errorf("commentAnnouncements don't match expected: %s", strings.Join(deep.Equal(got, want), "\n"))
if diff := cmp.Diff(tt.expectedEmails, sender.emailsSent, cmpopts.EquateComparable(time.Time{})); diff != "" {
t.Errorf("comment announcement emails mismatch (-want +got):\n%s", diff)
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions email/smtp/convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"testing"

"github.com/kylelemons/godebug/diff"
"github.com/google/go-cmp/cmp"

"github.com/mtlynch/screenjournal/v2/email"
"github.com/mtlynch/screenjournal/v2/email/smtp/convert"
Expand Down Expand Up @@ -86,8 +86,8 @@ com/movies/1#review25</a></p>
t.Fatalf("failed to generate email: %v", err)
}

if diff := diff.Diff(actual, tt.expected); diff != "" {
t.Fatalf("unexpected smtp message for email: %s\n%s", tt.input.Subject, diff)
if diff := cmp.Diff(tt.expected, actual); diff != "" {
t.Fatalf("unexpected smtp message for email: %s (-want +got):\n%s", tt.input.Subject, diff)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ module github.com/mtlynch/screenjournal/v2
go 1.23

require (
github.com/go-test/deep v1.0.8
github.com/gomarkdown/markdown v0.0.0-20240723152757-afa4a469d4f9
github.com/gorilla/mux v1.8.0
github.com/kylelemons/godebug v1.1.0
github.com/microcosm-cc/bluemonday v1.0.27
github.com/mtlynch/gorilla-handlers v1.5.2
github.com/mtlynch/simpleauth/v2 v2.0.0-20241108014613-2f32145d692d
github.com/ncruces/go-sqlite3 v0.22.0
github.com/ryanbradynd05/go-tmdb v0.0.0-20220721194547-2ab6191c6273
)

require github.com/google/go-cmp v0.7.0

require (
codeberg.org/mtlynch/go-evolutionary-migrate v0.0.1
github.com/aymerick/douceur v0.2.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ 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/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/gomarkdown/markdown v0.0.0-20240723152757-afa4a469d4f9 h1:TRYrIWJziqvMVn1owO8bmkDJTlMQFYnf74yhD8LXfgU=
github.com/gomarkdown/markdown v0.0.0-20240723152757-afa4a469d4f9/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/gomodule/redigo v1.8.5 h1:nRAxCa+SVsyjSBrtZmG/cqb6VbTmuRzpg/PoTFlpumc=
github.com/gomodule/redigo v1.8.5/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
github.com/gorilla/handlers v1.4.0/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
Expand All @@ -22,8 +22,6 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/kylelemons/go-gypsy v1.0.0 h1:7/wQ7A3UL1bnqRMnZ6T8cwCOArfZCxFmb1iTxaOOo1s=
github.com/kylelemons/go-gypsy v1.0.0/go.mod h1:chkXM0zjdpXOiqkCW1XcCHDfjfk14PH2KKkQWxfJUcU=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
Expand Down
6 changes: 3 additions & 3 deletions handlers/comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

"github.com/go-test/deep"
"github.com/google/go-cmp/cmp"

"github.com/mtlynch/screenjournal/v2/auth"
"github.com/mtlynch/screenjournal/v2/handlers"
Expand Down Expand Up @@ -263,8 +263,8 @@ func TestCommentsPost(t *testing.T) {

clearUnpredictableCommentProperties(&announcer.announcedComments[0])
clearUnpredictableCommentProperties(&tt.expectedComments[0])
if !reflect.DeepEqual(announcer.announcedComments, tt.expectedComments) {
t.Errorf("did not find expected announced comments: %v", deep.Equal(announcer.announcedComments, tt.expectedComments))
if diff := cmp.Diff(tt.expectedComments, announcer.announcedComments, cmpOpts...); diff != "" {
t.Errorf("announced comments mismatch (-want +got):\n%s", diff)
}
})
}
Expand Down
20 changes: 12 additions & 8 deletions handlers/reviews_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"log"
"net/http"
"net/http/httptest"
"reflect"
"strings"
"testing"
"time"

"github.com/go-test/deep"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"

"github.com/mtlynch/screenjournal/v2/auth"
"github.com/mtlynch/screenjournal/v2/handlers"
Expand All @@ -34,6 +34,10 @@ var nilAnnouncer handlers.Announcer

var nilAuthenticator auth.Authenticator

var cmpOpts = []cmp.Option{
cmpopts.EquateComparable(time.Time{}, screenjournal.WatchDate{}, screenjournal.ReleaseDate{}),
}

type mockAnnouncer struct {
announcedReviews []screenjournal.Review
announcedComments []screenjournal.ReviewComment
Expand Down Expand Up @@ -448,17 +452,17 @@ func TestReviewsPost(t *testing.T) {
}

clearUnpredictableReviewProperties(&rr[0])
if got, want := rr[0], tt.expected; !reflect.DeepEqual(got, want) {
t.Errorf("got=%#v, want=%#v, diff=%s", got, want, deep.Equal(got, want))
if diff := cmp.Diff(tt.expected, rr[0], cmpOpts...); diff != "" {
t.Errorf("review mismatch (-want +got):\n%s", diff)
}

if got, want := len(announcer.announcedReviews), 1; got != want {
t.Fatalf("reviewCountAnnounced=%d, want=%d", got, want)
}

clearUnpredictableReviewProperties(&announcer.announcedReviews[0])
if got, want := announcer.announcedReviews[0], tt.expected; !reflect.DeepEqual(got, want) {
t.Errorf("got=%#v, want=%#v, diff=%s", got, want, deep.Equal(got, want))
if diff := cmp.Diff(tt.expected, announcer.announcedReviews[0], cmpOpts...); diff != "" {
t.Errorf("announced review mismatch (-want +got):\n%s", diff)
}
})
}
Expand Down Expand Up @@ -906,8 +910,8 @@ func TestReviewsPut(t *testing.T) {
}

clearUnpredictableReviewProperties(&rr[0])
if got, want := rr[0], tt.expected; !reflect.DeepEqual(got, want) {
t.Errorf("unexpected reviews, got=%+v, want=%+v, diff=%s", got, want, deep.Equal(got, want))
if diff := cmp.Diff(tt.expected, rr[0], cmpOpts...); diff != "" {
t.Errorf("review mismatch (-want +got):\n%s", diff)
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions handlers/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

"github.com/kylelemons/godebug/diff"
"github.com/google/go-cmp/cmp"

"github.com/mtlynch/screenjournal/v2/auth"
"github.com/mtlynch/screenjournal/v2/handlers"
Expand Down Expand Up @@ -225,8 +225,8 @@ func TestSearchGet(t *testing.T) {

got := removeBlankLines(string(response))
want := formatExpectedResponse(tt.response)
if delta := diff.Diff(got, want); delta != "" {
t.Errorf("diff in search response\nGot:\n%s\nWant:\n%s\nDiff:%s", got, want, delta)
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("search response mismatch (-want +got):\n%s", diff)
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions markdown/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package markdown_test
import (
"testing"

"github.com/kylelemons/godebug/diff"
"github.com/google/go-cmp/cmp"
"github.com/mtlynch/screenjournal/v2/markdown"
"github.com/mtlynch/screenjournal/v2/screenjournal"
)
Expand Down Expand Up @@ -107,10 +107,10 @@ The butler did it!`,
} {
t.Run(tt.description, func(t *testing.T) {
if got, want := markdown.RenderBlurb(screenjournal.Blurb(tt.in)), tt.out; got != want {
t.Errorf("rendered blurb=%s, want=%s, diff=%s", got, want, diff.Diff(got, want))
t.Errorf("rendered blurb mismatch (-want +got):\n%s", cmp.Diff(want, got))
}
if got, want := markdown.RenderComment(screenjournal.CommentText(tt.in)), tt.out; got != want {
t.Errorf("rendered comment=%s, want=%s, diff=%s", got, want, diff.Diff(got, want))
t.Errorf("rendered comment mismatch (-want +got):\n%s", cmp.Diff(want, got))
}
})
}
Expand Down