當前位置: 首頁>>代碼示例>>Golang>>正文


Golang assert.Error函數代碼示例

本文整理匯總了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)
}
開發者ID:jessereynolds,項目名稱:coco,代碼行數:13,代碼來源:args_test.go

示例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)
}
開發者ID:elimisteve,項目名稱:turnpike,代碼行數:30,代碼來源:wamp_test.go

示例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)
}
開發者ID:elimisteve,項目名稱:turnpike,代碼行數:26,代碼來源:wamp_test.go

示例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)
}
開發者ID:flyinprogrammer,項目名稱:ec2metaproxy,代碼行數:7,代碼來源:app_test.go

示例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)
}
開發者ID:flyinprogrammer,項目名稱:ec2metaproxy,代碼行數:7,代碼來源:app_test.go

示例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)
}
開發者ID:jessereynolds,項目名稱:coco,代碼行數:8,代碼來源:args_test.go

示例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)
}
開發者ID:flyinprogrammer,項目名稱:ec2metaproxy,代碼行數:8,代碼來源:app_test.go

示例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)
}
開發者ID:jmptrader,項目名稱:binary,代碼行數:9,代碼來源:binary_test.go

示例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)
}
開發者ID:jessereynolds,項目名稱:coco,代碼行數:9,代碼來源:flags_test.go

示例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)
}
開發者ID:jessereynolds,項目名稱:coco,代碼行數:9,代碼來源:parsers_test.go

示例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)
}
開發者ID:jessereynolds,項目名稱:coco,代碼行數:9,代碼來源:flags_test.go

示例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)
}
開發者ID:flyinprogrammer,項目名稱:ec2metaproxy,代碼行數:10,代碼來源:app_test.go

示例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*(")
	})
}
開發者ID:Gwill,項目名稱:go-R,代碼行數:10,代碼來源:eval_test.go

示例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)
}
開發者ID:flyinprogrammer,項目名稱:ec2metaproxy,代碼行數:11,代碼來源:app_test.go

示例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)
}
開發者ID:jessereynolds,項目名稱:coco,代碼行數:11,代碼來源:flags_test.go


注:本文中的github.com/stretchrcom/testify/assert.Error函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。