package static_test import ( "net/http" "os" "path/filepath" "testing" "git.company.lan/gopkg/gin" "git.company.lan/gopkg/gin-contrib/static" "github.com/stretchr/testify/assert" ) 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(), `