From ec83dc7141cae7fbbe6c1bf6e5ae41833921895c Mon Sep 17 00:00:00 2001 From: Parnic Date: Sun, 5 May 2024 13:57:18 -0500 Subject: [PATCH] Fix tests to work on Windows (irrespective of line endings) --- dynamic_test.go | 9 +++++---- multitemplate_test.go | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/dynamic_test.go b/dynamic_test.go index 0a2cefa..e29e11e 100644 --- a/dynamic_test.go +++ b/dynamic_test.go @@ -3,6 +3,7 @@ package multitemplate import ( "html/template" "os" + "strings" "testing" "github.com/gin-gonic/gin" @@ -81,7 +82,7 @@ func TestAddFromFilesDynamic(t *testing.T) { w := performRequest(router, "GET", "/") assert.Equal(t, 200, w.Code) - assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", w.Body.String()) + assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", strings.ReplaceAll(w.Body.String(), "\r", "")) } func TestAddFromGlobDynamic(t *testing.T) { @@ -95,7 +96,7 @@ func TestAddFromGlobDynamic(t *testing.T) { w := performRequest(router, "GET", "/") assert.Equal(t, 200, w.Code) - assert.Equal(t, "

Test Multiple Template

\nHi, this is login template\n", w.Body.String()) + assert.Equal(t, "

Test Multiple Template

\nHi, this is login template\n", strings.ReplaceAll(w.Body.String(), "\r", "")) } func TestAddFromFSDynamic(t *testing.T) { @@ -109,7 +110,7 @@ func TestAddFromFSDynamic(t *testing.T) { w := performRequest(router, "GET", "/") assert.Equal(t, 200, w.Code) - assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", w.Body.String()) + assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", strings.ReplaceAll(w.Body.String(), "\r", "")) } func TestAddFromStringDynamic(t *testing.T) { @@ -151,7 +152,7 @@ func TestAddFromFilesFruncsDynamic(t *testing.T) { w := performRequest(router, "GET", "/") assert.Equal(t, 200, w.Code) - assert.Equal(t, "Welcome to index template\n", w.Body.String()) + assert.Equal(t, "Welcome to index template\n", strings.ReplaceAll(w.Body.String(), "\r", "")) } func TestPanicInvalidTypeBuilder(t *testing.T) { diff --git a/multitemplate_test.go b/multitemplate_test.go index 6b631de..c02af34 100644 --- a/multitemplate_test.go +++ b/multitemplate_test.go @@ -6,6 +6,7 @@ import ( "net/http" "net/http/httptest" "os" + "strings" "testing" "github.com/gin-gonic/gin" @@ -84,7 +85,7 @@ func TestAddFromFiles(t *testing.T) { w := performRequest(router, "GET", "/") assert.Equal(t, 200, w.Code) - assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", w.Body.String()) + assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", strings.ReplaceAll(w.Body.String(), "\r", "")) } func TestAddFromGlob(t *testing.T) { @@ -98,7 +99,7 @@ func TestAddFromGlob(t *testing.T) { w := performRequest(router, "GET", "/") assert.Equal(t, 200, w.Code) - assert.Equal(t, "

Test Multiple Template

\nHi, this is login template\n", w.Body.String()) + assert.Equal(t, "

Test Multiple Template

\nHi, this is login template\n", strings.ReplaceAll(w.Body.String(), "\r", "")) } func TestAddFromFS(t *testing.T) { @@ -112,7 +113,7 @@ func TestAddFromFS(t *testing.T) { w := performRequest(router, "GET", "/") assert.Equal(t, 200, w.Code) - assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", w.Body.String()) + assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", strings.ReplaceAll(w.Body.String(), "\r", "")) } func TestAddFromString(t *testing.T) { @@ -154,7 +155,7 @@ func TestAddFromFilesFruncs(t *testing.T) { w := performRequest(router, "GET", "/") assert.Equal(t, 200, w.Code) - assert.Equal(t, "Welcome to index template\n", w.Body.String()) + assert.Equal(t, "Welcome to index template\n", strings.ReplaceAll(w.Body.String(), "\r", "")) } func TestDuplicateTemplate(t *testing.T) {