Skip to content

Commit

Permalink
🐛 remove mock
Browse files Browse the repository at this point in the history
  • Loading branch information
perebaj committed Jan 24, 2024
1 parent 2a202d2 commit c19fdcd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 46 deletions.
10 changes: 6 additions & 4 deletions mail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package newsletter
import (
"context"
"testing"

"github.com/perebaj/newsletter/mock"
)

type MailClientMockImpl struct{}

func (m MailClientMockImpl) Send(_ []string, _ string) error { return nil }

func TestEmailTrigger(t *testing.T) {
ctx := context.Background()
s := mock.NewStorageMock()
e := mock.MailClientMockImpl{}
s := NewStorageMock()
e := MailClientMockImpl{}
err := EmailTrigger(ctx, s, e)
if err != nil {
t.Errorf("expected nil, got %v", err)
Expand Down
6 changes: 0 additions & 6 deletions mock/mail.go

This file was deleted.

31 changes: 0 additions & 31 deletions mock/scraper.go

This file was deleted.

29 changes: 24 additions & 5 deletions scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,42 @@ import (
"testing"
"time"

"github.com/perebaj/newsletter/mock"
"github.com/perebaj/newsletter/mongodb"
)

// const fakeURL = "http://fakeurl.test"
type StorageMockImpl struct{}

const FakeURL = "http://fakeurl.test"

func NewStorageMock() StorageMockImpl { return StorageMockImpl{} }
func (s StorageMockImpl) SavePage(_ context.Context, _ []mongodb.Page) error { return nil }
func (s StorageMockImpl) DistinctEngineerURLs(_ context.Context) ([]interface{}, error) {
return []interface{}{FakeURL}, nil
}
func (s StorageMockImpl) Page(_ context.Context, _ string) ([]mongodb.Page, error) {
return []mongodb.Page{}, nil
}
func (s StorageMockImpl) Newsletter() ([]mongodb.Newsletter, error) {
return []mongodb.Newsletter{{URLs: []string{FakeURL}}}, nil
}
func (s StorageMockImpl) PageIn(_ context.Context, _ []string) ([]mongodb.Page, error) {
return []mongodb.Page{
{IsMostRecent: true, URL: FakeURL, Content: "Hello, World!", HashMD5: md5.Sum([]byte("Hello, World!"))},
{IsMostRecent: true, URL: FakeURL, Content: "Hello, World! 2", HashMD5: md5.Sum([]byte("Hello, World! 2"))},
}, nil
}

func TestPageComparation(t *testing.T) {
recentScrapedPage := Page{
Content: "Hello, World!",
URL: mock.FakeURL,
URL: FakeURL,
ScrapeDateTime: time.Now().UTC(),
}

lastScrapedPage := []mongodb.Page{
{
Content: "Hello, World!",
URL: mock.FakeURL,
URL: FakeURL,
ScrapeDatetime: time.Now().UTC().Add(-time.Duration(1) * time.Hour),
HashMD5: md5.Sum([]byte("Hello, World!")),
},
Expand Down Expand Up @@ -60,7 +79,7 @@ func TestPageComparation(t *testing.T) {
func TestCrawlerRun(t *testing.T) {
timeoutCh := time.After(time.Duration(150) * time.Millisecond)
ctx := context.Background()
s := mock.NewStorageMock()
s := NewStorageMock()

f := func(string) (string, error) {
return "Hello, World!", nil
Expand Down

0 comments on commit c19fdcd

Please sign in to comment.