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"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"sync"
@ -15,10 +14,7 @@ import (
tassert "github.com/stretchr/testify/assert"
"oss.terrastruct.com/util-go/cmdlog"
"oss.terrastruct.com/util-go/xos"
"oss.terrastruct.com/util-go/xmain"
"oss.terrastruct.com/d2/lib/log"
)
//go:embed test_png.png
@ -53,7 +49,7 @@ func TestRegex(t *testing.T) {
func TestInlineRemote(t *testing.T) {
imgCache = sync.Map{}
ctx := context.Background()
ctx := log.WithTB(context.Background(), t, nil)
svgURL := "https://icons.terrastruct.com/essentials/004-picture.svg"
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>
`, 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 {
respRecorder := httptest.NewRecorder()
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) {
imgCache = sync.Map{}
ctx := context.Background()
ctx := log.WithTB(context.Background(), t, nil)
svgURL, err := filepath.Abs("./test_svg.svg")
if err != nil {
t.Fatal(err)
@ -205,16 +190,6 @@ width="328" height="587" viewBox="-100 -131 328 587"><style type="text/css">
}]]></style></svg>
`, 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)
if err != nil {
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
func TestDuplicateURL(t *testing.T) {
imgCache = sync.Map{}
ctx := context.Background()
ctx := log.WithTB(context.Background(), t, nil)
url1 := "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>
`, 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
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) {
imgCache = sync.Map{}
ctx := context.Background()
ctx := log.WithTB(context.Background(), t, nil)
url1 := "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>
`, 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
httpClient.Transport = roundTripFunc(func(req *http.Request) *http.Response {