Пример #1
0
func brokenCallWriteFile(filename string, data []byte) error {
	f, err := mockOS.Create(filename)
	if err != nil {
		return err
	}
	defer errors.AppendCall(&err, f.Close)
	n, err := f.Write(data)
	if err == nil && n < len(data) {
		err = io.ErrShortWrite
	}
	return err
}
Пример #2
0
func ReinventTheIOUtil(filename string) (buf []byte, err error) {
	f, err := os.Open(filename)
	if err != nil {
		return nil, err
	}
	defer errors.AppendCall(&err, f.Close)

	buf, err = ioutil.ReadAll(f)
	if err != nil {
		return nil, err
	}
	return buf, nil
}