Skip to content

Commit

Permalink
feat: Add skeleton for FeedStore.ViewEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
bow committed Oct 12, 2023
1 parent 103b2be commit 47dacbe
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
28 changes: 28 additions & 0 deletions internal/store/view_entry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2023 Wibowo Arindrarto <[email protected]>
// 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
}
56 changes: 56 additions & 0 deletions internal/store/view_entry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2023 Wibowo Arindrarto <[email protected]>
// 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)
}

0 comments on commit 47dacbe

Please sign in to comment.