From 150edf4374fbfb79a6d2ee1011509821772e7bd6 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 11 Aug 2020 14:30:03 +0200 Subject: [PATCH] feat: exclude sitemap.xml --- core.go | 8 +++++--- core_test.go | 44 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/core.go b/core.go index 594617b..8a711a9 100644 --- a/core.go +++ b/core.go @@ -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 } } diff --git a/core_test.go b/core_test.go index 9776843..7a4e4c7 100644 --- a/core_test.go +++ b/core_test.go @@ -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 { @@ -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", @@ -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`, }, }