本文整理汇总了Golang中github.com/stretchrcom/testify/assert.NoError函数的典型用法代码示例。如果您正苦于以下问题:Golang NoError函数的具体用法?Golang NoError怎么用?Golang NoError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NoError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestChannelServerClose
func TestChannelServerClose(t *testing.T) {
sm, cm := newServerAndClient()
wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
c, err := sm.Accept()
assert.NoError(t, err)
if err != nil {
return
}
b := make([]byte, 4)
_, err = c.Read(b)
assert.NoError(t, err)
err = c.Close()
assert.NoError(t, err)
}()
c, err := cm.Dial()
assert.NoError(t, err)
_, err = c.Write([]byte("PING"))
assert.NoError(t, err)
b := make([]byte, 4)
_, err = c.Read(b)
assert.Equal(t, io.EOF, err)
wg.Wait()
}
示例2: TestBinaryEncodeComplex
func TestBinaryEncodeComplex(t *testing.T) {
b, err := Marshal(s1v)
assert.NoError(t, err)
assert.Equal(t, svb, b)
s := &s1{}
err = Unmarshal(svb, s)
assert.NoError(t, err)
assert.Equal(t, s1v, s)
}
示例3: TestParseTCPAddrList
func TestParseTCPAddrList(t *testing.T) {
p := parserMixin{}
v := 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", (*tcpAddrsValue)(v).String())
}
示例4: 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)
}
示例5: TestRequiredFlag
func TestRequiredFlag(t *testing.T) {
fg := newFlagGroup()
fg.Flag("a", "").Required().Bool()
assert.NoError(t, fg.init())
tokens := Tokenize([]string{"--a"})
tokens, err := fg.parse(tokens, false)
assert.NoError(t, err)
tokens = Tokenize([]string{})
tokens, err = fg.parse(tokens, false)
assert.Error(t, err)
}
示例6: TestTooManyArgs
func TestTooManyArgs(t *testing.T) {
a := New("test", "test")
a.Arg("a", "").String()
assert.NoError(t, a.init())
toks := Tokenize([]string{"a", "b"})
toks, _, err := a.parse(toks)
assert.NoError(t, err)
assert.Equal(t, tokens{&token{TokenArg, "b"}}, toks)
_, err = a.Parse([]string{"a", "b"})
assert.Error(t, err)
}
示例7: TestTooManyArgs
func TestTooManyArgs(t *testing.T) {
a := New("test", "test")
a.Arg("a", "").String()
assert.NoError(t, a.init())
context := Tokenize([]string{"a", "b"})
_, err := a.parse(context)
assert.NoError(t, err)
assert.Equal(t, Tokens{&Token{TokenArg, "b"}}, context.Tokens)
_, err = a.Parse([]string{"a", "b"})
assert.Error(t, err)
}
示例8: 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)
}
示例9: 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)
}
示例10: 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)
}
示例11: TestUnmarshalStringField
func TestUnmarshalStringField(t *testing.T) {
mE := MustNewMapping(&everythingComp{})
var s string
err := mE.UnmarshalField("Key", []byte("keyhere"), &s)
assert.NoError(t, err)
assert.Equal(t, s, "keyhere")
}
示例12: TestMarshalUnMarshalTypeAliases
func TestMarshalUnMarshalTypeAliases(t *testing.T) {
type Foo int64
f := Foo(32)
b, err := Marshal(f)
assert.NoError(t, err)
assert.Equal(t, []byte{0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, b)
}
示例13: 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)
}
示例14: TestUnmarshalIntField
func TestUnmarshalIntField(t *testing.T) {
mE := MustNewMapping(&tagsA{})
var i int
err := mE.UnmarshalField("B", []byte{0, 0, 0, 0, 0, 0, 0, 1}, &i)
assert.NoError(t, err)
assert.Equal(t, i, 1)
}
示例15: TestParseURL
func TestParseURL(t *testing.T) {
p := parserMixin{}
v := p.URL()
p.value.Set("http://w3.org")
u, err := url.Parse("http://w3.org")
assert.NoError(t, err)
assert.Equal(t, *u, **v)
}