From 3cff453494d5ef6a15832242722f8a796092f5db Mon Sep 17 00:00:00 2001 From: Azareal Date: Sun, 13 Oct 2019 19:07:05 +1000 Subject: [PATCH] push a bit of progress while fixing the tests --- common/relations.go | 17 ++++++++++++++--- parser_test.go | 6 +++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/common/relations.go b/common/relations.go index 4f278d4e..68965fa2 100644 --- a/common/relations.go +++ b/common/relations.go @@ -1,20 +1,31 @@ package common -import qgen "github.com/Azareal/Gosora/query_gen" +import ( + "database/sql" + + qgen "github.com/Azareal/Gosora/query_gen" +) type BlockStore interface { IsBlockedBy(blocker int, blockee int) (bool, error) } type DefaultBlockStore struct { + isBlocked *sql.Stmt } func NewDefaultBlockStore(acc *qgen.Accumulator) (*DefaultBlockStore, error) { - return &DefaultBlockStore{}, acc.FirstError() + return &DefaultBlockStore{ + isBlocked: acc.Select("users_blocks").Cols("blocker").Where("blocker = ? AND blockedUser = ?").Prepare(), + }, acc.FirstError() } func (s *DefaultBlockStore) IsBlockedBy(blocker int, blockee int) (bool, error) { - return false, nil + err := s.isBlocked.QueryRow(blocker, blockee).Scan(&blocker) + if err != nil && err != ErrNoRows { + return false, err + } + return err != ErrNoRows, nil } type FriendStore interface { diff --git a/parser_test.go b/parser_test.go index 621d2f41..1f7194d1 100644 --- a/parser_test.go +++ b/parser_test.go @@ -287,6 +287,9 @@ func TestParser(t *testing.T) { l.Add("@0", "[Invalid Profile]") l.Add("@-1", "[Invalid Profile]1") + // TODO: Fix this hack and make the results a bit more reproducible, push the tests further in the process. + pre2 := c.Site.EnableSsl + c.Site.EnableSsl = true for _, item := range l.Items { if res := c.ParseMessage(item.Msg, 1, "forums"); res != item.Expects { if item.Name != "" { @@ -298,10 +301,11 @@ func TestParser(t *testing.T) { break } } + c.Site.EnableSsl = pre2 l = &METriList{nil} pre := c.Site.URL // Just in case this is localhost... - pre2 := c.Site.EnableSsl + pre2 = c.Site.EnableSsl c.Site.URL = "example.com" c.Site.EnableSsl = true l.Add("//"+c.Site.URL, ""+c.Site.URL+"")