Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Commit

Permalink
db: Fix sage and its effect on bump time
Browse files Browse the repository at this point in the history
close #1049
close #1048
  • Loading branch information
bakape committed May 1, 2019
1 parent bcd733e commit 90e3c91
Show file tree
Hide file tree
Showing 29 changed files with 227 additions and 121 deletions.
4 changes: 2 additions & 2 deletions auth/captcha_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestDecodeCaptcha(t *testing.T) {
r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
var c Captcha
c.FromRequest(r)
test.AssertDeepEquals(t, c, std)
test.AssertEquals(t, c, std)

src, err := json.Marshal(std)
if err != nil {
Expand All @@ -73,5 +73,5 @@ func TestDecodeCaptcha(t *testing.T) {
if err != nil {
t.Fatal(err)
}
test.AssertDeepEquals(t, c, std)
test.AssertEquals(t, c, std)
}
11 changes: 6 additions & 5 deletions cache/getters_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cache

import (
. "github.com/bakape/meguca/test"
"testing"
"time"

. "github.com/bakape/meguca/test"
)

func TestGetJSON(t *testing.T) {
Expand Down Expand Up @@ -33,8 +34,8 @@ func TestGetJSON(t *testing.T) {
if err := err; err != nil {
t.Fatal(err)
}
AssertDeepEquals(t, string(json), `"foo"`)
AssertDeepEquals(t, ctr, uint64(1))
AssertEquals(t, string(json), `"foo"`)
AssertEquals(t, ctr, uint64(1))
}
assertCount(t, "fetched", 1, fetches)
assertCount(t, "counter checked", 1, counterChecks)
Expand Down Expand Up @@ -70,8 +71,8 @@ func TestGetHTML(t *testing.T) {
if err := err; err != nil {
t.Fatal(err)
}
AssertDeepEquals(t, string(json), `bar`)
AssertDeepEquals(t, ctr, uint64(1))
AssertEquals(t, string(json), `bar`)
AssertEquals(t, ctr, uint64(1))
}
assertCount(t, "fetched", 1, fetches)
assertCount(t, "rendered", 1, fetches)
Expand Down
5 changes: 3 additions & 2 deletions common/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package common

import (
"encoding/json"
. "github.com/bakape/meguca/test"
"testing"

. "github.com/bakape/meguca/test"
)

func TestCommandsMarshaling(t *testing.T) {
Expand Down Expand Up @@ -35,7 +36,7 @@ func TestCommandsMarshaling(t *testing.T) {
if err != nil {
t.Fatal(err)
}
AssertDeepEquals(t, res, c.com)
AssertEquals(t, res, c.com)
})
}
}
12 changes: 6 additions & 6 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestSetGet(t *testing.T) {
if err := Set(conf); err != nil {
t.Fatal(err)
}
AssertDeepEquals(t, Get(), &conf)
AssertEquals(t, Get(), &conf)

json, hash := GetClient()
if json == nil {
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestGetBoards(t *testing.T) {
t.Fatal(err)
}

AssertDeepEquals(t, GetBoards(), []string{"a"})
AssertEquals(t, GetBoards(), []string{"a"})
}

func TestSetGetAddRemoveBoardConfigs(t *testing.T) {
Expand All @@ -81,14 +81,14 @@ func TestSetGetAddRemoveBoardConfigs(t *testing.T) {
if conf.JSON == nil {
t.Fatal("no JSON generated")
}
AssertDeepEquals(t, conf.BoardConfigs, std)
AssertEquals(t, conf.BoardConfigs, std)
if !IsBoard("a") {
t.Fatal("board does not exist")
}
AssertDeepEquals(t, len(GetAllBoardConfigs()), 1)
AssertEquals(t, len(GetAllBoardConfigs()), 1)

RemoveBoard("a")
AssertDeepEquals(t, GetBoardConfigs("a"), BoardConfContainer{})
AssertEquals(t, GetBoardConfigs("a"), BoardConfContainer{})
if IsBoard("a") {
t.Fatal("board not deleted")
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestGetBoardTitles(t *testing.T) {
}
}

AssertDeepEquals(t, GetBoardTitles(), BoardTitles{
AssertEquals(t, GetBoardTitles(), BoardTitles{
{
ID: "a",
Title: "Animu & Mango",
Expand Down
10 changes: 5 additions & 5 deletions db/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ func TestPurgePost(t *testing.T) {
if err != nil {
t.Fatal(err)
}
test.AssertDeepEquals(t, len(post.Moderation), 1)
test.AssertDeepEquals(t, post.Image == nil, true)
test.AssertDeepEquals(t, post.Body, "")
test.AssertEquals(t, len(post.Moderation), 1)
test.AssertEquals(t, post.Image == nil, true)
test.AssertEquals(t, post.Body, "")
}

func TestStickyThread(t *testing.T) {
Expand Down Expand Up @@ -355,7 +355,7 @@ func TestStaff(t *testing.T) {
if err != nil {
t.Fatal(err)
}
test.AssertDeepEquals(t, res, staff)
test.AssertEquals(t, res, staff)
}

func TestGetSameIPPosts(t *testing.T) {
Expand Down Expand Up @@ -429,7 +429,7 @@ func TestCanPerform(t *testing.T) {
if err != nil {
t.Fatal(err)
}
test.AssertDeepEquals(t, can, c.can)
test.AssertEquals(t, can, c.can)
})
}
}
4 changes: 2 additions & 2 deletions db/antispam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestSpamScores(t *testing.T) {
if err != c.needCaptchaErr {
test.UnexpectedError(t, err)
}
test.AssertDeepEquals(t, need, c.needCaptcha)
test.AssertEquals(t, need, c.needCaptcha)
})
}

Expand All @@ -106,7 +106,7 @@ func TestSpamScores(t *testing.T) {
if err != nil {
t.Fatal(err)
}
test.AssertDeepEquals(t, need, false)
test.AssertEquals(t, need, false)
})

t.Run("expiry", func(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions db/assets_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package db

import (
"testing"

"github.com/bakape/meguca/assets"
. "github.com/bakape/meguca/test"
"testing"
)

func TestBanners(t *testing.T) {
Expand Down Expand Up @@ -35,7 +36,7 @@ func TestBanners(t *testing.T) {
if !ok {
t.Fatal("banner not saved")
}
AssertDeepEquals(t, banner, std[0])
AssertEquals(t, banner, std[0])

err = SetBanners("a", []assets.File{})
if err != nil {
Expand Down Expand Up @@ -71,7 +72,7 @@ func TestLoaadingAnimations(t *testing.T) {
}

f := assets.Loading.Get("a")
AssertDeepEquals(t, f, std)
AssertEquals(t, f, std)

err = SetLoadingAnimation("a", assets.File{})
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions db/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestChangePassword(t *testing.T) {
if err != nil {
t.Fatal(err)
}
AssertDeepEquals(t, pass, samplePasswordHash)
AssertEquals(t, pass, samplePasswordHash)

newHash := []byte{1, 5, 51, 51, 3}
err = ChangePassword(sampleUserID, newHash)
Expand All @@ -72,7 +72,7 @@ func TestChangePassword(t *testing.T) {
if err != nil {
t.Fatal(err)
}
AssertDeepEquals(t, pass, newHash)
AssertEquals(t, pass, newHash)
}

func TestLoginLogout(t *testing.T) {
Expand Down Expand Up @@ -136,13 +136,13 @@ func TestGetPositions(t *testing.T) {
if err != nil {
t.Fatal(err)
}
AssertDeepEquals(t, pos, common.BoardOwner)
AssertEquals(t, pos, common.BoardOwner)

owned, err := GetOwnedBoards(sampleUserID)
if err != nil {
t.Fatal(err)
}
AssertDeepEquals(t, owned, []string{"a"})
AssertEquals(t, owned, []string{"a"})
}

func TestGetBanRecords(t *testing.T) {
Expand Down Expand Up @@ -173,13 +173,13 @@ func TestGetBanRecords(t *testing.T) {
}
// Location is a pointer and can't be compared with reflection
ban.Expires = std.Expires
AssertDeepEquals(t, ban, std)
AssertEquals(t, ban, std)

bans, err := GetBoardBans(std.Board)
if err != nil {
t.Fatal(err)
}
bans[0].Expires = std.Expires
std.Type = "classic"
AssertDeepEquals(t, bans, []auth.BanRecord{std})
AssertEquals(t, bans, []auth.BanRecord{std})
}
4 changes: 2 additions & 2 deletions db/captcha_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ func TestCaptchas(t *testing.T) {
c := cases[i]
t.Run(c.name, func(t *testing.T) {
err = ValidateCaptcha(c.captcha, ip)
test.AssertDeepEquals(t, err, c.err)
test.AssertEquals(t, err, c.err)

for _, dur := range [...]time.Duration{time.Hour, time.Minute} {
has, err := SolvedCaptchaRecently(ip, dur)
if err != nil {
t.Fatal(err)
}
test.AssertDeepEquals(t, has, c.hasSolved)
test.AssertEquals(t, has, c.hasSolved)
}
})
}
Expand Down
17 changes: 9 additions & 8 deletions db/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package db

import (
"database/sql"
"testing"

"github.com/bakape/meguca/config"
. "github.com/bakape/meguca/test"
"testing"
)

func TestLoadConfigs(t *testing.T) {
Expand All @@ -23,7 +24,7 @@ func TestLoadConfigs(t *testing.T) {
t.Fatal(err)
}

AssertDeepEquals(t, config.Get(), &std)
AssertEquals(t, config.Get(), &std)
}

func TestUpdateOnRemovedBoard(t *testing.T) {
Expand All @@ -37,12 +38,12 @@ func TestUpdateOnRemovedBoard(t *testing.T) {
t.Fatal(err)
}

AssertDeepEquals(
AssertEquals(
t,
config.GetBoardConfigs("a"),
config.BoardConfContainer{},
)
AssertDeepEquals(t, config.GetBoards(), []string{})
AssertEquals(t, config.GetBoards(), []string{})
}

func TestUpdateOnAddBoard(t *testing.T) {
Expand Down Expand Up @@ -70,12 +71,12 @@ func TestUpdateOnAddBoard(t *testing.T) {
t.Fatal(err)
}

AssertDeepEquals(
AssertEquals(
t,
config.GetBoardConfigs("a").BoardConfigs,
std.BoardConfigs,
)
AssertDeepEquals(t, config.GetBoards(), []string{"a"})
AssertEquals(t, config.GetBoards(), []string{"a"})
}

func TestUpdateBoardConfigs(t *testing.T) {
Expand Down Expand Up @@ -103,7 +104,7 @@ func TestUpdateBoardConfigs(t *testing.T) {
t.Fatal(err)
}

AssertDeepEquals(
AssertEquals(
t,
config.GetBoardConfigs("a").BoardConfigs,
std.BoardConfigs,
Expand All @@ -121,7 +122,7 @@ func TestUpdateBoardConfigs(t *testing.T) {
}

std.Title = "foo"
AssertDeepEquals(
AssertEquals(
t,
config.GetBoardConfigs("a").BoardConfigs,
std.BoardConfigs,
Expand Down
19 changes: 10 additions & 9 deletions db/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"database/sql"
"encoding/json"
"io/ioutil"
"github.com/bakape/meguca/common"
"github.com/bakape/meguca/imager/assets"
"github.com/bakape/meguca/test"
"os"
"sync"
"testing"
"time"

"github.com/bakape/meguca/common"
"github.com/bakape/meguca/imager/assets"
"github.com/bakape/meguca/test"
)

func writeSampleImage(t *testing.T) {
Expand Down Expand Up @@ -170,7 +171,7 @@ func TestInsertImage(t *testing.T) {
if err != nil {
t.Fatal(err)
}
test.AssertDeepEquals(t, has, std)
test.AssertEquals(t, has, std)
}

checkHas(false)
Expand Down Expand Up @@ -201,7 +202,7 @@ func TestInsertImage(t *testing.T) {
if err != nil {
t.Fatal(err)
}
test.AssertDeepEquals(t, img, result{
test.AssertEquals(t, img, result{
ID: postID,
Image: std,
})
Expand Down Expand Up @@ -243,7 +244,7 @@ func TestSpoilerImage(t *testing.T) {
if err != nil {
t.Fatal(err)
}
test.AssertDeepEquals(t, post.Image.Spoiler, true)
test.AssertEquals(t, post.Image.Spoiler, true)
}

func TestVideoPlaylist(t *testing.T) {
Expand Down Expand Up @@ -273,7 +274,7 @@ func TestVideoPlaylist(t *testing.T) {
if err != nil {
t.Fatal(err)
}
test.AssertDeepEquals(t, videos, []Video{
test.AssertEquals(t, videos, []Video{
{
FileType: common.WEBM,
Duration: time.Minute,
Expand All @@ -293,7 +294,7 @@ func TestImageExists(t *testing.T) {
if err != nil {
t.Fatal(err)
}
test.AssertDeepEquals(t, exists, false)
test.AssertEquals(t, exists, false)

writeSampleImage(t)

Expand All @@ -304,5 +305,5 @@ func TestImageExists(t *testing.T) {
if err != nil {
t.Fatal(err)
}
test.AssertDeepEquals(t, exists, true)
test.AssertEquals(t, exists, true)
}
Loading

0 comments on commit 90e3c91

Please sign in to comment.