Skip to content

Commit

Permalink
fix: XML test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinB committed Aug 22, 2024
1 parent 3df2a5a commit 06f9770
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 21 deletions.
8 changes: 0 additions & 8 deletions internal/pkg/crawl/extractor/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"
"net/url"
"reflect"
"sort"
"testing"
)

Expand Down Expand Up @@ -82,10 +81,3 @@ func TestJSON(t *testing.T) {
})
}
}

// Helper function to sort URL slices
func sortURLs(urls []*url.URL) {
sort.Slice(urls, func(i, j int) bool {
return urls[i].String() < urls[j].String()
})
}
40 changes: 40 additions & 0 deletions internal/pkg/crawl/extractor/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package extractor

import (
"net/url"
"sort"
)

// compareURLs compares two slices of *url.URL
func compareURLs(a, b []*url.URL) bool {
if len(a) != len(b) {
return false
}

// Create a map to store the count of each URL in slice a
counts := make(map[string]int)
for _, url := range a {
counts[url.String()]++
}

// Decrement the count for each URL in slice b
for _, url := range b {
counts[url.String()]--
}

// Check if any count is non-zero, indicating a mismatch
for _, count := range counts {
if count != 0 {
return false
}
}

return true
}

// sortURLs sorts a slice of *url.URL
func sortURLs(urls []*url.URL) {
sort.Slice(urls, func(i, j int) bool {
return urls[i].String() < urls[j].String()
})
}
13 changes: 0 additions & 13 deletions internal/pkg/crawl/extractor/xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,3 @@ func TestXMLBodyReadError(t *testing.T) {
t.Errorf("XML() expected error, got nil")
}
}

// compareURLs compares two slices of *url.URL
func compareURLs(a, b []*url.URL) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i].String() != b[i].String() {
return false
}
}
return true
}

0 comments on commit 06f9770

Please sign in to comment.