本文整理汇总了Golang中github.com/stretchrcom/testify/assert.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestArgMultipleRequired
func TestArgMultipleRequired(t *testing.T) {
a := newArgGroup()
a.Arg("a", "").Required().String()
a.Arg("b", "").Required().String()
a.init()
_, err := a.parse(Tokenize([]string{}))
assert.Error(t, err)
_, err = a.parse(Tokenize([]string{"A"}))
assert.Error(t, err)
_, err = a.parse(Tokenize([]string{"A", "B"}))
assert.NoError(t, err)
}
示例2: TestPublish
func TestPublish(t *testing.T) {
// test nil event
exp := `[7,"http://example.com/api/test",null]`
comparePublish(t, exp, "http://example.com/api/test", nil)
// test simple event
exp = `[7,"http://example.com/api/testing:thing","this is an event"]`
comparePublish(t, exp, "http://example.com/api/testing:thing", "this is an event")
// test complex event
obj := testObj{"the test", 17.3, []int{1, 2, 3}}
exp = `[7,"http://www.example.com/doc#thing",{"name":"the test","value":17.3,"list":[1,2,3]}]`
comparePublish(t, exp, "http://www.example.com/doc#thing", obj)
// test with excludeMe
exp = `[7,"http://example.com/api/testing:thing","this is an event",true]`
comparePublish(t, exp, "http://example.com/api/testing:thing", "this is an event", true)
// test with exclude list
exp = `[7,"http://example.com/api/testing:thing","this is an event",["bob","john"]]`
comparePublish(t, exp, "http://example.com/api/testing:thing", "this is an event", []string{"bob", "john"})
// test with eligible list
exp = `[7,"http://example.com/api/testing:thing","this is an event",[],["sam","fred"]]`
comparePublish(t, exp, "http://example.com/api/testing:thing", "this is an event", []string{}, []string{"sam", "fred"})
// test bad uri
_, err := createPublish("asdfasdf", "bad uri")
assert.Error(t, err)
}
示例3: TestCall
func TestCall(t *testing.T) {
// zero call arguments
exp := `[2,"123456","http://example.com/testRPC"]`
compareCall(t, exp, "123456", "http://example.com/testRPC")
// nil call argument
exp = `[2,"654321","http://example.com/otherRPC",null]`
compareCall(t, exp, "654321", "http://example.com/otherRPC", nil)
// one call argument
exp = `[2,"a1b2c3d4","http://example.com/dosomething/rpc","call arg"]`
compareCall(t, exp, "a1b2c3d4", "http://example.com/dosomething/rpc", "call arg")
// more call arguments
exp = `[2,"abcdefg","http://example.com/rpc","arg1","arg2"]`
compareCall(t, exp, "abcdefg", "http://example.com/rpc", "arg1", "arg2")
// complex call argument
exp = `[2,"1234","http://example.com/rpc",{"name":"george","value":14.98,"list":[1,3,5]},"astring"]`
obj := testObj{Name: "george", Value: 14.98, List: []int{1, 3, 5}}
compareCall(t, exp, "1234", "http://example.com/rpc", obj, "astring")
// test bad uri
_, err := createCall("abcd", "httpnopenopenope")
assert.Error(t, err)
}
示例4: TestTopLevelArgCantBeUsedWithCommands
func TestTopLevelArgCantBeUsedWithCommands(t *testing.T) {
c := New("test", "test")
c.Arg("arg", "help").String()
c.Command("cmd", "help")
_, err := c.Parse([]string{})
assert.Error(t, err)
}
示例5: TestInvalidDefaultArgValueErrors
func TestInvalidDefaultArgValueErrors(t *testing.T) {
c := New("test", "test")
cmd := c.Command("cmd", "cmd")
cmd.Arg("arg", "arg").Default("one").Int()
_, err := c.Parse([]string{"cmd"})
assert.Error(t, err)
}
示例6: TestInvalidArgsDefaultCanBeOverridden
func TestInvalidArgsDefaultCanBeOverridden(t *testing.T) {
a := newArgGroup()
a.Arg("a", "").Default("invalid").Bool()
assert.NoError(t, a.init())
tokens := Tokenize([]string{})
_, err := a.parse(tokens)
assert.Error(t, err)
}
示例7: TestArgsRequiredAfterNonRequiredErrors
func TestArgsRequiredAfterNonRequiredErrors(t *testing.T) {
c := New("test", "test")
cmd := c.Command("cmd", "")
cmd.Arg("a", "a").String()
cmd.Arg("b", "b").Required().String()
_, err := c.Parse([]string{})
assert.Error(t, err)
}
示例8: TestBinaryDecodeToValueErrors
func TestBinaryDecodeToValueErrors(t *testing.T) {
b := []byte{1, 0, 0, 0}
var v uint32
err := Unmarshal(b, v)
assert.Error(t, err)
err = Unmarshal(b, &v)
assert.NoError(t, err)
assert.Equal(t, uint32(1), v)
}
示例9: TestInvalidFlagDefaultCanBeOverridden
func TestInvalidFlagDefaultCanBeOverridden(t *testing.T) {
fg := newFlagGroup()
f := fg.Flag("a", "").Default("invalid")
f.Bool()
assert.NoError(t, fg.init())
tokens := Tokenize([]string{})
_, err := fg.parse(tokens, false)
assert.Error(t, err)
}
示例10: TestParseExistingFile
func TestParseExistingFile(t *testing.T) {
p := parserMixin{}
v := p.ExistingFile()
err := p.value.Set("/etc/hosts")
assert.NoError(t, err)
assert.Equal(t, "/etc/hosts", *v)
err = p.value.Set("/etc/hostsDEFINITELYMISSING")
assert.Error(t, err)
}
示例11: TestNegateNonBool
func TestNegateNonBool(t *testing.T) {
fg := newFlagGroup()
f := fg.Flag("b", "")
f.Int()
fg.init()
tokens := Tokenize([]string{"--no-b"})
_, err := fg.parse(tokens, false)
assert.Error(t, err)
}
示例12: TestRequiredFlags
func TestRequiredFlags(t *testing.T) {
c := New("test", "test")
c.Flag("a", "a").String()
c.Flag("b", "b").Required().String()
_, err := c.Parse([]string{"--a=foo"})
assert.Error(t, err)
_, err = c.Parse([]string{"--b=foo"})
assert.NoError(t, err)
}
示例13: TestEvalBadExpr
func TestEvalBadExpr(t *testing.T) {
assert.Equal(t, 1, Init())
r, err := Eval("x+")
assert.Nil(t, r)
assert.Error(t, err)
assert.Panics(t, func() {
EvalOrDie("+1*(")
})
}
示例14: 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)
}
示例15: 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)
}