summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-10-18 10:50:54 +0300
committerPaul Buetow <paul@buetow.org>2024-10-18 10:50:54 +0300
commit6bfebf75147c88c45f711463a3cfc0a11ac15498 (patch)
tree2c93f44293eba8b866001b112f78b1a35a806c1d /internal
parentb2230f9e34101e5491ceae2f8e79bdcc76321219 (diff)
fix unit test
Diffstat (limited to 'internal')
-rw-r--r--internal/queue/queue.go8
-rw-r--r--internal/queue/sharetags_test.go21
2 files changed, 21 insertions, 8 deletions
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
+}