diff options
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) + } +} |
