From dc0208ace3f6b22d70ffc54092feec2ea83c7e20 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 17 Nov 2025 08:03:25 +0100 Subject: pkg/osutil: add Read/ParseJSON functions --- pkg/osutil/osutil_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'pkg/osutil/osutil_test.go') diff --git a/pkg/osutil/osutil_test.go b/pkg/osutil/osutil_test.go index 7d5913b4a..4d9bf4cf8 100644 --- a/pkg/osutil/osutil_test.go +++ b/pkg/osutil/osutil_test.go @@ -10,6 +10,8 @@ import ( "strings" "testing" "time" + + "github.com/google/go-cmp/cmp" ) func TestIsExist(t *testing.T) { @@ -129,3 +131,22 @@ func TestMonotonicNano(t *testing.T) { t.Fatalf("diff %v", diff) } } + +func TestReadWriteJSON(t *testing.T) { + type Test struct { + X int + Y string + } + test := Test{10, "foo"} + file := filepath.Join(t.TempDir(), "file") + if err := WriteJSON(file, test); err != nil { + t.Fatal(err) + } + test2, err := ReadJSON[Test](file) + if err != nil { + t.Fatal(err) + } + if diff := cmp.Diff(test, test2); diff != "" { + t.Fatal(diff) + } +} -- cgit mrf-deployment