Skip to content

Commit

Permalink
feat: exclude sitemap.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Aug 11, 2020
1 parent 0b9bfb8 commit 150edf4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
8 changes: 5 additions & 3 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,14 @@ func hasDiff(output string) bool {
}

// ignore binary diff on sitemap.xml.gz (0 bytes diff)
for _, line := range strings.Split(output, "\n") {
if strings.TrimSpace(line) == "" {
for _, raw := range strings.Split(output, "\n") {
line := strings.TrimSpace(raw)

if line == "" {
continue
}

if !strings.HasSuffix(strings.TrimSpace(line), "sitemap.xml.gz") {
if !strings.HasSuffix(line, "sitemap.xml.gz") && !strings.HasSuffix(line, "sitemap.xml") {
return true
}
}
Expand Down
44 changes: 38 additions & 6 deletions core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ func Test_hasDiff(t *testing.T) {
M traefik/v2.2/sitemap.xml.gz
M traefik/v2.3/sitemap.xml.gz`,
},
{
desc: "only sitemap.xml",
output: ` M traefik/master/sitemap.xml
M traefik/sitemap.xml
M traefik/v2.0/sitemap.xml
M traefik/v2.1/sitemap.xml
M traefik/v2.2/sitemap.xml
M traefik/v2.3/sitemap.xml`,
},
{
desc: "mixed sitemap.xml and sitemap.xml.gz",
output: ` M traefik/master/sitemap.xml.gz
M traefik/master/sitemap.xml
M traefik/sitemap.xml
M traefik/sitemap.xml.gz
M traefik/v2.0/sitemap.xml
M traefik/v2.0/sitemap.xml.gz
M traefik/v2.1/sitemap.xml
M traefik/v2.1/sitemap.xml.gz
M traefik/v2.2/sitemap.xml
M traefik/v2.3/sitemap.xml`,
},
}

for _, test := range testCases {
Expand All @@ -43,12 +65,12 @@ func Test_hasDiff(t *testing.T) {
}{
{
desc: "simple",
output: `M traefik/master/sitemap.xml
M traefik/sitemap.xml
M traefik/v2.0/sitemap.xml
M traefik/v2.1/sitemap.xml
M traefik/v2.2/sitemap.xml
M traefik/v2.3/sitemap.xml`,
output: `M traefik/master/aaa.html
M traefik/bbb.html
M traefik/v2.0/ccc.html
M traefik/v2.1/ddd.html
M traefik/v2.2/eee.html
M traefik/v2.3/fff.html`,
},
{
desc: "sitemap.xml.gz but with other files",
Expand All @@ -58,6 +80,16 @@ func Test_hasDiff(t *testing.T) {
M traefik/v2.1/sitemap.xml.gz
M traefik/v2.2/sitemap.xml.gz
M traefik/v2.3/sitemap.xml.gz
?? foobar.txt`,
},
{
desc: "sitemap.xml but with other files",
output: ` M traefik/master/sitemap.xml
M traefik/sitemap.xml
M traefik/v2.0/sitemap.xml
M traefik/v2.1/sitemap.xml
M traefik/v2.2/sitemap.xml
M traefik/v2.3/sitemap.xml
?? foobar.txt`,
},
}
Expand Down

0 comments on commit 150edf4

Please sign in to comment.