From 98cc60bfec78e3348cb5aae7939093a5c1ce4935 Mon Sep 17 00:00:00 2001 From: binjip978 Date: Tue, 17 Sep 2024 18:10:32 +0300 Subject: [PATCH] cmds/fmap: cleanup tests (#431) Signed-off-by: Siarhiej Siemianczuk --- cmds/fmap/fmap_test.go | 10 +++------- cmds/fmap/{ => testdata}/fake_test.flash | Bin 2 files changed, 3 insertions(+), 7 deletions(-) rename cmds/fmap/{ => testdata}/fake_test.flash (100%) diff --git a/cmds/fmap/fmap_test.go b/cmds/fmap/fmap_test.go index a3787279..743fe457 100644 --- a/cmds/fmap/fmap_test.go +++ b/cmds/fmap/fmap_test.go @@ -13,7 +13,7 @@ import ( "github.com/u-root/u-root/pkg/testutil" ) -const testFlash = "fake_test.flash" +const testFlash = "testdata/fake_test.flash" var tests = []struct { cmd string @@ -64,7 +64,7 @@ func TestFmap(t *testing.T) { } // Filter out null characters which may be present in fmap strings. - out = bytes.Replace(out, []byte{0}, []byte{}, -1) + out = bytes.ReplaceAll(out, []byte{0}, []byte{}) if string(out) != tt.out { t.Errorf("expected:\n%s\ngot:\n%s", tt.out, string(out)) } @@ -72,11 +72,7 @@ func TestFmap(t *testing.T) { } func TestJson(t *testing.T) { - tmpDir, err := os.MkdirTemp("", "fmap_json") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpDir) + tmpDir := t.TempDir() jsonFile := filepath.Join(tmpDir, "tmp.json") if err := testutil.Command(t, "jget", jsonFile, testFlash).Run(); err != nil { diff --git a/cmds/fmap/fake_test.flash b/cmds/fmap/testdata/fake_test.flash similarity index 100% rename from cmds/fmap/fake_test.flash rename to cmds/fmap/testdata/fake_test.flash