1 Star 0 Fork 21

blackvirus/Fyne

forked from Gitee 极速下载/Fyne 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
log_test.go 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
Andy Williams 提交于 2019-03-16 22:13 . Improve error handling (#152)
package fyne
import (
"bufio"
"bytes"
"errors"
"log"
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func bufferLog(t *testing.T, reason string, err error) []string {
buf := bytes.NewBuffer([]byte{})
write := bufio.NewWriter(buf)
log.SetOutput(write)
LogError(reason, err)
log.SetOutput(os.Stdout)
err = write.Flush()
if err != nil {
t.Error(err)
}
output := strings.TrimSpace(buf.String())
return strings.Split(output, "\n")
}
func TestLogError(t *testing.T) {
err := errors.New("dummy error")
output := bufferLog(t, "Testing errors", err)
assert.Equal(t, 3, len(output))
assert.True(t, strings.Contains(output[0], "Testing errors"))
assert.True(t, strings.Contains(output[1], "Cause"))
assert.True(t, strings.Contains(output[1], "dummy"))
assert.True(t, strings.Contains(output[2], "At"))
}
func TestLogErrorNoErr(t *testing.T) {
output := bufferLog(t, "Testing errors", nil)
assert.Equal(t, 2, len(output))
assert.True(t, strings.Contains(output[0], "Testing errors"))
assert.True(t, strings.Contains(output[1], "At"))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/blackvirus/Fyne.git
[email protected]:blackvirus/Fyne.git
blackvirus
Fyne
Fyne
master

搜索帮助