From b12cc125e6da86910f7f77bf96cd43b5d7ea4f55 Mon Sep 17 00:00:00 2001 From: Chrstopher Hunter <8398225+crhntr@users.noreply.github.com> Date: Fri, 23 Aug 2024 10:28:46 -0700 Subject: [PATCH] test GOPACKGE env var usage --- .../testdata/generate/generate_env_vars.txtar | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 cmd/muxt/testdata/generate/generate_env_vars.txtar diff --git a/cmd/muxt/testdata/generate/generate_env_vars.txtar b/cmd/muxt/testdata/generate/generate_env_vars.txtar new file mode 100644 index 0000000..8690009 --- /dev/null +++ b/cmd/muxt/testdata/generate/generate_env_vars.txtar @@ -0,0 +1,52 @@ +env GOPACKAGE=server + +muxt generate + +exec go test -cover + +-- template.gohtml -- +{{define "GET /" }}

Hello, world!

{{end}} + +-- go.mod -- +module server + +go 1.22 + +-- template.go -- +package server + +import ( + "embed" + "html/template" +) + +//go:embed *.gohtml +var formHTML embed.FS + +var templates = template.Must(template.ParseFS(formHTML, "*")) +-- template_test.go -- +package server + +import ( + "testing" + + "net/http" + "net/http/httptest" +) + +func Test(t *testing.T) { + mux := http.NewServeMux() + + routes(mux, nil) + + req := httptest.NewRequest(http.MethodGet, "/", nil) + rec := httptest.NewRecorder() + + mux.ServeHTTP(rec, req) + + res := rec.Result() + + if res.StatusCode != http.StatusOK { + t.Error("expected OK") + } +}