first commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package static_test
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gitverse.ru/andoma/gin"
|
||||
"gitverse.ru/andoma/gin-contrib/static"
|
||||
)
|
||||
|
||||
func TestLocalFile(t *testing.T) {
|
||||
// SETUP file
|
||||
testRoot, _ := os.Getwd()
|
||||
f, err := os.CreateTemp(testRoot, "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer os.Remove(f.Name())
|
||||
_, _ = f.WriteString("Gin Web Framework")
|
||||
f.Close()
|
||||
|
||||
dir, filename := filepath.Split(f.Name())
|
||||
router := gin.New()
|
||||
router.Use(static.Serve("/", static.LocalFile(dir, true)))
|
||||
|
||||
w := PerformRequest(router, "GET", "/"+filename)
|
||||
assert.Equal(t, w.Code, http.StatusOK)
|
||||
assert.Equal(t, w.Body.String(), "Gin Web Framework")
|
||||
|
||||
w = PerformRequest(router, "GET", "/")
|
||||
assert.Contains(t, w.Body.String(), `<a href="`+filename)
|
||||
}
|
||||
Reference in New Issue
Block a user