core/json/io_test.go

37 lines
523 B
Go
Raw Permalink Normal View History

2024-01-01 16:55:54 +00:00
package json
import (
"os"
"testing"
"git.twelvetwelve.org/library/core/testutil/assert"
)
type testIoStruct struct {
Value string
Count int
}
func TestIo(t *testing.T) {
tmpFile := "io_test.tmp"
v := testIoStruct{
Value: "test",
Count: 999,
}
defer os.Remove(tmpFile)
err := ReadFromFile(tmpFile, &v)
assert.NotNil(t, err)
err = WriteToFile(tmpFile, &v, 0644)
assert.NoError(t, err)
read := testIoStruct{}
err = ReadFromFile(tmpFile, &read)
assert.NoError(t, err)
assert.Equal(t, v, read)
}