github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/ginx/anyfn/dl_test.go (about)

     1  package anyfn_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/bingoohuang/gg/pkg/ginx/adapt"
     7  	"github.com/bingoohuang/gg/pkg/ginx/anyfn"
     8  	"github.com/bingoohuang/gg/pkg/ginx/gintest"
     9  	"github.com/gin-gonic/gin"
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestDl(t *testing.T) {
    14  	af := anyfn.NewAdapter()
    15  	r := adapt.Adapt(gin.New(), af)
    16  
    17  	r.GET("/dl", af.F(func() anyfn.DlFile {
    18  		return anyfn.DlFile{DiskFile: "testdata/hello.txt"}
    19  	}))
    20  
    21  	rr := gintest.Get("/dl", r)
    22  	assert.Equal(t, 200, rr.StatusCode())
    23  	assert.Equal(t, []string{"attachment; filename=hello.txt"}, rr.Header()["Content-Disposition"])
    24  	assert.Equal(t, "Hello bingoohuang!", rr.Body())
    25  }