我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何测试bytes.ErrTooLarge紧急错误

I want to simulate bytes.ErrTooLarge panic error on bytes.Buffer.Write method and test panic handling. I have tried to write unlimited data amount to exceed memory but then whole test crashed. What are the other options?

Sounds like a job for a mock object. Use this (badBuffer) in place of your bytes.Buffer during your test.

type badBuffer bytes.Buffer

func (b *badBuffer) Write(p []byte) (n int, err error) {
    panic(bytes.ErrTooLarge)
}

近期文章

  • Goio中使用ioutil.ReadAll()的“无效的内存地址”
  • 将本地结果分配给外部范围
  • 退出前如何确保goroutine完全运行
  • 解释方法表达式的打印值
  • 使用Go从字符串中删除所有文章和其他字符串?
  • 如何解析结构未知的嵌套json文件Golang
  • 为什么不按名称调用此String()方法
  • 如果content-length错误,Chrome将关闭tcp连接?
  • 检测进口包裹中的比赛状况
  • 混淆golang项目布局回购在实践中的工作方式
  • goapp测试无法正常工作,出现错误“ GOPATH必须是绝对的”
  • 是否有将包装拆分成模块化组件的标准做法?
  • 用Golang查询Postgres
  • Go项目的结构
  • 嵌套开关在golang中合法吗? [关闭]
  • 为什么GoConvey测试失败,错误代码为0? [关闭]
  • 从结构体内部的float32指针获取值?
  • Golang Switch变量范围
  • GO语言中的Lambda表达式[重复]
  • 如何与大猩猩Mux建立无状态连接?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华