Skip to content

Commit

Permalink
fix golangci-lint reported errors
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal committed Feb 20, 2024
1 parent faf39bb commit e64f24e
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 61 deletions.
14 changes: 0 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0.8
gocyclo:
min-complexity: 15
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
misspell:
locale: US
lll:
line-length: 140
gocritic:
enabled-tags:
- performance
Expand All @@ -34,7 +21,6 @@ linters:
- revive
- govet
- unconvert
- megacheck
- unused
- gas
- misspell
Expand Down
2 changes: 1 addition & 1 deletion app/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (s *Server) router() *chi.Mux {
rrss.Get("/feeds", s.getFeedsPageCtrl)
})

router.Get("/config", func(w http.ResponseWriter, r *http.Request) { rest.RenderJSON(w, s.Conf) })
router.Get("/config", func(w http.ResponseWriter, _ *http.Request) { rest.RenderJSON(w, s.Conf) })

router.Route("/yt", func(r chi.Router) {

Expand Down
12 changes: 6 additions & 6 deletions app/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestServer_Run(t *testing.T) {
func TestServer_getFeedCtrl(t *testing.T) {

store := &mocks.StoreMock{
LoadFunc: func(fmFeed string, max int, skipJunk bool) ([]feed.Item, error) {
LoadFunc: func(string, int, bool) ([]feed.Item, error) {
return []feed.Item{
{
GUID: "guid1",
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestServer_getFeedCtrl(t *testing.T) {
func TestServer_getFeedCtrlExtendDateTitle(t *testing.T) {

store := &mocks.StoreMock{
LoadFunc: func(fmFeed string, max int, skipJunk bool) ([]feed.Item, error) {
LoadFunc: func(string, int, bool) ([]feed.Item, error) {
return []feed.Item{
{
GUID: "guid1",
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestServer_getFeedCtrlExtendDateTitle(t *testing.T) {
func TestServer_getFeedCtrlFeedImage(t *testing.T) {

store := &mocks.StoreMock{
LoadFunc: func(fmFeed string, max int, skipJunk bool) ([]feed.Item, error) {
LoadFunc: func(string, int, bool) ([]feed.Item, error) {
return []feed.Item{
{
GUID: "guid1",
Expand Down Expand Up @@ -272,10 +272,10 @@ func TestServer_getFeedCtrlFeedImage(t *testing.T) {
func TestServer_regenerateRSSCtrl(t *testing.T) {

yt := &mocks.YoutubeSvcMock{
RSSFeedFunc: func(cinfo youtube.FeedInfo) (string, error) {
RSSFeedFunc: func(youtube.FeedInfo) (string, error) {
return "blah", nil
},
StoreRSSFunc: func(chanID string, rss string) error {
StoreRSSFunc: func(string, string) error {
return nil
},
}
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestServer_regenerateRSSCtrl(t *testing.T) {

func TestServer_removeEntryCtrl(t *testing.T) {
yt := &mocks.YoutubeSvcMock{
RemoveEntryFunc: func(entry ytfeed.Entry) error {
RemoveEntryFunc: func(ytfeed.Entry) error {
return nil
},
}
Expand Down
4 changes: 2 additions & 2 deletions app/feed/item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestGetFilename(t *testing.T) {

func TestDownloadAudioIfRequestError(t *testing.T) {
var ts *httptest.Server
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts = httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
ts.CloseClientConnections()
}))

Expand All @@ -49,7 +49,7 @@ func TestDownloadAudioIfRequestError(t *testing.T) {
}

func TestDownloadAudio(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Length", "4")
fmt.Fprint(w, "abcd")
Expand Down
6 changes: 3 additions & 3 deletions app/feed/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestFeedParse(t *testing.T) {
<media:credit role="author">Umputun, Bobuk, Gray, Ksenks, Alek.sys</media:credit><media:rating>nonadult</media:rating><media:description type="plain">Еженедельные импровизации на хай–тек темы</media:description></channel>
</rss>
`
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte(testFeed))
assert.NoError(t, err)
Expand All @@ -84,7 +84,7 @@ func TestFeedParse(t *testing.T) {
}

func TestFeedParseBadBody(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte("bad"))
assert.NoError(t, err)
Expand All @@ -96,7 +96,7 @@ func TestFeedParseBadBody(t *testing.T) {

func TestFeedParseHttpError(t *testing.T) {
var ts *httptest.Server
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts = httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
ts.CloseClientConnections()
}))

Expand Down
18 changes: 9 additions & 9 deletions app/proc/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (

func TestProcessor_DoRemoveOldItems(t *testing.T) {
lgr.Setup(lgr.Debug)
tgNotif := &mocks.TelegramNotifMock{SendFunc: func(chanID string, item feed.Item) error {
tgNotif := &mocks.TelegramNotifMock{SendFunc: func(string, feed.Item) error {
return nil
}}

twitterNotif := &mocks.TwitterNotifMock{SendFunc: func(item feed.Item) error {
twitterNotif := &mocks.TwitterNotifMock{SendFunc: func(feed.Item) error {
return nil
}}

Expand All @@ -41,7 +41,7 @@ func TestProcessor_DoRemoveOldItems(t *testing.T) {
testFeed, err := os.ReadFile("./testdata/rss1.xml")
require.NoError(t, err)

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Length", strconv.Itoa(len(testFeed)))
_, e := w.Write(testFeed)
Expand Down Expand Up @@ -159,11 +159,11 @@ func TestProcessor_DoRemoveOldItems(t *testing.T) {

func TestProcessor_DoLoadMaxItems(t *testing.T) {

tgNotif := &mocks.TelegramNotifMock{SendFunc: func(chanID string, item feed.Item) error {
tgNotif := &mocks.TelegramNotifMock{SendFunc: func(string, feed.Item) error {
return nil
}}

twitterNotif := &mocks.TwitterNotifMock{SendFunc: func(item feed.Item) error {
twitterNotif := &mocks.TwitterNotifMock{SendFunc: func(feed.Item) error {
return nil
}}

Expand All @@ -177,7 +177,7 @@ func TestProcessor_DoLoadMaxItems(t *testing.T) {
testFeed, err := os.ReadFile("./testdata/rss2.xml")
require.NoError(t, err)

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Length", strconv.Itoa(len(testFeed)))
_, e := w.Write(testFeed)
Expand Down Expand Up @@ -255,11 +255,11 @@ func TestProcessor_DoLoadMaxItems(t *testing.T) {

func TestProcessor_DoSkipItems(t *testing.T) {

tgNotif := &mocks.TelegramNotifMock{SendFunc: func(chanID string, item feed.Item) error {
tgNotif := &mocks.TelegramNotifMock{SendFunc: func(string, feed.Item) error {
return nil
}}

twitterNotif := &mocks.TwitterNotifMock{SendFunc: func(item feed.Item) error {
twitterNotif := &mocks.TwitterNotifMock{SendFunc: func(feed.Item) error {
return nil
}}

Expand All @@ -273,7 +273,7 @@ func TestProcessor_DoSkipItems(t *testing.T) {
testFeed, err := os.ReadFile("./testdata/rss1.xml")
require.NoError(t, err)

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Length", strconv.Itoa(len(testFeed)))
_, e := w.Write(testFeed)
Expand Down
22 changes: 11 additions & 11 deletions app/proc/telegram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ func TestTelegramClient_sendAudio(t *testing.T) {
defer ts.Close()

dur := &mocks.DurationServiceMock{
FileFunc: func(fname string) int {
FileFunc: func(string) int {
return 12345
},
}

snd := &mocks.TelegramSenderMock{
SendFunc: func(audio tb.Audio, bot *tb.Bot, recipient tb.Recipient, sendOptions *tb.SendOptions) (*tb.Message, error) {
SendFunc: func(tb.Audio, *tb.Bot, tb.Recipient, *tb.SendOptions) (*tb.Message, error) {
return nil, nil
},
}
Expand All @@ -235,13 +235,13 @@ func TestSendIfSendAudioFailed(t *testing.T) {
defer ts.Close()

dur := &mocks.DurationServiceMock{
FileFunc: func(fname string) int {
FileFunc: func(string) int {
return 12345
},
}

snd := &mocks.TelegramSenderMock{
SendFunc: func(audio tb.Audio, bot *tb.Bot, recipient tb.Recipient, sendOptions *tb.SendOptions) (*tb.Message, error) {
SendFunc: func(tb.Audio, *tb.Bot, tb.Recipient, *tb.SendOptions) (*tb.Message, error) {
return nil, errors.New("error while sending audio")
},
}
Expand All @@ -263,13 +263,13 @@ func TestSend(t *testing.T) {
defer ts.Close()

dur := &mocks.DurationServiceMock{
FileFunc: func(fname string) int {
FileFunc: func(string) int {
return 12345
},
}

snd := &mocks.TelegramSenderMock{
SendFunc: func(audio tb.Audio, bot *tb.Bot, recipient tb.Recipient, sendOptions *tb.SendOptions) (*tb.Message, error) {
SendFunc: func(tb.Audio, *tb.Bot, tb.Recipient, *tb.SendOptions) (*tb.Message, error) {
return &tb.Message{Text: "Some test message"}, nil
},
}
Expand All @@ -296,13 +296,13 @@ func TestSendTextIfAudioLarge(t *testing.T) {
defer ts.Close()

dur := &mocks.DurationServiceMock{
FileFunc: func(fname string) int {
FileFunc: func(string) int {
return 12345
},
}

snd := &mocks.TelegramSenderMock{
SendFunc: func(audio tb.Audio, bot *tb.Bot, recipient tb.Recipient, sendOptions *tb.SendOptions) (*tb.Message, error) {
SendFunc: func(tb.Audio, *tb.Bot, tb.Recipient, *tb.SendOptions) (*tb.Message, error) {
return nil, errors.New("Request Entity Too Large")
},
}
Expand Down Expand Up @@ -369,18 +369,18 @@ func mockTelegramServer(h http.HandlerFunc) *httptest.Server {
_, _ = w.Write([]byte(getMeResp))
})

router.Get("/download/some.mp3", func(w http.ResponseWriter, r *http.Request) {
router.Get("/download/some.mp3", func(w http.ResponseWriter, _ *http.Request) {
// taken from https://github.com/mathiasbynens/small/blob/master/mp3.mp3
smallMP3File := []byte{54, 53, 53, 48, 55, 54, 51, 52, 48, 48, 51, 49, 56, 52, 51, 50, 48, 55, 54, 49, 54, 55, 49, 55, 49, 55, 55, 49, 53, 49, 49, 56, 51, 51, 49, 52, 51, 56, 50, 49, 50, 56, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48}

_, _ = w.Write(smallMP3File)
})

router.Post("/bottest-token/sendMessage", func(w http.ResponseWriter, r *http.Request) {
router.Post("/bottest-token/sendMessage", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(`{"ok": true, "result": {"text": "Some test message"}}`))
})

router.Post("/bot/sendAudio", func(w http.ResponseWriter, r *http.Request) {
router.Post("/bot/sendAudio", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(`{"ok": true, "result": {"id": 1}}`))
})

Expand Down
8 changes: 4 additions & 4 deletions app/proc/twitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestNewTwitterClient(t *testing.T) {
AccessSecret: "d",
}

client := NewTwitterClient(twiAuth, func(item feed.Item) string {
client := NewTwitterClient(twiAuth, func(feed.Item) string {
return ""
}, nil)

Expand Down Expand Up @@ -49,7 +49,7 @@ func TestTwitterSendIfFieldsTwitterAuthEmpty(t *testing.T) {
AccessSecret: tt.accessSecret,
}

twitterFmtFn := func(item feed.Item) string {
twitterFmtFn := func(feed.Item) string {
return ""
}

Expand Down Expand Up @@ -83,10 +83,10 @@ func TestCleanText(t *testing.T) {
}

func TestTwitterSend(t *testing.T) {
twitPoster := &mocks.TweetPosterMock{PostTweetFunc: func(msg string, v url.Values) (anaconda.Tweet, error) {
twitPoster := &mocks.TweetPosterMock{PostTweetFunc: func(string, url.Values) (anaconda.Tweet, error) {
return anaconda.Tweet{}, nil
}}
formatter := func(item feed.Item) string {
formatter := func(feed.Item) string {
return "formatted text"
}

Expand Down
Loading

0 comments on commit e64f24e

Please sign in to comment.