Repository: labstack/echo
Pull request #1557 (2020-04-25 15:37:28)

Add test case for Response
This checks whether Flush method of the writer was called.

codecov[bot]: # [Codecov](https://codecov.io/gh/labstack/echo/pull/1557?src=pr&el=h1) Report
> Merging [#1557](https://codecov.io/gh/labstack/echo/pull/1557?src=pr&el=desc) into [master](https://codecov.io/gh/labstack/echo/commit/2207c37bf875b40f2f7b14c587c1c3de7581340e&el=desc) will **increase** coverage by `0.09%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/labstack/echo/pull/1557/graphs/tree.svg?width=650&height=150&src=pr&token=vqnT76l79i)](https://codecov.io/gh/labstack/echo/pull/1557?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1557      +/-   ##
==========================================
+ Coverage   84.85%   84.94%   +0.09%     
==========================================
  Files          28       28              
  Lines        2166     2166              
==========================================
+ Hits         1838     1840       +2     
+ Misses        213      211       -2     
  Partials      115      115              
```


| [Impacted Files](https://codecov.io/gh/labstack/echo/pull/1557?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [response.go](https://codecov.io/gh/labstack/echo/pull/1557/diff?src=pr&el=tree#diff-cmVzcG9uc2UuZ28=) | `76.31% <0.00%> (+5.26%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/labstack/echo/pull/1557?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/labstack/echo/pull/1557?src=pr&el=footer). Last update [2207c37...037c746](https://codecov.io/gh/labstack/echo/pull/1557?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/group.go b/group.go
index 5d95825..426bef9 100644
--- a/group.go
+++ b/group.go
@@ -109,7 +109,7 @@ func (g *Group) Static(prefix, root string) {
 
 // File implements `Echo#File()` for sub-routes within the Group.
 func (g *Group) File(path, file string) {
-	g.file(g.prefix+path, file, g.GET)
+	g.file(path, file, g.GET)
 }
 
 // Add implements `Echo#Add()` for sub-routes within the Group.


Test patch:
diff --git a/group_test.go b/group_test.go
index 342cd29..c51fd91 100644
--- a/group_test.go
+++ b/group_test.go
@@ -1,7 +1,9 @@
 package echo
 
 import (
+	"io/ioutil"
 	"net/http"
+	"net/http/httptest"
 	"testing"
 
 	"github.com/stretchr/testify/assert"
@@ -26,6 +28,19 @@ func TestGroup(t *testing.T) {
 	g.File("/walle", "_fixture/images//walle.png")
 }
 
+func TestGroupFile(t *testing.T) {
+	e := New()
+	g := e.Group("/group")
+	g.File("/walle", "_fixture/images/walle.png")
+	expectedData, err := ioutil.ReadFile("_fixture/images/walle.png")
+	assert.Nil(t, err)
+	req := httptest.NewRequest(http.MethodGet, "/group/walle", nil)
+	rec := httptest.NewRecorder()
+	e.ServeHTTP(rec, req)
+	assert.Equal(t, http.StatusOK, rec.Code)
+	assert.Equal(t, expectedData, rec.Body.Bytes())
+}
+
 func TestGroupRouteMiddleware(t *testing.T) {
 	// Ensure middleware slices are not re-used
 	e := New()
diff --git a/response_test.go b/response_test.go
index bc570a5..07776ca 100644
--- a/response_test.go
+++ b/response_test.go
@@ -41,3 +41,13 @@ func TestResponse_Write_UsesSetResponseCode(t *testing.T) {
 	res.Write([]byte("test"))
 	assert.Equal(t, http.StatusBadRequest, rec.Code)
 }
+
+func TestResponse_Flush(t *testing.T) {
+	e := New()
+	rec := httptest.NewRecorder()
+	res := &Response{echo: e, Writer: rec}
+
+	res.Write([]byte("test"))
+	res.Flush()
+	assert.True(t, rec.Flushed)
+}