Make 'tweet not in database' a named error that can be checked for
This commit is contained in:
parent
dcdec91d62
commit
7d2f35be68
@ -132,7 +132,11 @@ func (p Profile) GetTweetById(id TweetID) (Tweet, error) {
|
|||||||
`, id)
|
`, id)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Tweet{}, fmt.Errorf("Error executing GetTweetByID(%d):\n %w", id, err)
|
if err == sql.ErrNoRows {
|
||||||
|
return Tweet{}, fmt.Errorf("GetTweetById %d: %w", id, ErrNotInDB)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Spaces = []Space{}
|
t.Spaces = []Space{}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/go-test/deep"
|
"github.com/go-test/deep"
|
||||||
|
|
||||||
|
"gitlab.com/offline-twitter/twitter_offline_engine/pkg/persistence"
|
||||||
"gitlab.com/offline-twitter/twitter_offline_engine/pkg/scraper"
|
"gitlab.com/offline-twitter/twitter_offline_engine/pkg/scraper"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -326,3 +327,12 @@ func TestCheckTweetContentDownloadNeeded(t *testing.T) {
|
|||||||
// Should no longer need a download
|
// Should no longer need a download
|
||||||
assert.False(profile.CheckTweetContentDownloadNeeded(tweet))
|
assert.False(profile.CheckTweetContentDownloadNeeded(tweet))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoadMissingTweet(t *testing.T) {
|
||||||
|
profile_path := "test_profiles/TestTweetQueries"
|
||||||
|
profile := create_or_load_profile(profile_path)
|
||||||
|
|
||||||
|
_, err := profile.GetTweetById(scraper.TweetID(6234234)) // Random number
|
||||||
|
require.Error(t, err)
|
||||||
|
assert.ErrorIs(t, err, persistence.ErrNotInDB)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user