internal/screentest: update screenshot extensions

The screenshot file extensions are updated such that
when the hostname of the origins for a testcase are
equal, for example when comparing cached screenshots
to live screenshots from the same server, the output
filenames do not collide.

Change-Id: I0b82f94d87912923e734fc30ba457a440ede94f4
Reviewed-on: https://go-review.googlesource.com/c/website/+/378476
Run-TryBot: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Jamal Carvalho <jamalcarvalho@google.com>
This commit is contained in:
Jamal Carvalho 2022-01-14 18:52:07 +00:00 коммит произвёл Jamal Carvalho
Родитель 5cf278daa6
Коммит 3bdafedcb3
7 изменённых файлов: 36 добавлений и 32 удалений

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

@ -561,8 +561,8 @@ func readTests(file string, vars map[string]string) ([]*testcase, error) {
if gcsBucket {
outfile = out + "/" + sanitized(test.name)
}
test.outImgA = outfile + "." + sanitized(urlA.Host) + ".png"
test.outImgB = outfile + "." + sanitized(urlB.Host) + ".png"
test.outImgA = outfile + "." + sanitized(urlA.Host) + ".a.png"
test.outImgB = outfile + "." + sanitized(urlB.Host) + ".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.png"),
outImgB: filepath.Join(cache, "readtests-txt", "go-dev-homepage.localhost-6060.png"),
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"),
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.png"),
outImgB: filepath.Join(cache, "readtests-txt", "go-dev-homepage-540x1080.localhost-6060.png"),
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"),
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.png"),
outImgB: filepath.Join(cache, "readtests-txt", "about-page.localhost-6060.png"),
outImgA: filepath.Join(cache, "readtests-txt", "about-page.go-dev.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "about-page.localhost-6060.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.png"),
outImgB: filepath.Join(cache, "readtests-txt", "pkg-go-dev-homepage--go-Carousel.beta-pkg-go-dev.png"),
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"),
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.png"),
outImgB: filepath.Join(cache, "readtests-txt", "net-package-doc.beta-pkg-go-dev.png"),
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"),
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.png"),
outImgB: filepath.Join(cache, "readtests-txt", "net-package-doc-540x1080.beta-pkg-go-dev.png"),
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"),
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.png"),
outImgB: filepath.Join(cache, "readtests-txt", "about.localhost-8080.png"),
outImgA: filepath.Join(cache, "readtests-txt", "about.pkg-go-dev.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "about.localhost-8080.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.png"),
outImgB: filepath.Join(cache, "readtests-txt", "eval.localhost-8080.png"),
outImgA: filepath.Join(cache, "readtests-txt", "eval.pkg-go-dev.a.png"),
outImgB: filepath.Join(cache, "readtests-txt", "eval.localhost-8080.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.png",
outImgB: "gs://bucket-name/gcs-output.localhost-8080.png",
outImgA: "gs://bucket-name/gcs-output.pkg-go-dev.a.png",
outImgB: "gs://bucket-name/gcs-output.localhost-8080.b.png",
outDiff: "gs://bucket-name/gcs-output.diff.png",
screenshotType: viewportScreenshot,
viewportWidth: 1536,
@ -222,8 +222,8 @@ func TestCheckHandler(t *testing.T) {
wantErr: true,
wantFiles: []string{
filepath.Join(cache, "fail-txt", "homepage.diff.png"),
filepath.Join(cache, "fail-txt", "homepage.go-dev.png"),
filepath.Join(cache, "fail-txt", "homepage.pkg-go-dev.png"),
filepath.Join(cache, "fail-txt", "homepage.go-dev.a.png"),
filepath.Join(cache, "fail-txt", "homepage.pkg-go-dev.b.png"),
},
},
{
@ -233,7 +233,8 @@ func TestCheckHandler(t *testing.T) {
glob: "testdata/cached.txt",
},
wantFiles: []string{
filepath.Join("testdata", "screenshots", "cached", "homepage.go-dev.png"),
filepath.Join("testdata", "screenshots", "cached", "homepage.go-dev.a.png"),
filepath.Join("testdata", "screenshots", "cached", "homepage.go-dev.b.png"),
},
},
}
@ -278,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.png"),
outImgB: filepath.Join("testdata", "screenshots", "headers", "headers-test.localhost-6061.png"),
outImgA: filepath.Join("testdata", "screenshots", "headers", "headers-test.localhost-6061.a.png"),
outImgB: filepath.Join("testdata", "screenshots", "headers", "headers-test.localhost-6061.b.png"),
outDiff: filepath.Join("testdata", "screenshots", "headers", "headers-test.diff.png"),
viewportWidth: 1536,
viewportHeight: 960,
@ -343,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.png")
f, err := os.Create("testdata/screenshots/cached/should-delete.go-dev.a.png")
if err != nil {
t.Fatal(err)
}
@ -369,17 +370,20 @@ func Test_cleanDirs(t *testing.T) {
"testdata": true,
},
keepFiles: map[string]bool{
"testdata/screenshots/cached/homepage.go-dev.png": true,
"testdata/screenshots/headers/headers-test.localhost-6061.png": true,
"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,
},
safeExts: map[string]bool{
"go-dev.png": true,
"localhost-6061.png": true,
"go-dev.a.png": true,
"go-dev.b.png": true,
"localhost-6061.a.png": true,
"localhost-6061.b.png": true,
},
},
wantFiles: map[string]bool{
"testdata/screenshots/cached/homepage.go-dev.png": true,
"testdata/screenshots/headers/headers-test.localhost-6061.png": true,
"testdata/screenshots/cached/homepage.go-dev.a.png": true,
"testdata/screenshots/headers/headers-test.localhost-6061.a.png": true,
},
},
{

Двоичные данные
internal/screentest/testdata/screenshots/cached/homepage.go-dev.a.png поставляемый Normal file

Двоичный файл не отображается.

После

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

Двоичные данные
internal/screentest/testdata/screenshots/cached/homepage.go-dev.b.png поставляемый Normal file

Двоичный файл не отображается.

После

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

Двоичные данные
internal/screentest/testdata/screenshots/cached/homepage.go-dev.png поставляемый

Двоичный файл не отображается.

До

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

Двоичные данные
internal/screentest/testdata/screenshots/headers/headers-test.localhost-6061.a.png поставляемый Normal file

Двоичный файл не отображается.

После

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

Двоичные данные
internal/screentest/testdata/screenshots/headers/headers-test.localhost-6061.png поставляемый

Двоичный файл не отображается.

До

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