mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
Refactor HTTP Client and LocalizedError packages
This commit is contained in:
parent
120aabfbce
commit
14e25ab9fe
104 changed files with 1277 additions and 10672 deletions
|
@ -9,7 +9,6 @@ import (
|
|||
"time"
|
||||
|
||||
"miniflux.app/v2/internal/config"
|
||||
"miniflux.app/v2/internal/http/client"
|
||||
)
|
||||
|
||||
// List of supported schedulers.
|
||||
|
@ -79,20 +78,13 @@ func (f *Feed) String() string {
|
|||
)
|
||||
}
|
||||
|
||||
// WithClientResponse updates feed attributes from an HTTP request.
|
||||
func (f *Feed) WithClientResponse(response *client.Response) {
|
||||
f.EtagHeader = response.ETag
|
||||
f.LastModifiedHeader = response.LastModified
|
||||
f.FeedURL = response.EffectiveURL
|
||||
}
|
||||
|
||||
// WithCategoryID initializes the category attribute of the feed.
|
||||
func (f *Feed) WithCategoryID(categoryID int64) {
|
||||
f.Category = &Category{ID: categoryID}
|
||||
}
|
||||
|
||||
// WithError adds a new error message and increment the error counter.
|
||||
func (f *Feed) WithError(message string) {
|
||||
// WithTranslatedErrorMessage adds a new error message and increment the error counter.
|
||||
func (f *Feed) WithTranslatedErrorMessage(message string) {
|
||||
f.ParsingErrorCount++
|
||||
f.ParsingErrorMsg = message
|
||||
}
|
||||
|
|
|
@ -10,28 +10,8 @@ import (
|
|||
"time"
|
||||
|
||||
"miniflux.app/v2/internal/config"
|
||||
"miniflux.app/v2/internal/http/client"
|
||||
)
|
||||
|
||||
func TestFeedWithResponse(t *testing.T) {
|
||||
response := &client.Response{ETag: "Some etag", LastModified: "Some date", EffectiveURL: "Some URL"}
|
||||
|
||||
feed := &Feed{}
|
||||
feed.WithClientResponse(response)
|
||||
|
||||
if feed.EtagHeader != "Some etag" {
|
||||
t.Fatal(`The ETag header should be set`)
|
||||
}
|
||||
|
||||
if feed.LastModifiedHeader != "Some date" {
|
||||
t.Fatal(`The LastModified header should be set`)
|
||||
}
|
||||
|
||||
if feed.FeedURL != "Some URL" {
|
||||
t.Fatal(`The Feed URL should be set`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedCategorySetter(t *testing.T) {
|
||||
feed := &Feed{}
|
||||
feed.WithCategoryID(int64(123))
|
||||
|
@ -47,7 +27,7 @@ func TestFeedCategorySetter(t *testing.T) {
|
|||
|
||||
func TestFeedErrorCounter(t *testing.T) {
|
||||
feed := &Feed{}
|
||||
feed.WithError("Some Error")
|
||||
feed.WithTranslatedErrorMessage("Some Error")
|
||||
|
||||
if feed.ParsingErrorMsg != "Some Error" {
|
||||
t.Error(`The error message must be set`)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue