fix(e2e): 修复 E2E 测试使用正确的 API
- 使用 StartLolly 替代 StartLollyContainer - 简化 compression_e2e_test.go 的辅助函数 - 移除函数内的 import 语句 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
7c67c93ca6
commit
dbc74939d8
@ -51,7 +51,7 @@ servers:
|
||||
`
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
@ -92,7 +92,7 @@ servers:
|
||||
`
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
@ -133,7 +133,7 @@ servers:
|
||||
`
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
@ -170,7 +170,7 @@ servers:
|
||||
`
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
@ -213,7 +213,7 @@ servers:
|
||||
`
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
@ -263,7 +263,7 @@ servers:
|
||||
`, backendAddr)
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -38,9 +39,12 @@ func TestE2ECompressionGzip(t *testing.T) {
|
||||
}
|
||||
|
||||
// 创建包含可压缩内容的 HTML 文件
|
||||
htmlContent := `<html><body>` + repeatString("<p>Hello World</p>", 100) + `</body></html>`
|
||||
htmlContent := repeatString("<p>Hello World</p>", 100)
|
||||
tmpDir := t.TempDir()
|
||||
htmlPath := filepath.Join(tmpDir, "index.html")
|
||||
require.NoError(t, os.WriteFile(htmlPath, []byte(htmlContent), 0o644))
|
||||
|
||||
config := fmt.Sprintf(`
|
||||
config := `
|
||||
servers:
|
||||
- listen: ":8080"
|
||||
static:
|
||||
@ -52,12 +56,12 @@ servers:
|
||||
- "text/html"
|
||||
- "text/css"
|
||||
- "application/json"
|
||||
`)
|
||||
`
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "",
|
||||
lolly, err := testutil.StartLolly(ctx,
|
||||
testutil.WithConfigYAML(config),
|
||||
testutil.WithExtraMount(createTempHTMLFile(t, "index.html", htmlContent), "/var/www/html/index.html"),
|
||||
testutil.WithExtraMount(tmpDir, "/var/www/html"),
|
||||
)
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
@ -104,6 +108,9 @@ func TestE2ECompressionNoAcceptEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
htmlContent := `<html><body><p>Test Content</p></body></html>`
|
||||
tmpDir := t.TempDir()
|
||||
htmlPath := filepath.Join(tmpDir, "index.html")
|
||||
require.NoError(t, os.WriteFile(htmlPath, []byte(htmlContent), 0o644))
|
||||
|
||||
config := `
|
||||
servers:
|
||||
@ -116,9 +123,9 @@ servers:
|
||||
`
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "",
|
||||
lolly, err := testutil.StartLolly(ctx,
|
||||
testutil.WithConfigYAML(config),
|
||||
testutil.WithExtraMount(createTempHTMLFile(t, "index.html", htmlContent), "/var/www/html/index.html"),
|
||||
testutil.WithExtraMount(tmpDir, "/var/www/html"),
|
||||
)
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
@ -148,6 +155,9 @@ func TestE2ECompressionDisabled(t *testing.T) {
|
||||
}
|
||||
|
||||
htmlContent := repeatString("<p>Hello World</p>", 100)
|
||||
tmpDir := t.TempDir()
|
||||
htmlPath := filepath.Join(tmpDir, "index.html")
|
||||
require.NoError(t, os.WriteFile(htmlPath, []byte(htmlContent), 0o644))
|
||||
|
||||
config := `
|
||||
servers:
|
||||
@ -160,9 +170,9 @@ servers:
|
||||
`
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "",
|
||||
lolly, err := testutil.StartLolly(ctx,
|
||||
testutil.WithConfigYAML(config),
|
||||
testutil.WithExtraMount(createTempHTMLFile(t, "index.html", htmlContent), "/var/www/html/index.html"),
|
||||
testutil.WithExtraMount(tmpDir, "/var/www/html"),
|
||||
)
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
@ -200,8 +210,8 @@ func TestE2ECompressionPrecompressed(t *testing.T) {
|
||||
gzContent := gzipCompress(t, originalContent)
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
writeFile(t, tmpDir+"/test.js", originalContent)
|
||||
writeFile(t, tmpDir+"/test.js.gz", gzContent)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "test.js"), []byte(originalContent), 0o644))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "test.js.gz"), gzContent, 0o644))
|
||||
|
||||
config := `
|
||||
servers:
|
||||
@ -213,7 +223,7 @@ servers:
|
||||
`
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "",
|
||||
lolly, err := testutil.StartLolly(ctx,
|
||||
testutil.WithConfigYAML(config),
|
||||
testutil.WithExtraMount(tmpDir, "/var/www/html"),
|
||||
)
|
||||
@ -249,35 +259,6 @@ func repeatString(s string, n int) string {
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func createTempHTMLFile(t *testing.T, filename, content string) string {
|
||||
t.Helper()
|
||||
tmpDir := t.TempDir()
|
||||
filePath := tmpDir + "/" + filename
|
||||
writeFile(t, filePath, content)
|
||||
return filePath
|
||||
}
|
||||
|
||||
func writeFile(t *testing.T, path, content string) {
|
||||
t.Helper()
|
||||
require.NoError(t, writeFileErr(path, content))
|
||||
}
|
||||
|
||||
func writeFileErr(path, content string) error {
|
||||
return writeFileBytes(path, []byte(content))
|
||||
}
|
||||
|
||||
func writeFileBytes(path string, content []byte) error {
|
||||
return writeFileBytesWithPerm(path, content, 0o644)
|
||||
}
|
||||
|
||||
func writeFileBytesWithPerm(path string, content []byte, perm uint32) error {
|
||||
return writeFileWithPerm(path, content, perm)
|
||||
}
|
||||
|
||||
func writeFileWithPerm(path string, content []byte, perm uint32) error {
|
||||
return os.WriteFile(path, content, os.FileMode(perm))
|
||||
}
|
||||
|
||||
func gzipCompress(t *testing.T, content string) []byte {
|
||||
t.Helper()
|
||||
var buf bytes.Buffer
|
||||
|
||||
@ -54,7 +54,7 @@ servers:
|
||||
`, backendAddr)
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
@ -123,7 +123,7 @@ servers:
|
||||
`, backendAddr)
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
@ -177,7 +177,7 @@ servers:
|
||||
`, backendAddr)
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
@ -241,7 +241,7 @@ servers:
|
||||
`, backendAddr)
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ servers:
|
||||
`
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
@ -92,7 +92,7 @@ servers:
|
||||
`
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
@ -138,7 +138,7 @@ servers:
|
||||
`
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
@ -180,7 +180,7 @@ servers:
|
||||
`
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
@ -232,7 +232,7 @@ servers:
|
||||
`, backendAddr)
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
@ -274,7 +274,7 @@ servers:
|
||||
`
|
||||
|
||||
// 启动 lolly
|
||||
lolly, err := testutil.StartLollyContainer(ctx, "", testutil.WithConfigYAML(config))
|
||||
lolly, err := testutil.StartLolly(ctx, testutil.WithConfigYAML(config))
|
||||
require.NoError(t, err, "Failed to start lolly container")
|
||||
defer lolly.Terminate(ctx)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user