e2etests-cli: Add pad test and cleanup

This commit is contained in:
Anmol Sethi 2023-03-02 20:02:36 -08:00
parent 9227021bc9
commit eae8fdeb29
No known key found for this signature in database
GPG key ID: 25BC68888A99A8BA
5 changed files with 24 additions and 6 deletions

View file

@ -20,12 +20,22 @@ func TestCLI_E2E(t *testing.T) {
run func(t *testing.T, ctx context.Context, dir string, env *xos.Env)
}{
{
name: "hello_world",
name: "hello_world_png",
run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) {
assert.WriteFile(t, filepath.Join(dir, "hello-world.d2"), []byte(`x -> y`), 0644)
err := runTestMain(t, ctx, dir, env, "hello-world.d2", "hello-world.png")
writeFile(t, dir, "hello-world.d2", `x -> y`)
err := runTestMain(t, ctx, dir, env, "hello-world.d2", "hello-world.png")
assert.Success(t, err)
png := assert.ReadFile(t, filepath.Join(dir, "hello-world.png"))
png := readFile(t, dir, "hello-world.png")
assert.Testdata(t, ".png", png)
},
},
{
name: "hello_world_png_pad",
run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) {
writeFile(t, dir, "hello-world.d2", `x -> y`)
err := runTestMain(t, ctx, dir, env, "-pad 4000", "hello-world.d2", "hello-world.png")
assert.Success(t, err)
png := readFile(t, dir, "hello-world.png")
assert.Testdata(t, ".png", png)
},
},
@ -67,3 +77,13 @@ func runTestMain(tb testing.TB, ctx context.Context, dir string, env *xos.Env, a
defer tms.Cleanup(tb)
return tms.Wait(ctx)
}
func writeFile(tb testing.TB, dir, fp, data string) {
tb.Helper()
assert.WriteFile(tb, filepath.Join(dir, fp), []byte(data), 0644)
}
func readFile(tb testing.TB, dir, fp string) []byte {
tb.Helper()
return assert.ReadFile(tb, filepath.Join(dir, fp))
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

2
go.sum generated
View file

@ -277,8 +277,6 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g=
nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=
oss.terrastruct.com/util-go v0.0.0-20230301015829-35b30391c74d h1:+1Bp2bYA7bieedJuqbiwOLhnMs6GQQLB4sNX7BcDbSQ=
oss.terrastruct.com/util-go v0.0.0-20230301015829-35b30391c74d/go.mod h1:Fwy72FDIOOM4K8F96ScXkxHHppR1CPfUyo9+x9c1PBU=
oss.terrastruct.com/util-go v0.0.0-20230303033840-484c630faa46 h1:pVcaRgqhNDXtWlsHg1cAy7BRycDiOaAEBexCFgMyUxQ=
oss.terrastruct.com/util-go v0.0.0-20230303033840-484c630faa46/go.mod h1:Fwy72FDIOOM4K8F96ScXkxHHppR1CPfUyo9+x9c1PBU=
rsc.io/pdf v0.1.1 h1:k1MczvYDUvJBe93bYd7wrZLLUEcLZAuF824/I4e5Xr4=