@@ -86,6 +86,14 @@ func TestEchoStatic(t *testing.T) {
86
86
e .ServeHTTP (rec , req )
87
87
assert .Equal (http .StatusMovedPermanently , rec .Code )
88
88
assert .Equal ("/folder/" , rec .HeaderMap ["Location" ][0 ])
89
+
90
+ // Directory Redirect with non-root path
91
+ e .Static ("/static" , "_fixture" )
92
+ req = httptest .NewRequest (http .MethodGet , "/static" , nil )
93
+ rec = httptest .NewRecorder ()
94
+ e .ServeHTTP (rec , req )
95
+ assert .Equal (http .StatusMovedPermanently , rec .Code )
96
+ assert .Equal ("/static/" , rec .HeaderMap ["Location" ][0 ])
89
97
90
98
// Directory with index.html
91
99
e .Static ("/" , "_fixture" )
@@ -100,6 +108,40 @@ func TestEchoStatic(t *testing.T) {
100
108
101
109
}
102
110
111
+ func TestEchoStaticRedirectIndex (t * testing.T ) {
112
+ assert := assert .New (t )
113
+ e := New ()
114
+
115
+ // HandlerFunc
116
+ e .Static ("/static" , "_fixture" )
117
+
118
+ errCh := make (chan error )
119
+
120
+ go func () {
121
+ errCh <- e .Start ("127.0.0.1:1323" )
122
+ }()
123
+
124
+ time .Sleep (200 * time .Millisecond )
125
+
126
+ if resp , err := http .Get ("http://127.0.0.1:1323/static" ); err == nil {
127
+ defer resp .Body .Close ()
128
+ assert .Equal (http .StatusOK , resp .StatusCode )
129
+
130
+ if body , err := ioutil .ReadAll (resp .Body ); err == nil {
131
+ assert .Equal (true , strings .HasPrefix (string (body ), "<!doctype html>" ))
132
+ } else {
133
+ assert .Fail (err .Error ())
134
+ }
135
+
136
+ } else {
137
+ assert .Fail (err .Error ())
138
+ }
139
+
140
+ if err := e .Close (); err != nil {
141
+ t .Fatal (err )
142
+ }
143
+ }
144
+
103
145
func TestEchoFile (t * testing.T ) {
104
146
e := New ()
105
147
e .File ("/walle" , "_fixture/images/walle.png" )
0 commit comments