diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2025-11-17 08:03:25 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2025-11-17 08:54:02 +0000 |
| commit | dc0208ace3f6b22d70ffc54092feec2ea83c7e20 (patch) | |
| tree | ebddae7184cc0df43db3a363729863aac0cc5dc6 /pkg/osutil/osutil_test.go | |
| parent | f7988ea4935e2627f33bc73cf235f2c1942dce76 (diff) | |
pkg/osutil: add Read/ParseJSON functions
Diffstat (limited to 'pkg/osutil/osutil_test.go')
| -rw-r--r-- | pkg/osutil/osutil_test.go | 21 |
1 files changed, 21 insertions, 0 deletions
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) + } +} |
