cleanup test logging

This commit is contained in:
Gavin Nishizawa 2023-10-19 16:15:08 -07:00
parent eba687fbbe
commit 0df39dbeea
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD

View file

@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
"sync" "sync"
@ -15,10 +14,7 @@ import (
tassert "github.com/stretchr/testify/assert" tassert "github.com/stretchr/testify/assert"
"oss.terrastruct.com/util-go/cmdlog" "oss.terrastruct.com/d2/lib/log"
"oss.terrastruct.com/util-go/xos"
"oss.terrastruct.com/util-go/xmain"
) )
//go:embed test_png.png //go:embed test_png.png
@ -53,7 +49,7 @@ func TestRegex(t *testing.T) {
func TestInlineRemote(t *testing.T) { func TestInlineRemote(t *testing.T) {
imgCache = sync.Map{} imgCache = sync.Map{}
ctx := context.Background() ctx := log.WithTB(context.Background(), t, nil)
svgURL := "https://icons.terrastruct.com/essentials/004-picture.svg" svgURL := "https://icons.terrastruct.com/essentials/004-picture.svg"
pngURL := "https://cdn4.iconfinder.com/data/icons/smart-phones-technologies/512/android-phone.png" pngURL := "https://cdn4.iconfinder.com/data/icons/smart-phones-technologies/512/android-phone.png"
@ -84,17 +80,6 @@ width="328" height="587" viewBox="-100 -131 328 587"><style type="text/css">
}]]></style></svg> }]]></style></svg>
`, svgURL, pngURL) `, svgURL, pngURL)
ms := &xmain.State{
Name: "test",
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
Env: xos.NewEnv(os.Environ()),
}
ms.Log = cmdlog.NewTB(ms.Env, t)
httpClient.Transport = roundTripFunc(func(req *http.Request) *http.Response { httpClient.Transport = roundTripFunc(func(req *http.Request) *http.Response {
respRecorder := httptest.NewRecorder() respRecorder := httptest.NewRecorder()
switch req.URL.String() { switch req.URL.String() {
@ -168,7 +153,7 @@ width="328" height="587" viewBox="-100 -131 328 587"><style type="text/css">
func TestInlineLocal(t *testing.T) { func TestInlineLocal(t *testing.T) {
imgCache = sync.Map{} imgCache = sync.Map{}
ctx := context.Background() ctx := log.WithTB(context.Background(), t, nil)
svgURL, err := filepath.Abs("./test_svg.svg") svgURL, err := filepath.Abs("./test_svg.svg")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -205,16 +190,6 @@ width="328" height="587" viewBox="-100 -131 328 587"><style type="text/css">
}]]></style></svg> }]]></style></svg>
`, svgURL, pngURL) `, svgURL, pngURL)
ms := &xmain.State{
Name: "test",
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
Env: xos.NewEnv(os.Environ()),
}
ms.Log = cmdlog.NewTB(ms.Env, t)
out, err := BundleLocal(ctx, []byte(sampleSVG), false) out, err := BundleLocal(ctx, []byte(sampleSVG), false)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -233,7 +208,7 @@ width="328" height="587" viewBox="-100 -131 328 587"><style type="text/css">
// TestDuplicateURL ensures that we don't fetch the same image twice // TestDuplicateURL ensures that we don't fetch the same image twice
func TestDuplicateURL(t *testing.T) { func TestDuplicateURL(t *testing.T) {
imgCache = sync.Map{} imgCache = sync.Map{}
ctx := context.Background() ctx := log.WithTB(context.Background(), t, nil)
url1 := "https://icons.terrastruct.com/essentials/004-picture.svg" url1 := "https://icons.terrastruct.com/essentials/004-picture.svg"
url2 := "https://icons.terrastruct.com/essentials/004-picture.svg" url2 := "https://icons.terrastruct.com/essentials/004-picture.svg"
@ -264,17 +239,6 @@ width="328" height="587" viewBox="-100 -131 328 587"><style type="text/css">
}]]></style></svg> }]]></style></svg>
`, url1, url2) `, url1, url2)
ms := &xmain.State{
Name: "test",
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
Env: xos.NewEnv(os.Environ()),
}
ms.Log = cmdlog.NewTB(ms.Env, t)
count := 0 count := 0
httpClient.Transport = roundTripFunc(func(req *http.Request) *http.Response { httpClient.Transport = roundTripFunc(func(req *http.Request) *http.Response {
@ -298,7 +262,7 @@ width="328" height="587" viewBox="-100 -131 328 587"><style type="text/css">
func TestImgCache(t *testing.T) { func TestImgCache(t *testing.T) {
imgCache = sync.Map{} imgCache = sync.Map{}
ctx := context.Background() ctx := log.WithTB(context.Background(), t, nil)
url1 := "https://icons.terrastruct.com/essentials/004-picture.svg" url1 := "https://icons.terrastruct.com/essentials/004-picture.svg"
url2 := "https://icons.terrastruct.com/essentials/004-picture.svg" url2 := "https://icons.terrastruct.com/essentials/004-picture.svg"
@ -329,17 +293,6 @@ width="328" height="587" viewBox="-100 -131 328 587"><style type="text/css">
}]]></style></svg> }]]></style></svg>
`, url1, url2) `, url1, url2)
ms := &xmain.State{
Name: "test",
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
Env: xos.NewEnv(os.Environ()),
}
ms.Log = cmdlog.NewTB(ms.Env, t)
count := 0 count := 0
httpClient.Transport = roundTripFunc(func(req *http.Request) *http.Response { httpClient.Transport = roundTripFunc(func(req *http.Request) *http.Response {