diff options
| author | Paul Buetow <paul@buetow.org> | 2024-10-17 11:11:28 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-10-17 11:11:28 +0300 |
| commit | b2230f9e34101e5491ceae2f8e79bdcc76321219 (patch) | |
| tree | ca4598a67087dea4c70e93eae9a0d03de5644813 /internal/queue | |
| parent | 563ea5dbaaa77e59939812d6825d54cf829db8eb (diff) | |
debugging queueing
Diffstat (limited to 'internal/queue')
| -rw-r--r-- | internal/queue/queue.go | 9 | ||||
| -rw-r--r-- | internal/queue/sharetags.go | 23 | ||||
| -rw-r--r-- | internal/queue/sharetags_test.go | 79 |
3 files changed, 29 insertions, 82 deletions
diff --git a/internal/queue/queue.go b/internal/queue/queue.go index ddd3136..f46e7a6 100644 --- a/internal/queue/queue.go +++ b/internal/queue/queue.go @@ -27,6 +27,7 @@ func Run(args config.Args) error { } // Queue all *.txt into ./db/*.txt.STAMP.queued +// TODO: This doesn't work correctly yet, neet to test it more! func queueEntries(args config.Args) error { ch, err := oi.ReadDirCh(args.GosDir, func(file os.DirEntry) (string, bool) { filePath := filepath.Join(args.GosDir, file.Name()) @@ -77,10 +78,10 @@ func queuePlatforms(args config.Args) error { if args.DryRun { continue } - log.Println("Removing", filePath) - if err := os.Remove(filePath); err != nil { - return err - } + // log.Println("Removing", filePath) + // if err := os.Remove(filePath); err != nil { + // return err + // } } return nil diff --git a/internal/queue/sharetags.go b/internal/queue/sharetags.go index b8088c0..6aa3c5f 100644 --- a/internal/queue/sharetags.go +++ b/internal/queue/sharetags.go @@ -1,12 +1,15 @@ package queue import ( + "log" "slices" "strings" "codeberg.org/snonux/gos/internal/config" ) +// TODO: Refactor this file, maybe a simple function is enough not a newShareTags + type shareTags struct { includes []string // The platforms to include excludes []string // The platforms to exclude @@ -19,13 +22,14 @@ func newShareTags(args config.Args, filePath string) shareTags { var s shareTags parts := strings.Split(filePath, ".") - tagStr := parts[len(parts)-2] + // TODO: Defensively test whether the parts is long enough + tagStr := parts[len(parts)-4] if len(parts) > 2 && strings.HasPrefix(tagStr, "share:") { for _, tag := range strings.Split(tagStr[6:], ":") { if strings.HasPrefix(tag, "-") { - s.excludes = append(s.excludes, tag[1:]) + s.excludes = append(s.excludes, strings.ToLower(tag[1:])) } else { - s.includes = append(s.includes, tag) + s.includes = append(s.includes, strings.ToLower(tag)) } } } @@ -33,17 +37,18 @@ func newShareTags(args config.Args, filePath string) shareTags { if len(s.includes) == 0 && len(s.excludes) == 0 { // If nothing found, include all of them for platform := range args.Platforms { - s.includes = append(s.includes, platform) + s.includes = append(s.includes, strings.ToLower(platform)) } } return s } -func (s shareTags) IsIncluded(platform string) bool { - return slices.Contains(s.includes, platform) && !slices.Contains(s.excludes, platform) -} - +// TODO: Write unit test func (s shareTags) IsExcluded(platform string) bool { - return slices.Contains(s.excludes, platform) || !slices.Contains(s.includes, platform) + log.Println("DEBUG", platform, s) + log.Println("DEBUG is it in the excludes", slices.Contains(s.excludes, strings.ToLower(platform))) + log.Println("DEBUG is it not in the includes", !slices.Contains(s.includes, strings.ToLower(platform))) + return slices.Contains(s.excludes, strings.ToLower(platform)) || + !slices.Contains(s.includes, strings.ToLower(platform)) } diff --git a/internal/queue/sharetags_test.go b/internal/queue/sharetags_test.go index 2a2a6aa..94de2a5 100644 --- a/internal/queue/sharetags_test.go +++ b/internal/queue/sharetags_test.go @@ -12,19 +12,19 @@ func TestShareTagsPositive(t *testing.T) { args := config.Args{Platforms: map[string]int{"mastodon": 100, "linkedin": 100}} testTable := map[string]shareTags{ - "./foo/bar.without.tags.txt": { + "./foo/bar.without.tags.txt.20240101-010101.queued": { includes: []string{"mastodon", "linkedin"}, }, - "./foo/bar.share:linkedin.txt": { + "./foo/bar.share:linkeDin.txt.20240101-010101.queued": { includes: []string{"linkedin"}, }, - "./foo/bar.share:-linkedin.txt": { + "./foo/bar.share:-LinkedIn.txt.20240101-010101.queued": { excludes: []string{"linkedin"}, }, - "./foo/bar.share:linkedin:mastodon.txt": { + "./foo/bar.share:linkedin:mastOdon.txt.20240101-010101.queued": { includes: []string{"linkedin", "mastodon"}, }, - "./foo/bar.share:linkedin:-mastodon:xcom.txt": { + "./foo/bar.share:linkediN:-mastodon:XCOM.txt.20240101-010101.queued": { includes: []string{"linkedin", "xcom"}, excludes: []string{"mastodon"}, }, @@ -48,19 +48,19 @@ func TestShareTagsNegative(t *testing.T) { args := config.Args{Platforms: map[string]int{"mastodon": 100, "linkedin": 100}} testTable := map[string]shareTags{ - "./foo/bar.without.tags.txt": { + "./foo/bar.without.tags.txt.20240101-010101.queued": { includes: []string{"linkedin"}, }, - "./foo/bar.share:linkedin.txt": { + "./foo/bar.share:linkedIn.txt.20240101-010101.queued": { includes: []string{"mastodon"}, }, - "./foo/bar.share:-linkedin.txt": { + "./foo/bar.share:-liNkedin.txt.20240101-010101.queued": { includes: []string{"linkedin"}, }, - "./foo/bar.share:linkedin:mastodon.txt": { + "./foo/bar.share:linkedin:mastodon.txt.20240101-010101.queued": { includes: []string{"oups", "mastodon"}, }, - "./foo/bar.share:linkedin:-mastodon:xcom.txt": { + "./foo/bar.share:linkedin:-MASTODON:xcom.txt.20240101-010101.queued": { includes: []string{"linkedin", "xcom"}, excludes: []string{"mastodon", "xcom"}, }, @@ -77,62 +77,3 @@ func TestShareTagsNegative(t *testing.T) { } } - -func TestShareTagsIsIncluded(t *testing.T) { - t.Parallel() - - assertIncluded := func(shareTags shareTags, platforms ...string) { - for _, platform := range platforms { - if !shareTags.IsIncluded(platform) { - t.Errorf("expected %s included in %v", platform, shareTags) - } - if shareTags.IsExcluded(platform) { - t.Errorf("expected %s not to be excluded in %v", platform, shareTags) - } - } - } - assertExcluded := func(shareTags shareTags, platforms ...string) { - for _, platform := range platforms { - if shareTags.IsIncluded(platform) { - t.Errorf("expected %s not to be included in %v", platform, shareTags) - } - if !shareTags.IsExcluded(platform) { - t.Errorf("expected %s to be excluded in %v", platform, shareTags) - } - } - } - args := config.Args{Platforms: map[string]int{"mastodon": 100, "linkedin": 100}} - - filePath := "foo/bar/baz.txt" - t.Run(filePath, func(t *testing.T) { - assertIncluded(newShareTags(args, filePath), "mastodon", "linkedin") - }) - - filePath = "foo/bar/baz.share:mastodon.txt" - t.Run(filePath, func(t *testing.T) { - assertIncluded(newShareTags(args, filePath), "mastodon") - assertExcluded(newShareTags(args, filePath), "linkedin") - }) - - filePath = "foo/bar/baz.share:mastodon.txt" - t.Run(filePath, func(t *testing.T) { - assertIncluded(newShareTags(args, filePath), "mastodon") - assertExcluded(newShareTags(args, filePath), "linkedin") - }) - - filePath = "foo/bar/baz.share:linkedin:mastodon.txt" - t.Run(filePath, func(t *testing.T) { - assertIncluded(newShareTags(args, filePath), "mastodon", "linkedin") - }) - - filePath = "foo/bar/baz.share:-linkedin:-mastodon.txt" - t.Run(filePath, func(t *testing.T) { - assertExcluded(newShareTags(args, filePath), "mastodon", "linkedin") - }) - - filePath = "foo/bar/baz.share:-linkedin:mastodon.txt" - t.Run(filePath, func(t *testing.T) { - assertIncluded(newShareTags(args, filePath), "mastodon") - assertExcluded(newShareTags(args, filePath), "linkedin") - }) -} |
