Repository: tetratelabs/getenvoy
Pull request #237 (2021-05-25 08:45:11)

Simplifies code that adds user-agent
Signed-off-by: Adrian Cole <adrian@tetrate.io>


Patch:
diff --git a/internal/envoy/debug/admin.go b/internal/envoy/debug/admin.go
index ec2f120..d886b64 100644
--- a/internal/envoy/debug/admin.go
+++ b/internal/envoy/debug/admin.go
@@ -56,8 +56,8 @@ func (e *envoyAdminDataCollection) retrieveAdminAPIData() error {
 	for p, f := range adminAPIPaths {
 		url := fmt.Sprintf("http://%s/%v", adminAddress, p)
 		file := filepath.Join(e.workingDir, f)
-		if e := copyURLToFile(url, file); e != nil {
-			return e
+		if err := copyURLToFile(url, file); err != nil {
+			return err
 		}
 	}
 	return nil
diff --git a/internal/envoy/debug/node.go b/internal/envoy/debug/node.go
index 4d2b9f2..e67e77c 100644
--- a/internal/envoy/debug/node.go
+++ b/internal/envoy/debug/node.go
@@ -92,20 +92,19 @@ type proc struct {
 }
 
 // parseProcessTable returns processes that could be parsed and the first error
-func parseProcessTable(ctx context.Context, processes []*process.Process) ([]*proc, error) {
-	procs := make([]*proc, 0, len(processes))
-	var err error
+func parseProcessTable(ctx context.Context, processes []*process.Process) (procs []*proc, e error) {
+	procs = make([]*proc, 0, len(processes))
 	for _, p := range processes {
-		parsed, e := parseProc(ctx, p)
-		if e != nil { // Continue as the process could have died between the process listing and now.
-			if err == nil { // Capture only one error
-				err = e
+		parsed, err := parseProc(ctx, p)
+		if err != nil { // Continue as the process could have died between the process listing and now.
+			if e == nil { // Capture only one error
+				e = err
 			}
 			continue
 		}
 		procs = append(procs, parsed)
 	}
-	return procs, err
+	return
 }
 
 // parseProc returns a proc if there were no errors parsing its data
diff --git a/internal/envoy/http.go b/internal/envoy/http.go
new file mode 100644
index 0000000..23498a5
--- /dev/null
+++ b/internal/envoy/http.go
@@ -0,0 +1,35 @@
+// Copyright 2021 Tetrate
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package envoy
+
+import (
+	"fmt"
+	"net/http"
+
+	"github.com/tetratelabs/getenvoy/internal/version"
+)
+
+var userAgent = fmt.Sprintf("GetEnvoy/%s", version.GetEnvoy)
+
+// httpGet adds the "User-Agent" header to the request, so that we can tell what is a dev build vs release.
+func httpGet(url string) (*http.Response, error) {
+	// #nosec -> url can be anywhere by design
+	req, err := http.NewRequest("GET", url, nil)
+	if err != nil {
+		return nil, err
+	}
+	req.Header.Add("User-Agent", userAgent)
+	return http.DefaultClient.Do(req)
+}
diff --git a/internal/envoy/install.go b/internal/envoy/install.go
index 2716919..c8b05a8 100644
--- a/internal/envoy/install.go
+++ b/internal/envoy/install.go
@@ -25,7 +25,7 @@ import (
 
 	"github.com/tetratelabs/getenvoy/internal/globals"
 	"github.com/tetratelabs/getenvoy/internal/tar"
-	"github.com/tetratelabs/getenvoy/internal/transport"
+	"github.com/tetratelabs/getenvoy/internal/version"
 )
 
 const binEnvoy = "bin/envoy"
@@ -37,13 +37,14 @@ func InstallIfNeeded(o *globals.GlobalOpts, p, v string) (string, error) {
 	_, err := os.Stat(envoyPath)
 	switch {
 	case os.IsNotExist(err):
-		if e := os.MkdirAll(installPath, 0750); e != nil {
-			return "", fmt.Errorf("unable to create directory %q: %w", installPath, e)
+		if err = os.MkdirAll(installPath, 0750); err != nil {
+			return "", fmt.Errorf("unable to create directory %q: %w", installPath, err)
 		}
 
-		ev, e := GetEnvoyVersions(o.EnvoyVersionsURL)
-		if e != nil {
-			return "", e
+		var ev version.EnvoyVersions
+		ev, err = GetEnvoyVersions(o.EnvoyVersionsURL)
+		if err != nil {
+			return "", err
 		}
 
 		tarballURL := ev.Versions[v].Tarballs[p]
@@ -52,8 +53,8 @@ func InstallIfNeeded(o *globals.GlobalOpts, p, v string) (string, error) {
 		}
 
 		fmt.Fprintln(o.Out, "downloading", tarballURL) //nolint
-		if e := untarEnvoy(installPath, tarballURL, o.Out); e != nil {
-			return "", e
+		if err = untarEnvoy(installPath, tarballURL, o.Out); err != nil {
+			return "", err
 		}
 	case err == nil:
 		fmt.Fprintln(o.Out, v, "is already downloaded") //nolint
@@ -77,10 +78,9 @@ func verifyEnvoy(installPath string) (string, error) {
 }
 
 func untarEnvoy(dst, url string, out io.Writer) error { // dst, src order like io.Copy
-	// #nosec -> url can be anywhere by design
-	resp, e := transport.Get(url)
-	if e != nil {
-		return e
+	resp, err := httpGet(url)
+	if err != nil {
+		return err
 	}
 	defer resp.Body.Close() //nolint
 
@@ -92,8 +92,8 @@ func untarEnvoy(dst, url string, out io.Writer) error { // dst, src order like i
 	src := progressReader(out, resp.Body, resp.ContentLength)
 	defer src.Close() //nolint
 
-	if e = tar.Untar(dst, src); e != nil {
-		return fmt.Errorf("error untarring %s: %w", url, e)
+	if err = tar.Untar(dst, src); err != nil {
+		return fmt.Errorf("error untarring %s: %w", url, err)
 	}
 	return nil
 }
diff --git a/internal/envoy/run.go b/internal/envoy/run.go
index 3526f76..30313e6 100644
--- a/internal/envoy/run.go
+++ b/internal/envoy/run.go
@@ -52,8 +52,8 @@ func (r *Runtime) Run(ctx context.Context, args []string) (err error) {
 	}
 
 	// Print the process line to the console for user knowledge and parsing convenience
-	e := strings.Join(append([]string{r.opts.EnvoyPath}, args...), " ") // ensures no trailing space on empty args
-	fmt.Fprintln(r.Out, "starting:", e)                                 //nolint
+	a := strings.Join(append([]string{r.opts.EnvoyPath}, args...), " ") // ensures no trailing space on empty args
+	fmt.Fprintln(r.Out, "starting:", a)                                 //nolint
 	fmt.Fprintln(r.Out, "working directory:", cmd.Dir)                  //nolint
 	if err := cmd.Start(); err != nil {
 		return fmt.Errorf("unable to start Envoy process: %w", err)
diff --git a/internal/envoy/versions.go b/internal/envoy/versions.go
index bf7321d..fab6345 100644
--- a/internal/envoy/versions.go
+++ b/internal/envoy/versions.go
@@ -22,7 +22,6 @@ import (
 	"runtime"
 	"sort"
 
-	"github.com/tetratelabs/getenvoy/internal/transport"
 	"github.com/tetratelabs/getenvoy/internal/version"
 )
 
@@ -30,7 +29,7 @@ import (
 func GetEnvoyVersions(envoyVersionsURL string) (version.EnvoyVersions, error) {
 	result := version.EnvoyVersions{}
 	// #nosec => This is by design, users can call out to wherever they like!
-	resp, err := transport.Get(envoyVersionsURL)
+	resp, err := httpGet(envoyVersionsURL)
 	if err != nil {
 		return result, err
 	}
diff --git a/internal/tar/tar.go b/internal/tar/tar.go
index 44d4c23..6af9584 100644
--- a/internal/tar/tar.go
+++ b/internal/tar/tar.go
@@ -35,13 +35,13 @@ import (
 // To keep the binary size small, only supports compression formats used in practice. As of May 2021, all
 // "tarballURL" from stable releases were "tar.xz".
 func Untar(dst string, src io.Reader) error { // dst, src order like io.Copy
-	if e := os.MkdirAll(dst, 0750); e != nil {
-		return e
+	if err := os.MkdirAll(dst, 0750); err != nil {
+		return err
 	}
 
-	zSrc, e := newDecompressor(src)
-	if e != nil {
-		return e
+	zSrc, err := newDecompressor(src)
+	if err != nil {
+		return err
 	}
 	defer zSrc.Close() //nolint
 
@@ -64,14 +64,14 @@ func Untar(dst string, src io.Reader) error { // dst, src order like io.Copy
 		dstPath := filepath.Join(dst, srcPath)
 		info := header.FileInfo()
 		if info.IsDir() {
-			if e := os.MkdirAll(dstPath, info.Mode()); e != nil {
-				return e
+			if err := os.MkdirAll(dstPath, info.Mode()); err != nil {
+				return err
 			}
 			continue
 		}
 
-		if e := extractFile(dstPath, tr, info.Mode()); e != nil {
-			return e
+		if err := extractFile(dstPath, tr, info.Mode()); err != nil {
+			return err
 		}
 	}
 	return nil
@@ -85,8 +85,8 @@ func newDecompressor(r io.Reader) (io.ReadCloser, error) {
 		return nil, err
 	}
 	if xz.ValidHeader(h) {
-		xzr, e := xz.NewReader(br)
-		if e != nil {
+		xzr, err := xz.NewReader(br)
+		if err != nil {
 			return nil, err
 		}
 		return io.NopCloser(xzr), nil
diff --git a/internal/transport/client.go b/internal/transport/client.go
deleted file mode 100644
index 9103f43..0000000
--- a/internal/transport/client.go
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2020 Tetrate
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package transport
-
-import (
-	"fmt"
-	"net/http"
-
-	"github.com/tetratelabs/getenvoy/internal/version"
-)
-
-var (
-	cliUserAgent  = fmt.Sprintf("GetEnvoy/%s", version.GetEnvoy)
-	defaultClient = NewClient(AddUserAgent(cliUserAgent))
-)
-
-// Option represents an argument of NewClient
-type Option func(http.RoundTripper) http.RoundTripper
-
-// NewClient returns HTTP client for use of GetEnvoy CLI.
-func NewClient(opts ...Option) *http.Client {
-	tr := http.DefaultTransport
-	for _, opt := range opts {
-		tr = opt(tr)
-	}
-	client := &http.Client{Transport: tr}
-	return client
-}
-
-// AddUserAgent returns Option that adds passed user-agent to every requests.
-// It should be passed as an argument of NewClient.
-func AddUserAgent(ua string) Option {
-	return func(tr http.RoundTripper) http.RoundTripper {
-		return &funcTripper{roundTrip: func(r *http.Request) (*http.Response, error) {
-			r.Header.Add("User-Agent", ua)
-			return tr.RoundTrip(r)
-		}}
-	}
-}
-
-type funcTripper struct {
-	roundTrip func(*http.Request) (*http.Response, error)
-}
-
-func (f funcTripper) RoundTrip(r *http.Request) (*http.Response, error) {
-	return f.roundTrip(r)
-}
-
-// Get is thin wrapper of net/http.Get.
-func Get(url string) (*http.Response, error) {
-	return defaultClient.Get(url)
-}


Test patch:
diff --git a/e2e/command.go b/e2e/command.go
index cb09b5f..1a8f2f0 100644
--- a/e2e/command.go
+++ b/e2e/command.go
@@ -79,8 +79,8 @@ func (b *cmdBuilder) start(t *testing.T, terminateTimeout time.Duration) (io.Rea
 		require.NoError(t, err, `error terminating [%v]`, b.cmd)
 
 		select {
-		case e := <-errc:
-			require.NoError(t, e, `error running [%v]`, b.cmd)
+		case err := <-errc:
+			require.NoError(t, err, `error running [%v]`, b.cmd)
 		case <-time.After(terminateTimeout):
 			t.Fatal(fmt.Sprintf("getenvoy command didn't exit gracefully within %s", terminateTimeout))
 		}
diff --git a/e2e/getenvoy_run_test.go b/e2e/getenvoy_run_test.go
index 85b7dfb..7d32c61 100644
--- a/e2e/getenvoy_run_test.go
+++ b/e2e/getenvoy_run_test.go
@@ -86,8 +86,8 @@ func requireEnvoyReady(t *testing.T, envoyWorkingDir string, stderr io.Reader, c
 	envoyClient, err := newClient(string(adminAddress))
 	require.NoError(t, err, `error from envoy client %s after running [%v]`, adminAddress, c)
 	require.Eventually(t, func() bool {
-		ready, e := envoyClient.isReady()
-		return e == nil && ready
+		ready, err := envoyClient.isReady()
+		return err == nil && ready
 	}, 1*time.Minute, 100*time.Millisecond, `envoy client %s never ready after running [%v]`, adminAddress, c)
 
 	return envoyClient
@@ -101,8 +101,8 @@ func verifyDebugDump(t *testing.T, workingDir string, c interface{}) {
 
 	src, err := os.Open(runArchive)
 	require.NoError(t, err, "error opening %s after stopping [%v]", runArchive, c)
-	e := tar.Untar(workingDir, src)
-	require.NoError(t, e, "error restoring %s from %s after stopping [%v]", workingDir, runArchive, c)
+	err = tar.Untar(workingDir, src)
+	require.NoError(t, err, "error restoring %s from %s after stopping [%v]", workingDir, runArchive, c)
 
 	// ensure the minimum contents exist
 	for _, filename := range []string{"config_dump.json", "stats.json"} {
diff --git a/internal/cmd/app_test.go b/internal/cmd/app_test.go
index e66e51b..d557c8f 100644
--- a/internal/cmd/app_test.go
+++ b/internal/cmd/app_test.go
@@ -176,8 +176,8 @@ func requireSetenv(t *testing.T, key, value string) func() {
 	err := os.Setenv(key, value)
 	require.NoError(t, err, `error setting env variable %s=%s`, key, value)
 	return func() {
-		e := os.Setenv(key, previous)
-		require.NoError(t, e, `error reverting env variable %s=%s`, key, previous)
+		err := os.Setenv(key, previous)
+		require.NoError(t, err, `error reverting env variable %s=%s`, key, previous)
 	}
 }
 
diff --git a/internal/transport/client_test.go b/internal/envoy/http_test.go
similarity index 52%
rename from internal/transport/client_test.go
rename to internal/envoy/http_test.go
index 9561a6e..39ebb58 100644
--- a/internal/transport/client_test.go
+++ b/internal/envoy/http_test.go
@@ -12,44 +12,25 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package transport
+package envoy
 
 import (
-	"fmt"
 	"net/http"
 	"net/http/httptest"
-	"reflect"
 	"testing"
+
+	"github.com/stretchr/testify/require"
 )
 
-func TestClientWithoutRequest(t *testing.T) {
-	ua := fmt.Sprintf("GetEnvoy/%s", "1.0")
+func TestHttpGet_AddsUserAgent(t *testing.T) {
 	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-		want := http.Header{
-			"Accept-Encoding": []string{"gzip"},
-			"User-Agent":      []string{ua},
-		}
-		if !reflect.DeepEqual(r.Header, want) {
-			t.Errorf("Request.Header = %#v; want %#v", r.Header, want)
-		}
-		if t.Failed() {
-			w.Header().Set("Result", "got errors")
-		} else {
-			w.Header().Set("Result", "ok")
-		}
+		require.Equal(t, userAgent, r.UserAgent())
 	}))
 	defer ts.Close()
 
-	client := NewClient(AddUserAgent(ua))
-	res, err := client.Get(ts.URL)
-	if err != nil {
-		t.Fatal(err)
-	}
+	res, err := httpGet(ts.URL)
+	require.NoError(t, err)
+
 	defer res.Body.Close()
-	if res.StatusCode != 200 {
-		t.Fatal(res.Status)
-	}
-	if got := res.Header.Get("Result"); got != "ok" {
-		t.Errorf("result = %q; want ok", got)
-	}
+	require.Equal(t, 200, res.StatusCode)
 }
diff --git a/internal/envoy/install_test.go b/internal/envoy/install_test.go
index 0461e30..43e73ac 100644
--- a/internal/envoy/install_test.go
+++ b/internal/envoy/install_test.go
@@ -51,16 +51,16 @@ func TestUntarEnvoyError(t *testing.T) {
 
 	url := server.URL + "/file.tar.gz"
 	t.Run("error on incorrect URL", func(t *testing.T) {
-		e := untarEnvoy(dst, url, io.Discard)
-		require.EqualError(t, e, fmt.Sprintf(`received 404 status code from %s`, url))
+		err := untarEnvoy(dst, url, io.Discard)
+		require.EqualError(t, err, fmt.Sprintf(`received 404 status code from %s`, url))
 	})
 
 	realHandler = func(w http.ResponseWriter, _ *http.Request) {
 		w.WriteHeader(200)
 	}
 	t.Run("error on empty", func(t *testing.T) {
-		e := untarEnvoy(dst, url, io.Discard)
-		require.EqualError(t, e, fmt.Sprintf(`error untarring %s: EOF`, url))
+		err := untarEnvoy(dst, url, io.Discard)
+		require.EqualError(t, err, fmt.Sprintf(`error untarring %s: EOF`, url))
 	})
 
 	realHandler = func(w http.ResponseWriter, _ *http.Request) {
@@ -68,8 +68,8 @@ func TestUntarEnvoyError(t *testing.T) {
 		w.Write([]byte("mary had a little lamb")) //nolint
 	}
 	t.Run("error on not a tar", func(t *testing.T) {
-		e := untarEnvoy(dst, url, io.Discard)
-		require.EqualError(t, e, fmt.Sprintf(`error untarring %s: gzip: invalid header`, url))
+		err := untarEnvoy(dst, url, io.Discard)
+		require.EqualError(t, err, fmt.Sprintf(`error untarring %s: gzip: invalid header`, url))
 	})
 }
 
@@ -79,8 +79,8 @@ func TestUntarEnvoy(t *testing.T) {
 	defer cleanup()
 
 	out := new(bytes.Buffer)
-	e := untarEnvoy(o.tempDir, o.tarballURL, out)
-	require.NoError(t, e)
+	err := untarEnvoy(o.tempDir, o.tarballURL, out)
+	require.NoError(t, err)
 	require.FileExists(t, filepath.Join(o.tempDir, binEnvoy))
 	require.Contains(t, out.String(), `100% |████████████████████████████████████████|`)
 }
@@ -91,8 +91,8 @@ func TestInstallIfNeeded_ErrorOnIncorrectURL(t *testing.T) {
 
 	o.EnvoyVersionsURL += "/varsionz.json"
 
-	_, e := InstallIfNeeded(&o.GlobalOpts, runtime.GOOS, version.LastKnownEnvoy)
-	require.EqualError(t, e, "received 404 status code from "+o.EnvoyVersionsURL)
+	_, err := InstallIfNeeded(&o.GlobalOpts, runtime.GOOS, version.LastKnownEnvoy)
+	require.EqualError(t, err, "received 404 status code from "+o.EnvoyVersionsURL)
 	require.Empty(t, o.Out.(*bytes.Buffer))
 }
 
diff --git a/internal/tar/tar_test.go b/internal/tar/tar_test.go
index 729ffca..d0414cc 100644
--- a/internal/tar/tar_test.go
+++ b/internal/tar/tar_test.go
@@ -55,8 +55,8 @@ func TestNewDecompressor_Validates(t *testing.T) {
 	for _, tt := range tests {
 		tc := tt
 		t.Run(tc.name, func(t *testing.T) {
-			_, e := newDecompressor(bytes.NewReader(tc.junk))
-			require.EqualError(t, e, tc.expectedErr)
+			_, err := newDecompressor(bytes.NewReader(tc.junk))
+			require.EqualError(t, err, tc.expectedErr)
 		})
 	}
 }
@@ -75,19 +75,19 @@ func TestNewDecompressor(t *testing.T) {
 	} {
 		p := p
 		t.Run(p, func(t *testing.T) {
-			f, e := os.Open(p)
-			require.NoError(t, e)
+			f, err := os.Open(p)
+			require.NoError(t, err)
 			defer f.Close()
 
-			want, e := os.ReadFile(strings.TrimSuffix(p, path.Ext(p)))
-			require.NoError(t, e)
+			want, err := os.ReadFile(strings.TrimSuffix(p, path.Ext(p)))
+			require.NoError(t, err)
 
-			d, e := newDecompressor(f)
-			require.NoError(t, e)
+			d, err := newDecompressor(f)
+			require.NoError(t, err)
 			defer d.Close()
 
-			have, e := io.ReadAll(d)
-			require.NoError(t, e)
+			have, err := io.ReadAll(d)
+			require.NoError(t, err)
 
 			require.Equal(t, want, have)
 		})
@@ -114,12 +114,12 @@ func TestUntar(t *testing.T) {
 			if tt.emptyTar {
 				srcFile = filepath.Join("testdata", "empty.tar.xz")
 			}
-			f, e := os.Open(srcFile)
-			require.NoError(t, e)
+			f, err := os.Open(srcFile)
+			require.NoError(t, err)
 			defer f.Close()
 
-			e = Untar(dst, f)
-			require.NoError(t, e)
+			err = Untar(dst, f)
+			require.NoError(t, err)
 
 			if tt.emptyTar {
 				requireEmptyDirectory(t, dst)
diff --git a/internal/test/envoy.go b/internal/test/envoy.go
index 277146b..a1240aa 100644
--- a/internal/test/envoy.go
+++ b/internal/test/envoy.go
@@ -40,8 +40,8 @@ func RequireRunTerminate(t *testing.T, terminate func(), r Runner, stderr io.Rea
 
 	reader := bufio.NewReader(stderr)
 	require.Eventually(t, func() bool {
-		b, e := reader.Peek(512)
-		return e != nil && strings.Contains(string(b), "started\n")
+		b, err := reader.Peek(512)
+		return err != nil && strings.Contains(string(b), "started\n")
 	}, 2*time.Second, 100*time.Millisecond, "never started process")
 
 	terminate()
diff --git a/internal/test/server.go b/internal/test/server.go
index cde5568..9f42ca0 100644
--- a/internal/test/server.go
+++ b/internal/test/server.go
@@ -82,8 +82,8 @@ func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		require.Regexpf(s.t, `^1\.[1-9][0-9]\.[0-9]+$`, v, "unsupported version in uri %q", subpath)
 
 		w.WriteHeader(http.StatusOK)
-		_, e := w.Write(requireFakeEnvoyTarGz(s.t, v))
-		require.NoError(s.t, e)
+		_, err := w.Write(requireFakeEnvoyTarGz(s.t, v))
+		require.NoError(s.t, err)
 	default:
 		w.WriteHeader(http.StatusNotFound)
 	}
@@ -115,14 +115,14 @@ echo >&2 envoy stderr
 
 	// tar.gz the platform dir
 	tempGz := filepath.Join(tempDir, "envoy.tar.gz")
-	e := tar.TarGz(tempGz, installDir)
-	require.NoError(t, e)
+	err := tar.TarGz(tempGz, installDir)
+	require.NoError(t, err)
 
 	// Read the tar.gz into a byte array. This allows the mock server to set content length correctly
-	f, e := os.Open(tempGz) //nolint:gosec
-	require.NoError(t, e)
+	f, err := os.Open(tempGz) //nolint:gosec
+	require.NoError(t, err)
 	defer f.Close() // nolint
-	b, e := io.ReadAll(f)
-	require.NoError(t, e)
+	b, err := io.ReadAll(f)
+	require.NoError(t, err)
 	return b
 }