From 47dacbe207629a87248527d6ca02c07dc79beeab Mon Sep 17 00:00:00 2001 From: Wibowo Arindrarto Date: Thu, 12 Oct 2023 05:24:32 +0200 Subject: [PATCH] feat: Add skeleton for FeedStore.ViewEntry --- internal/store/view_entry.go | 28 ++++++++++++++++ internal/store/view_entry_test.go | 56 +++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 internal/store/view_entry.go create mode 100644 internal/store/view_entry_test.go diff --git a/internal/store/view_entry.go b/internal/store/view_entry.go new file mode 100644 index 0000000..0c07d2f --- /dev/null +++ b/internal/store/view_entry.go @@ -0,0 +1,28 @@ +// Copyright (c) 2023 Wibowo Arindrarto +// SPDX-License-Identifier: BSD-3-Clause + +package store + +import ( + "context" + "database/sql" + "fmt" +) + +func (s *SQLite) ViewEntry(ctx context.Context, entryID DBID) (*Entry, error) { + s.mu.Lock() + defer s.mu.Unlock() + + var entry *Entry + dbFunc := func(ctx context.Context, tx *sql.Tx) error { + return fmt.Errorf("unimplemented") + } + + fail := failF("SQLite.ViewFeed") + + err := s.withTx(ctx, dbFunc) + if err != nil { + return nil, fail(err) + } + return entry, nil +} diff --git a/internal/store/view_entry_test.go b/internal/store/view_entry_test.go new file mode 100644 index 0000000..7bcf637 --- /dev/null +++ b/internal/store/view_entry_test.go @@ -0,0 +1,56 @@ +// Copyright (c) 2023 Wibowo Arindrarto +// SPDX-License-Identifier: BSD-3-Clause + +package store + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestViewEntryOk(t *testing.T) { + t.Parallel() + + a := assert.New(t) + r := require.New(t) + st := newTestStore(t) + + dbFeeds := []*Feed{ + { + Title: "Feed A", + FeedURL: "http://a.com/feed.xml", + Updated: WrapNullString("2022-03-19T16:23:18.600+02:00"), + Entries: []*Entry{ + {Title: "Entry A1", IsRead: true}, + }, + }, + { + Title: "Feed X", + FeedURL: "http://x.com/feed.xml", + Updated: WrapNullString("2022-04-20T16:32:30.760+02:00"), + Entries: []*Entry{ + {Title: "Entry X1", IsRead: false}, + {Title: "Entry X2", IsRead: true}, + }, + }, + { + Title: "Feed B", + FeedURL: "http://b.com/feed.xml", + Updated: WrapNullString("2023-04-09T09:49:22.685+02:00"), + }, + } + keys := st.addFeeds(dbFeeds) + + r.Equal(3, st.countFeeds()) + r.Equal(2, st.countEntries(dbFeeds[1].FeedURL)) + + dbEntry, err := st.ViewEntry( + context.Background(), + keys[dbFeeds[1].Title].Entries["Entry X2"], + ) + r.EqualError(err, "SQLite.ViewFeed: unimplemented") + a.Nil(dbEntry) +}