本文整理汇总了Golang中gx/ipfs/QmZwjfAKWe7vWZ8f48u7AGA1xYfzR1iCD9A2XSCYFRBWot/testify/assert.NoError函数的典型用法代码示例。如果您正苦于以下问题:Golang NoError函数的具体用法?Golang NoError怎么用?Golang NoError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NoError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
示例2: 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())
}
示例3: TestParseBase2Bytes
func TestParseBase2Bytes(t *testing.T) {
n, err := ParseBase2Bytes("0B")
assert.NoError(t, err)
assert.Equal(t, 0, n)
n, err = ParseBase2Bytes("1KB")
assert.NoError(t, err)
assert.Equal(t, 1024, n)
n, err = ParseBase2Bytes("1MB1KB25B")
assert.NoError(t, err)
assert.Equal(t, 1049625, n)
n, err = ParseBase2Bytes("1.5MB")
assert.NoError(t, err)
assert.Equal(t, 1572864, n)
}
示例4: TestParseMetricBytes
func TestParseMetricBytes(t *testing.T) {
n, err := ParseMetricBytes("0B")
assert.NoError(t, err)
assert.Equal(t, 0, n)
n, err = ParseMetricBytes("1KB1B")
assert.NoError(t, err)
assert.Equal(t, 1001, n)
n, err = ParseMetricBytes("1MB1KB25B")
assert.NoError(t, err)
assert.Equal(t, 1001025, n)
n, err = ParseMetricBytes("1.5MB")
assert.NoError(t, err)
assert.Equal(t, 1500000, n)
}
示例5: 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", " "))
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)
}
示例6: TestCommander
func TestCommander(t *testing.T) {
c := New("test", "test")
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)
}
示例7: TestBool
func TestBool(t *testing.T) {
app := New("test", "")
b := app.Flag("b", "").Bool()
_, err := app.Parse([]string{"--b"})
assert.NoError(t, err)
assert.True(t, *b)
}
示例8: TestShortFlag
func TestShortFlag(t *testing.T) {
app := New("test", "")
f := app.Flag("long", "").Short('s').Bool()
_, err := app.Parse([]string{"-s"})
assert.NoError(t, err)
assert.True(t, *f)
}
示例9: 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)
}
示例10: TestTopLevelArgWorks
func TestTopLevelArgWorks(t *testing.T) {
c := New("test", "test")
s := c.Arg("arg", "help").String()
_, err := c.Parse([]string{"foo"})
assert.NoError(t, err)
assert.Equal(t, "foo", *s)
}
示例11: TestCombinedShortFlagArg
func TestCombinedShortFlagArg(t *testing.T) {
a := New("test", "")
n := a.Flag("short", "").Short('s').Int()
_, err := a.Parse([]string{"-s10"})
assert.NoError(t, err)
assert.Equal(t, 10, *n)
}
示例12: 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)
}
示例13: TestTooManyArgsAfterCommand
func TestTooManyArgsAfterCommand(t *testing.T) {
a := New("test", "test")
a.Command("a", "")
assert.NoError(t, a.init())
_, err := a.Parse([]string{"a", "b"})
assert.Error(t, err)
}
示例14: TestNestedCommandWithMergedFlags
func TestNestedCommandWithMergedFlags(t *testing.T) {
app := New("app", "")
cmd0 := app.Command("a", "")
cmd0f0 := cmd0.Flag("aflag", "").Bool()
// cmd1 := app.Command("b", "")
// cmd1f0 := cmd0.Flag("bflag", "").Bool()
cmd00 := cmd0.Command("aa", "")
cmd00f0 := cmd00.Flag("aaflag", "").Bool()
err := app.init()
assert.NoError(t, err)
context := tokenize(strings.Split("a aa --aflag --aaflag", " "))
selected, err := parseAndExecute(app, context)
assert.NoError(t, err)
assert.True(t, *cmd0f0)
assert.True(t, *cmd00f0)
assert.Equal(t, "a aa", selected)
}
示例15: TestSelectedCommand
func TestSelectedCommand(t *testing.T) {
app := New("test", "help")
c0 := app.Command("c0", "")
c0.Command("c1", "")
s, err := app.Parse([]string{"c0", "c1"})
assert.NoError(t, err)
assert.Equal(t, "c0 c1", s)
}