mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 11:51:17 +00:00
[linkcheck] Refactor: Improve wait-code
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
61bab3c984
commit
eb02858280
3 changed files with 21 additions and 6 deletions
|
@ -87,7 +87,6 @@ func (c Checker) scanPartsConnected(parts []string, connector string) (links []s
|
|||
|
||||
for ptJoin := 2; ptJoin < len(parts); ptJoin++ {
|
||||
for i := 0; i <= len(parts)-ptJoin; i++ {
|
||||
wg.Add(1)
|
||||
c.res.Resolve(resolverQueueEntry{
|
||||
Link: strings.Join(parts[i:i+ptJoin], connector),
|
||||
Callback: func(link string) { links = str.AppendIfMissing(links, link) },
|
||||
|
@ -108,7 +107,6 @@ func (c Checker) scanPlainNoObfuscate(message string) (links []string) {
|
|||
)
|
||||
|
||||
for _, part := range parts {
|
||||
wg.Add(1)
|
||||
c.res.Resolve(resolverQueueEntry{
|
||||
Link: part,
|
||||
Callback: func(link string) { links = str.AppendIfMissing(links, link) },
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/Luzifer/go_helpers/v2/str"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -59,9 +60,10 @@ func TestScanForLinks(t *testing.T) {
|
|||
c := New()
|
||||
|
||||
for _, testCase := range []struct {
|
||||
Heuristic bool
|
||||
Message string
|
||||
ExpectedLinks []string
|
||||
Heuristic bool
|
||||
Message string
|
||||
ExpectedLinks []string
|
||||
ExpectedContains bool
|
||||
}{
|
||||
// Case: full URL is present in the message
|
||||
{
|
||||
|
@ -187,7 +189,21 @@ func TestScanForLinks(t *testing.T) {
|
|||
}
|
||||
sort.Strings(linksFound)
|
||||
|
||||
assert.Equal(t, testCase.ExpectedLinks, linksFound, "links from message %q", testCase.Message)
|
||||
if testCase.ExpectedContains {
|
||||
for _, expLnk := range testCase.ExpectedLinks {
|
||||
assert.Contains(t, linksFound, expLnk)
|
||||
}
|
||||
|
||||
var extraLinks []string
|
||||
for _, link := range linksFound {
|
||||
if !str.StringInSlice(link, testCase.ExpectedLinks) {
|
||||
extraLinks = append(extraLinks, link)
|
||||
}
|
||||
}
|
||||
t.Logf("extra links found: %v", extraLinks)
|
||||
} else {
|
||||
assert.Equal(t, testCase.ExpectedLinks, linksFound)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@ func withSkipVerify() func(*resolver) {
|
|||
}
|
||||
|
||||
func (r resolver) Resolve(qe resolverQueueEntry) {
|
||||
qe.WaitGroup.Add(1)
|
||||
r.resolverC <- qe
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue