Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic in test with template from embed fs #906

Closed
ringsaturn opened this issue Aug 15, 2023 · 1 comment
Closed

Panic in test with template from embed fs #906

ringsaturn opened this issue Aug 15, 2023 · 1 comment

Comments

@ringsaturn
Copy link

ringsaturn commented Aug 15, 2023

Describe the bug

Program panic in when using template files from embed fs.

To Reproduce

Steps to reproduce the behavior:

  1. Go to https://github.com/ringsaturn/hertz-template-test-panic/actions/workflows/ci.yml
  2. Click on latest ci run
  3. Scroll down
  4. See error: https://github.com/ringsaturn/hertz-template-test-panic/actions/runs/5869081099/job/15913303547#step:5:26

Expected behavior

CI should pass with HTTP 200.

Screenshots

If applicable, add screenshots to help explain your problem.

Hertz version:

0.6.7

Environment:

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/runner/.cache/go-build"
GOENV="/home/runner/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/runner/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/runner/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/hostedtoolcache/go/1.20.7/x64"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/hostedtoolcache/go/1.20.7/x64/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.7"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/runner/work/hertz-template-test-panic/hertz-template-test-panic/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4000659406=/tmp/go-build -gno-record-gcc-switches"

Additional context

Sample repo: https://github.com/ringsaturn/hertz-template-test-panic

package app

import (
	"context"
	"embed"
	"html/template"
	"net/http"

	"github.com/cloudwego/hertz/pkg/app"
	"github.com/cloudwego/hertz/pkg/app/server"
)

//go:embed template/*
var f embed.FS

func NewHertz() *server.Hertz {
	h := server.Default()
	h.SetHTMLTemplate(template.Must(template.New("").ParseFS(f, "template/*.html")))

	h.GET("/hello", func(c context.Context, ctx *app.RequestContext) {
		ctx.HTML(http.StatusOK, "hello.html", nil)
	})
	return h
}

Test:

package app_test

import (
	"net/http"
	"testing"

	"github.com/cloudwego/hertz/pkg/common/test/assert"
	"github.com/cloudwego/hertz/pkg/common/ut"
	"github.com/ringsaturn/hertz-template-test-panic/app"
)

func TestAppHello(t *testing.T) {
	h := app.NewHertz()
	w := ut.PerformRequest(h.Engine, "GET", "/hello", nil)
	resp := w.Result()
	t.Log(string(resp.BodyBytes()))
	assert.DeepEqual(t, http.StatusOK, resp.StatusCode())
}
@ringsaturn ringsaturn changed the title Panic with template from embed fs Panic in test with template from embed fs Aug 15, 2023
@li-jin-gou
Copy link
Member

not support and refer to #630

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants