This PR adds integration tests for the ASCII renderer in d2renderers/d2ascii/
. The goal? Make sure we donβt accidentally break it while trying to be smart. Think of it as a safety net, like wearing a helmet while ASCII biking.
/claim #924
d2renderers/d2ascii/
β
), diamonds (β
), cylinders, hexagons, you name itd2target.Diagram
interface as the SVG rendererd2lib.Compile()
ascii_integration_test.go
.d2
files in testdata/
We have two types of tests working together:
d2ascii_test.go
)TestSortObjects()
- Object sorting logicTestGrid()
- Grid data structureTestDrawShapes()
- Individual shape drawing functionsascii_integration_test.go
).d2
files as inputCovers all this:
simple.d2
: Just a -> b
to keep it humblebike.d2
: ASCII bicycle with all the bells and whistlesshapes.d2
: Every shape we supporttest.d2
: Routing testexample.d2
: Your classic user-server-database setup.d2
files you drop into testdata/
going forwardRun all integration tests:
go test ./d2renderers/d2ascii/ -run TestIntegration -v
Check which tests were picked up:
go test ./d2renderers/d2ascii/ -run TestIntegration -v | grep "=== RUN"
Run just one test:
go test ./d2renderers/d2ascii/ -run TestIntegration/bike
# Create a new test file
echo "api -> database -> cache" > d2renderers/d2ascii/testdata/api.d2
# Generate golden output for it
TESTDATA_ACCEPT=1 go test ./d2renderers/d2ascii/ -run TestIntegration/api
# Check that it works
go test ./d2renderers/d2ascii/ -run TestIntegration/api
# When you know the output should change
TESTDATA_ACCEPT=1 go test ./d2renderers/d2ascii/ -run TestIntegration
=== RUN TestIntegration
=== RUN TestIntegration/simple
=== RUN TestIntegration/bike
=== RUN TestIntegration/shapes
=== RUN TestIntegration/test
=== RUN TestIntegration/example
--- PASS: TestIntegration (0.00s)
--- PASS: TestIntegration/simple (0.18s)
--- PASS: TestIntegration/bike (0.22s)
--- PASS: TestIntegration/shapes (0.21s)
--- PASS: TestIntegration/test (0.19s)
--- PASS: TestIntegration/example (0.20s)
PASS
--- FAIL: TestIntegration/bike (0.24s)
ascii_integration_test.go:103: unexpected error: diff:
--- expected/bike/ascii.exp.txt
+++ actual output
@@ -15,7 +15,7 @@
-βββ Front Wheel βββ
+### Front Wheel ###
.d2
files are auto-discoveredTESTDATA_ACCEPT=1
updates golden files as neededNo-Code Venture
@nocodeventure-nl
Terrastruct
@terrastruct