internal/screentest: remove hostname from output file extension

The original motivation to add hostnames to the files
was to make them easier to identify. Now that the origins
can be dynamically set with template variables, it causes
more trouble than it helps.

After removing the extensions, we can support reusing a
single test script for multiple origins. For example:

  compare {{.Origin}}::cache {{.Origin}}

Origin may be set to https://staging-pkg.go.dev or
http://localhost:8080 and share the same set of screenshots.

Change-Id: I2c1811fcb0fa7cca9e3b5feeb362528fd3f07af4
Reviewed-on: https://go-review.googlesource.com/c/website/+/382157
Run-TryBot: Jamal Carvalho <jamal@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Trust: Jamal Carvalho <jamalcarvalho@google.com>
This commit is contained in:
Jamal Carvalho 2022-02-01 17:51:11 +00:00 коммит произвёл Jamal Carvalho
Родитель 617d83c5d4
Коммит c4c0da89ae
5 изменённых файлов: 37 добавлений и 39 удалений

Просмотреть файл

@ -267,11 +267,11 @@ func cleanOutput(ctx context.Context, tests []*testcase) error {
dirs := make(map[string]bool)
// The extensions of files that are safe to delete
safeExts := map[string]bool{
"a.png": true,
"b.png": true,
"diff.png": true,
}
for _, t := range tests {
safeExts[ext(t.outImgA)] = true
safeExts[ext(t.outImgB)] = true
if t.cacheA {
keepFiles[t.outImgA] = true
}
@ -570,8 +570,8 @@ func readTests(file string, vars map[string]string) ([]*testcase, error) {
if gcsBucket {
outfile = out + "/" + sanitized(test.name)
}
test.outImgA = outfile + "." + sanitized(urlA.Host) + ".a.png"
test.outImgB = outfile + "." + sanitized(urlB.Host) + ".b.png"
test.outImgA = outfile + ".a.png"
test.outImgB = outfile + ".b.png"
test.outDiff = outfile + ".diff.png"
default:
// We should never reach this error.

Просмотреть файл

@ -43,8 +43,8 @@ func TestReadTests(t *testing.T) {
name: "go.dev homepage",
urlA: "https://go.dev/",
urlB: "http://localhost:6060/go.dev/",
outImgA: filepath.Join(cache, "readtests-txt", "go-dev-homepage.go-dev.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "go-dev-homepage.localhost-6060.b.png"),
outImgA: filepath.Join(cache, "readtests-txt", "go-dev-homepage.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "go-dev-homepage.b.png"),
outDiff: filepath.Join(cache, "readtests-txt", "go-dev-homepage.diff.png"),
viewportWidth: 1536,
viewportHeight: 960,
@ -54,8 +54,8 @@ func TestReadTests(t *testing.T) {
name: "go.dev homepage 540x1080",
urlA: "https://go.dev/",
urlB: "http://localhost:6060/go.dev/",
outImgA: filepath.Join(cache, "readtests-txt", "go-dev-homepage-540x1080.go-dev.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "go-dev-homepage-540x1080.localhost-6060.b.png"),
outImgA: filepath.Join(cache, "readtests-txt", "go-dev-homepage-540x1080.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "go-dev-homepage-540x1080.b.png"),
outDiff: filepath.Join(cache, "readtests-txt", "go-dev-homepage-540x1080.diff.png"),
viewportWidth: 540,
viewportHeight: 1080,
@ -65,8 +65,8 @@ func TestReadTests(t *testing.T) {
name: "about page",
urlA: "https://go.dev/about",
urlB: "http://localhost:6060/go.dev/about",
outImgA: filepath.Join(cache, "readtests-txt", "about-page.go-dev.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "about-page.localhost-6060.b.png"),
outImgA: filepath.Join(cache, "readtests-txt", "about-page.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "about-page.b.png"),
outDiff: filepath.Join(cache, "readtests-txt", "about-page.diff.png"),
screenshotType: fullScreenshot,
viewportWidth: 1536,
@ -76,8 +76,8 @@ func TestReadTests(t *testing.T) {
name: "pkg.go.dev homepage .go-Carousel",
urlA: "https://pkg.go.dev/",
urlB: "https://beta.pkg.go.dev/",
outImgA: filepath.Join(cache, "readtests-txt", "pkg-go-dev-homepage--go-Carousel.pkg-go-dev.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "pkg-go-dev-homepage--go-Carousel.beta-pkg-go-dev.b.png"),
outImgA: filepath.Join(cache, "readtests-txt", "pkg-go-dev-homepage--go-Carousel.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "pkg-go-dev-homepage--go-Carousel.b.png"),
outDiff: filepath.Join(cache, "readtests-txt", "pkg-go-dev-homepage--go-Carousel.diff.png"),
screenshotType: elementScreenshot,
screenshotElement: ".go-Carousel",
@ -91,8 +91,8 @@ func TestReadTests(t *testing.T) {
name: "net package doc",
urlA: "https://pkg.go.dev/net",
urlB: "https://beta.pkg.go.dev/net",
outImgA: filepath.Join(cache, "readtests-txt", "net-package-doc.pkg-go-dev.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "net-package-doc.beta-pkg-go-dev.b.png"),
outImgA: filepath.Join(cache, "readtests-txt", "net-package-doc.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "net-package-doc.b.png"),
outDiff: filepath.Join(cache, "readtests-txt", "net-package-doc.diff.png"),
screenshotType: viewportScreenshot,
viewportWidth: 1536,
@ -105,8 +105,8 @@ func TestReadTests(t *testing.T) {
name: "net package doc 540x1080",
urlA: "https://pkg.go.dev/net",
urlB: "https://beta.pkg.go.dev/net",
outImgA: filepath.Join(cache, "readtests-txt", "net-package-doc-540x1080.pkg-go-dev.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "net-package-doc-540x1080.beta-pkg-go-dev.b.png"),
outImgA: filepath.Join(cache, "readtests-txt", "net-package-doc-540x1080.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "net-package-doc-540x1080.b.png"),
outDiff: filepath.Join(cache, "readtests-txt", "net-package-doc-540x1080.diff.png"),
screenshotType: viewportScreenshot,
viewportWidth: 540,
@ -121,8 +121,8 @@ func TestReadTests(t *testing.T) {
cacheA: true,
urlB: "http://localhost:8080/about",
headers: map[string]interface{}{"Authorization": "Bearer token"},
outImgA: filepath.Join(cache, "readtests-txt", "about.pkg-go-dev.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "about.localhost-8080.b.png"),
outImgA: filepath.Join(cache, "readtests-txt", "about.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "about.b.png"),
outDiff: filepath.Join(cache, "readtests-txt", "about.diff.png"),
screenshotType: viewportScreenshot,
viewportWidth: 1536,
@ -134,8 +134,8 @@ func TestReadTests(t *testing.T) {
cacheA: true,
urlB: "http://localhost:8080/eval",
headers: map[string]interface{}{"Authorization": "Bearer token"},
outImgA: filepath.Join(cache, "readtests-txt", "eval.pkg-go-dev.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "eval.localhost-8080.b.png"),
outImgA: filepath.Join(cache, "readtests-txt", "eval.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "eval.b.png"),
outDiff: filepath.Join(cache, "readtests-txt", "eval.diff.png"),
screenshotType: viewportScreenshot,
viewportWidth: 1536,
@ -151,8 +151,8 @@ func TestReadTests(t *testing.T) {
urlB: "http://localhost:8080/gcs-output",
gcsBucket: true,
headers: map[string]interface{}{"Authorization": "Bearer token"},
outImgA: "gs://bucket-name/gcs-output.pkg-go-dev.a.png",
outImgB: "gs://bucket-name/gcs-output.localhost-8080.b.png",
outImgA: "gs://bucket-name/gcs-output.a.png",
outImgB: "gs://bucket-name/gcs-output.b.png",
outDiff: "gs://bucket-name/gcs-output.diff.png",
screenshotType: viewportScreenshot,
viewportWidth: 1536,
@ -221,9 +221,9 @@ func TestCheckHandler(t *testing.T) {
},
wantErr: true,
wantFiles: []string{
filepath.Join(cache, "fail-txt", "homepage.a.png"),
filepath.Join(cache, "fail-txt", "homepage.b.png"),
filepath.Join(cache, "fail-txt", "homepage.diff.png"),
filepath.Join(cache, "fail-txt", "homepage.go-dev.a.png"),
filepath.Join(cache, "fail-txt", "homepage.pkg-go-dev.b.png"),
},
},
{
@ -233,8 +233,8 @@ func TestCheckHandler(t *testing.T) {
glob: "testdata/cached.txt",
},
wantFiles: []string{
filepath.Join("testdata", "screenshots", "cached", "homepage.go-dev.a.png"),
filepath.Join("testdata", "screenshots", "cached", "homepage.go-dev.b.png"),
filepath.Join("testdata", "screenshots", "cached", "homepage.a.png"),
filepath.Join("testdata", "screenshots", "cached", "homepage.b.png"),
},
},
}
@ -279,8 +279,8 @@ func TestHeaders(t *testing.T) {
cacheA: true,
urlB: "http://localhost:6061",
headers: map[string]interface{}{"Authorization": "Bearer token"},
outImgA: filepath.Join("testdata", "screenshots", "headers", "headers-test.localhost-6061.a.png"),
outImgB: filepath.Join("testdata", "screenshots", "headers", "headers-test.localhost-6061.b.png"),
outImgA: filepath.Join("testdata", "screenshots", "headers", "headers-test.a.png"),
outImgB: filepath.Join("testdata", "screenshots", "headers", "headers-test.b.png"),
outDiff: filepath.Join("testdata", "screenshots", "headers", "headers-test.diff.png"),
viewportWidth: 1536,
viewportHeight: 960,
@ -344,7 +344,7 @@ func Test_gcsParts(t *testing.T) {
}
func Test_cleanDirs(t *testing.T) {
f, err := os.Create("testdata/screenshots/cached/should-delete.go-dev.a.png")
f, err := os.Create("testdata/screenshots/cached/should-delete.a.png")
if err != nil {
t.Fatal(err)
}
@ -370,20 +370,18 @@ func Test_cleanDirs(t *testing.T) {
"testdata": true,
},
keepFiles: map[string]bool{
"testdata/screenshots/cached/homepage.go-dev.a.png": true,
"testdata/screenshots/cached/homepage.go-dev.b.png": true,
"testdata/screenshots/headers/headers-test.localhost-6061.a.png": true,
"testdata/screenshots/cached/homepage.a.png": true,
"testdata/screenshots/cached/homepage.b.png": true,
"testdata/screenshots/headers/headers-test.a.png": true,
},
safeExts: map[string]bool{
"go-dev.a.png": true,
"go-dev.b.png": true,
"localhost-6061.a.png": true,
"localhost-6061.b.png": true,
"a.png": true,
"b.png": true,
},
},
wantFiles: map[string]bool{
"testdata/screenshots/cached/homepage.go-dev.a.png": true,
"testdata/screenshots/headers/headers-test.localhost-6061.a.png": true,
"testdata/screenshots/cached/homepage.a.png": true,
"testdata/screenshots/headers/headers-test.a.png": true,
},
},
{
@ -393,7 +391,7 @@ func Test_cleanDirs(t *testing.T) {
"testdata": true,
},
safeExts: map[string]bool{
"go-dev.png": true,
"a.png": true,
},
},
wantFiles: map[string]bool{

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 151 KiB

После

Ширина:  |  Высота:  |  Размер: 151 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 151 KiB

После

Ширина:  |  Высота:  |  Размер: 151 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 1.5 KiB

После

Ширина:  |  Высота:  |  Размер: 1.5 KiB