diff options
| author | Paul Buetow <paul@buetow.org> | 2024-10-18 11:05:08 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-10-18 11:05:08 +0300 |
| commit | a8f87b7393f24ccd2435ac455bc8c750a4c203e2 (patch) | |
| tree | bd736ee54665d1045318109f30d4aace40bedddd /internal/queue | |
| parent | 6bfebf75147c88c45f711463a3cfc0a11ac15498 (diff) | |
fix
Diffstat (limited to 'internal/queue')
| -rw-r--r-- | internal/queue/sharetags.go | 6 | ||||
| -rw-r--r-- | internal/queue/sharetags_test.go | 16 |
2 files changed, 16 insertions, 6 deletions
diff --git a/internal/queue/sharetags.go b/internal/queue/sharetags.go index 6aa3c5f..79a94d8 100644 --- a/internal/queue/sharetags.go +++ b/internal/queue/sharetags.go @@ -34,9 +34,11 @@ func newShareTags(args config.Args, filePath string) shareTags { } } - if len(s.includes) == 0 && len(s.excludes) == 0 { - // If nothing found, include all of them + if len(s.includes) == 0 { for platform := range args.Platforms { + if slices.Contains(s.excludes, strings.ToLower(platform)) { + continue + } s.includes = append(s.includes, strings.ToLower(platform)) } } diff --git a/internal/queue/sharetags_test.go b/internal/queue/sharetags_test.go index 23628e4..3aa6b58 100644 --- a/internal/queue/sharetags_test.go +++ b/internal/queue/sharetags_test.go @@ -19,6 +19,7 @@ func TestShareTagsPositive(t *testing.T) { includes: []string{"linkedin"}, }, "./foo/bar.share:-LinkedIn.txt.20240101-010101.queued": { + includes: []string{"mastodon"}, excludes: []string{"linkedin"}, }, "./foo/bar.share:linkedin:mastOdon.txt.20240101-010101.queued": { @@ -28,16 +29,22 @@ func TestShareTagsPositive(t *testing.T) { includes: []string{"linkedin", "xcom"}, excludes: []string{"mastodon"}, }, + "./foo/bar/ql-e7657e8a1ab573f84ad0dbc55199e937.share:-mastodon.txt.20241018-105524.queued": { + includes: []string{"linkedin"}, + excludes: []string{"mastodon"}, + }, } for filePath, expectedResult := range testTable { t.Run(filePath, func(t *testing.T) { shareTags := newShareTags(args, filePath) if !sameElements(shareTags.includes, expectedResult.includes) { - t.Errorf("Expected includes to be %v but got %v", expectedResult.includes, shareTags.includes) + t.Errorf("Expected includes to be %v but got %v with %s", + expectedResult.includes, shareTags.includes, filePath) } if !sameElements(shareTags.excludes, expectedResult.excludes) { - t.Errorf("Expected excludes to be %v but got %v", expectedResult.excludes, shareTags.excludes) + t.Errorf("Expected excludes to be %v but got %v with %s", + expectedResult.excludes, shareTags.excludes, filePath) } }) @@ -71,14 +78,15 @@ func TestShareTagsNegative(t *testing.T) { shareTags := newShareTags(args, filePath) if sameElements(shareTags.includes, unexpectedResult.includes) && sameElements(shareTags.excludes, unexpectedResult.excludes) { - t.Errorf("expected %v not to be the actual result", unexpectedResult) + t.Errorf("expected %v not to be the actual result with %s", + unexpectedResult, filePath) } }) } } -// Can't use sameElements as order may be different +// Can't use slices.Equal as order of elements may be different. func sameElements(a, b []string) bool { if len(a) != len(b) { return false |
