本文整理汇总了Golang中github.com/alecthomas/assert.NoError函数的典型用法代码示例。如果您正苦于以下问题:Golang NoError函数的具体用法?Golang NoError怎么用?Golang NoError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NoError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: cpDir
func cpDir(t *testing.T, src string, dst string) {
assert.NoError(t, os.MkdirAll(dst, 0755))
assert.NoError(t, filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
assert.NoError(t, err)
name, fErr := filepath.Rel(src, path)
assert.NoError(t, fErr)
dstPath := filepath.Join(dst, name)
if info.IsDir() {
assert.NoError(t, os.MkdirAll(dstPath, info.Mode()))
} else if info.Mode()&os.ModeSymlink > 0 {
dest, fErr := os.Readlink(path)
assert.NoError(t, fErr)
assert.NoError(t, os.Symlink(dest, dstPath))
} else if info.Mode().IsRegular() {
df, fErr := os.OpenFile(dstPath, os.O_CREATE|os.O_WRONLY, info.Mode())
assert.NoError(t, fErr)
defer df.Close()
sf, fErr := os.Open(path)
assert.NoError(t, fErr)
defer sf.Close()
_, fErr = io.Copy(df, sf)
assert.NoError(t, fErr)
} else {
return fmt.Errorf("not regular, not symlink, not dir, what is it? %s", path)
}
return nil
}))
}
示例2: Test_CopyContainer
func Test_CopyContainer(t *testing.T) {
mainDir, err := ioutil.TempDir("", "copycontainer")
assert.NoError(t, err)
defer os.RemoveAll(mainDir)
src := path.Join(mainDir, "src")
dst := path.Join(mainDir, "dst")
makeTestDir(t, src, testDirSettings{
seed: 0x91738,
entries: []testDirEntry{
{path: "subdir/file-1", seed: 0x1},
{path: "file-1", seed: 0x2},
{path: "file-2", seed: 0x3},
},
})
container, err := tlc.WalkAny(src, nil)
assert.NoError(t, err)
inPool := fspool.New(container, src)
outPool := fspool.New(container, dst)
err = CopyContainer(container, outPool, inPool, &state.Consumer{})
assert.NoError(t, err)
assert.NoError(t, inPool.Close())
}
示例3: Test_OpenRemoteDownloadBuild
func Test_OpenRemoteDownloadBuild(t *testing.T) {
fakeData := []byte("aaaabbbb")
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("content-length", fmt.Sprintf("%d", len(fakeData)))
w.WriteHeader(200)
w.Write(fakeData)
}))
defer server.CloseClientConnections()
tfs := &testfs{server.URL}
assert.NoError(t, RegisterHandler(tfs))
assert.Error(t, RegisterHandler(tfs))
defer DeregisterHandler(tfs)
f, err := Open("nofs:///not-quite")
assert.Error(t, err)
f, err = Open("testfs:///now/we/are/talking")
assert.NoError(t, err)
stats, err := f.Stat()
assert.NoError(t, err)
assert.EqualValues(t, len(fakeData), stats.Size())
assert.NoError(t, f.Close())
}
示例4: TestParseTCPAddrList
func TestParseTCPAddrList(t *testing.T) {
p := parserMixin{}
_ = p.TCPList()
err := p.value.Set("127.0.0.1:1234")
assert.NoError(t, err)
err = p.value.Set("127.0.0.1:1235")
assert.NoError(t, err)
assert.Equal(t, "127.0.0.1:1234,127.0.0.1:1235", p.value.String())
}
示例5: TestParseTCPAddr
func TestParseTCPAddr(t *testing.T) {
p := parserMixin{}
v := p.TCP()
err := p.value.Set("127.0.0.1:1234")
assert.NoError(t, err)
expected, err := net.ResolveTCPAddr("tcp", "127.0.0.1:1234")
assert.NoError(t, err)
assert.Equal(t, *expected, **v)
}
示例6: Test_Writer
func Test_Writer(t *testing.T) {
dropSize := 16
numShort := 0
shortSize := 0
validate := func(buf []byte) error {
switch {
case len(buf) == dropSize:
if numShort > 0 {
return fmt.Errorf("got full after short")
}
return nil
case len(buf) < dropSize:
if numShort > 0 {
return fmt.Errorf("got second short (%d)", len(buf))
}
numShort++
shortSize = len(buf)
default:
return fmt.Errorf("drop too large (%d > %d)", len(buf), dropSize)
}
return nil
}
buf := make([]byte, dropSize)
countingWriter := counter.NewWriter(nil)
dw := &Writer{
Buffer: buf,
Validate: validate,
Writer: countingWriter,
}
rbuf := make([]byte, 128)
write := func(l int) {
written, wErr := dw.Write(rbuf[0:l])
assert.Equal(t, l, written)
assert.NoError(t, wErr)
}
write(12)
write(4)
write(10)
write(6)
write(16)
write(64)
write(5)
assert.NoError(t, dw.Close())
assert.Equal(t, 5, shortSize)
assert.Equal(t, int64(12+4+10+6+16+64+5), countingWriter.Count())
}
示例7: TestGetFlagAndOverrideDefault
func TestGetFlagAndOverrideDefault(t *testing.T) {
app := newTestApp()
a := app.Flag("a", "").Default("default").String()
_, err := app.Parse([]string{})
assert.NoError(t, err)
assert.Equal(t, "default", *a)
app.GetFlag("a").Default("new")
_, err = app.Parse([]string{})
assert.NoError(t, err)
assert.Equal(t, "new", *a)
}
示例8: Test_FanOut
func Test_FanOut(t *testing.T) {
t.Logf("Testing fail fast...")
ts := &TestSink{
FailingBlock: BlockLocation{
FileIndex: 2,
BlockIndex: 2,
},
}
fos, err := NewFanOutSink(ts, 8)
assert.NoError(t, err)
fos.Start()
hadError := false
for i := 0; i < 8; i++ {
for j := 0; j < 8; j++ {
loc := BlockLocation{
FileIndex: int64(i),
BlockIndex: int64(j),
}
sErr := fos.Store(loc, []byte{})
if sErr != nil {
hadError = true
}
}
}
assert.True(t, hadError)
err = fos.Close()
assert.NoError(t, err)
t.Logf("Testing tail errors...")
fos, err = NewFanOutSink(ts, 8)
assert.NoError(t, err)
fos.Start()
// Store shouldn't err, just queue it...
err = fos.Store(ts.FailingBlock, []byte{})
assert.NoError(t, err)
// but close should catch the error
err = fos.Close()
assert.NotNil(t, err)
}
示例9: TestNestedCommandsWithFlags
func TestNestedCommandsWithFlags(t *testing.T) {
app := New("app", "")
cmd := app.Command("a", "").Command("b", "")
a := cmd.Flag("aaa", "").Short('a').String()
b := cmd.Flag("bbb", "").Short('b').String()
err := app.init()
assert.NoError(t, err)
context := tokenize(strings.Split("a b --aaa x -b x", " "), false)
selected, err := parseAndExecute(app, context)
assert.NoError(t, err)
assert.True(t, context.EOL())
assert.Equal(t, "a b", selected)
assert.Equal(t, "x", *a)
assert.Equal(t, "x", *b)
}
示例10: TestCommander
func TestCommander(t *testing.T) {
c := newTestApp()
ping := c.Command("ping", "Ping an IP address.")
pingTTL := ping.Flag("ttl", "TTL for ICMP packets").Short('t').Default("5s").Duration()
selected, err := c.Parse([]string{"ping"})
assert.NoError(t, err)
assert.Equal(t, "ping", selected)
assert.Equal(t, 5*time.Second, *pingTTL)
selected, err = c.Parse([]string{"ping", "--ttl=10s"})
assert.NoError(t, err)
assert.Equal(t, "ping", selected)
assert.Equal(t, 10*time.Second, *pingTTL)
}
示例11: cpFile
func cpFile(t *testing.T, src string, dst string) {
sf, fErr := os.Open(src)
assert.NoError(t, fErr)
defer sf.Close()
info, fErr := sf.Stat()
assert.NoError(t, fErr)
df, fErr := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY, info.Mode())
assert.NoError(t, fErr)
defer df.Close()
_, fErr = io.Copy(df, sf)
assert.NoError(t, fErr)
}
示例12: TestTooManyArgsAfterCommand
func TestTooManyArgsAfterCommand(t *testing.T) {
a := newTestApp()
a.Command("a", "")
assert.NoError(t, a.init())
_, err := a.Parse([]string{"a", "b"})
assert.Error(t, err)
}
示例13: TestParserExpandFromFile
func TestParserExpandFromFile(t *testing.T) {
f, err := ioutil.TempFile("", "")
assert.NoError(t, err)
defer os.Remove(f.Name())
f.WriteString("hello\nworld\n")
f.Close()
app := New("test", "")
arg0 := app.Arg("arg0", "").String()
arg1 := app.Arg("arg1", "").String()
_, err = app.Parse([]string{"@" + f.Name()})
assert.NoError(t, err)
assert.Equal(t, "hello", *arg0)
assert.Equal(t, "world", *arg1)
}
示例14: TestFloat32
func TestFloat32(t *testing.T) {
p := parserMixin{}
v := p.Float32()
err := p.value.Set("123.45")
assert.NoError(t, err)
assert.InEpsilon(t, 123.45, *v, 0.001)
}
示例15: TestCounter
func TestCounter(t *testing.T) {
app := New("", "")
c := app.Flag("f", "").Counter()
_, err := app.Parse([]string{"--f", "--f", "--f"})
assert.NoError(t, err)
assert.Equal(t, 3, *c)
}