From 2175c683196d955d92cc59e6947a93716b54a991 Mon Sep 17 00:00:00 2001 From: Karthic Rao Date: Sat, 13 Jun 2015 09:54:54 +0530 Subject: [PATCH 1/4] Preliminary test case for setup/config/ext.go --- config/setup/ext_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 config/setup/ext_test.go diff --git a/config/setup/ext_test.go b/config/setup/ext_test.go new file mode 100644 index 000000000..27730230c --- /dev/null +++ b/config/setup/ext_test.go @@ -0,0 +1,31 @@ +package setup + +import ( + "testing" + + "github.com/mholt/caddy/middleware/gzip" +) + +func TestExt(t *testing.T) { + c := newTestController(`ext .html .htm .php`) + + mid, err := Ext(c) + + if err != nil { + t.Errorf("Expected no errors, got: %v", err) + } + + if mid == nil { + t.Fatal("Expected middleware, was nil instead") + } + + handler := mid(emptyNext) + myHandler, ok := handler.(ext.Ext) + if !ok { + t.Fatalf("Expected handler to be type Ext, got: %#v", handler) + } + + if !sameNext(myHandler.Next, emptyNext) { + t.Error("'Next' field of handler was not set properly") + } +} \ No newline at end of file From 2a166f088d89a38e7eb0a938aa37af878ebefd83 Mon Sep 17 00:00:00 2001 From: karthic rao Date: Sat, 13 Jun 2015 10:05:42 +0530 Subject: [PATCH 2/4] Update ext_test.go --- config/setup/ext_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/setup/ext_test.go b/config/setup/ext_test.go index 27730230c..4c1402beb 100644 --- a/config/setup/ext_test.go +++ b/config/setup/ext_test.go @@ -3,7 +3,7 @@ package setup import ( "testing" - "github.com/mholt/caddy/middleware/gzip" + "github.com/mholt/caddy/middleware/ext" ) func TestExt(t *testing.T) { @@ -28,4 +28,4 @@ func TestExt(t *testing.T) { if !sameNext(myHandler.Next, emptyNext) { t.Error("'Next' field of handler was not set properly") } -} \ No newline at end of file +} From d7db1b9576187079942966f97e21b1bd8772e0f3 Mon Sep 17 00:00:00 2001 From: karthic rao Date: Sat, 13 Jun 2015 15:56:29 +0530 Subject: [PATCH 3/4] Added Assertions Added assertions to check for the extensions in the order specified --- config/setup/ext_test.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/config/setup/ext_test.go b/config/setup/ext_test.go index 4c1402beb..a6e5e98c7 100644 --- a/config/setup/ext_test.go +++ b/config/setup/ext_test.go @@ -2,8 +2,8 @@ package setup import ( "testing" - - "github.com/mholt/caddy/middleware/ext" + + "github.com/mholt/caddy/middleware/extensions" ) func TestExt(t *testing.T) { @@ -20,12 +20,20 @@ func TestExt(t *testing.T) { } handler := mid(emptyNext) - myHandler, ok := handler.(ext.Ext) + myHandler, ok := handler.(extensions.Ext) + if !ok { t.Fatalf("Expected handler to be type Ext, got: %#v", handler) } - if !sameNext(myHandler.Next, emptyNext) { - t.Error("'Next' field of handler was not set properly") + if myHandler.Extensions[0] != ".html" { + t.Errorf("Expected .html in the list of Extensions") } + if myHandler.Extensions[1] != ".htm" { + t.Errorf("Expected .htm in the list of Extensions") + } + if myHandler.Extensions[2] != ".php" { + t.Errorf("Expected .php in the list of Extensions") + } + } From 076fc4d72cfef9994b72f6d786c18f5f8f7aed01 Mon Sep 17 00:00:00 2001 From: karthic rao Date: Sat, 13 Jun 2015 20:25:23 +0530 Subject: [PATCH 4/4] Update Update with missing assertion for the Next middleware being properly set , this makes sure that Ext middleware carries the requests to the further middlewares . --- config/setup/ext_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config/setup/ext_test.go b/config/setup/ext_test.go index a6e5e98c7..30cd12a7b 100644 --- a/config/setup/ext_test.go +++ b/config/setup/ext_test.go @@ -25,7 +25,7 @@ func TestExt(t *testing.T) { if !ok { t.Fatalf("Expected handler to be type Ext, got: %#v", handler) } - + if myHandler.Extensions[0] != ".html" { t.Errorf("Expected .html in the list of Extensions") } @@ -35,5 +35,9 @@ func TestExt(t *testing.T) { if myHandler.Extensions[2] != ".php" { t.Errorf("Expected .php in the list of Extensions") } + if !sameNext(myHandler.Next, emptyNext) { + t.Error("'Next' field of handler was not set properly") + } + }