mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 16:50:01 +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 ptJoin := 2; ptJoin < len(parts); ptJoin++ {
|
||||||
for i := 0; i <= len(parts)-ptJoin; i++ {
|
for i := 0; i <= len(parts)-ptJoin; i++ {
|
||||||
wg.Add(1)
|
|
||||||
c.res.Resolve(resolverQueueEntry{
|
c.res.Resolve(resolverQueueEntry{
|
||||||
Link: strings.Join(parts[i:i+ptJoin], connector),
|
Link: strings.Join(parts[i:i+ptJoin], connector),
|
||||||
Callback: func(link string) { links = str.AppendIfMissing(links, link) },
|
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 {
|
for _, part := range parts {
|
||||||
wg.Add(1)
|
|
||||||
c.res.Resolve(resolverQueueEntry{
|
c.res.Resolve(resolverQueueEntry{
|
||||||
Link: part,
|
Link: part,
|
||||||
Callback: func(link string) { links = str.AppendIfMissing(links, link) },
|
Callback: func(link string) { links = str.AppendIfMissing(links, link) },
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Luzifer/go_helpers/v2/str"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
@ -59,9 +60,10 @@ func TestScanForLinks(t *testing.T) {
|
||||||
c := New()
|
c := New()
|
||||||
|
|
||||||
for _, testCase := range []struct {
|
for _, testCase := range []struct {
|
||||||
Heuristic bool
|
Heuristic bool
|
||||||
Message string
|
Message string
|
||||||
ExpectedLinks []string
|
ExpectedLinks []string
|
||||||
|
ExpectedContains bool
|
||||||
}{
|
}{
|
||||||
// Case: full URL is present in the message
|
// Case: full URL is present in the message
|
||||||
{
|
{
|
||||||
|
@ -187,7 +189,21 @@ func TestScanForLinks(t *testing.T) {
|
||||||
}
|
}
|
||||||
sort.Strings(linksFound)
|
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) {
|
func (r resolver) Resolve(qe resolverQueueEntry) {
|
||||||
|
qe.WaitGroup.Add(1)
|
||||||
r.resolverC <- qe
|
r.resolverC <- qe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue