From 6bfebf75147c88c45f711463a3cfc0a11ac15498 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 18 Oct 2024 10:50:54 +0300 Subject: fix unit test --- internal/queue/queue.go | 8 ++++---- internal/queue/sharetags_test.go | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'internal') diff --git a/internal/queue/queue.go b/internal/queue/queue.go index f46e7a6..32d645f 100644 --- a/internal/queue/queue.go +++ b/internal/queue/queue.go @@ -78,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_test.go b/internal/queue/sharetags_test.go index 94de2a5..23628e4 100644 --- a/internal/queue/sharetags_test.go +++ b/internal/queue/sharetags_test.go @@ -33,10 +33,10 @@ func TestShareTagsPositive(t *testing.T) { for filePath, expectedResult := range testTable { t.Run(filePath, func(t *testing.T) { shareTags := newShareTags(args, filePath) - if !slices.Equal(shareTags.includes, expectedResult.includes) { + if !sameElements(shareTags.includes, expectedResult.includes) { t.Errorf("Expected includes to be %v but got %v", expectedResult.includes, shareTags.includes) } - if !slices.Equal(shareTags.excludes, expectedResult.excludes) { + if !sameElements(shareTags.excludes, expectedResult.excludes) { t.Errorf("Expected excludes to be %v but got %v", expectedResult.excludes, shareTags.excludes) } }) @@ -69,11 +69,24 @@ func TestShareTagsNegative(t *testing.T) { for filePath, unexpectedResult := range testTable { t.Run(filePath, func(t *testing.T) { shareTags := newShareTags(args, filePath) - if slices.Equal(shareTags.includes, unexpectedResult.includes) && - slices.Equal(shareTags.excludes, unexpectedResult.excludes) { + if sameElements(shareTags.includes, unexpectedResult.includes) && + sameElements(shareTags.excludes, unexpectedResult.excludes) { t.Errorf("expected %v not to be the actual result", unexpectedResult) } }) } } + +// Can't use sameElements as order may be different +func sameElements(a, b []string) bool { + if len(a) != len(b) { + return false + } + for _, elem := range a { + if !slices.Contains(b, elem) { + return false + } + } + return true +} -- cgit v1.2.3