本文整理汇总了Golang中github.com/alecthomas/assert.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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())
}
示例2: Test_NewHealer
func Test_NewHealer(t *testing.T) {
_, err := NewHealer("", "/dev/null")
assert.Error(t, err)
_, err = NewHealer("nope,/dev/null", "invalid")
assert.Error(t, err)
healer, err := NewHealer("archive,/dev/null", "invalid")
assert.NoError(t, err)
_, ok := healer.(*ArchiveHealer)
assert.True(t, ok)
}
示例3: TestToOneWithError
func TestToOneWithError(t *testing.T) {
_, err := FromInts(1, 2).ToOneWithError()
assert.Error(t, err)
value, err := FromInts(3).ToOneWithError()
assert.NoError(t, err)
assert.Equal(t, 3, value)
}
示例4: 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)
}
示例5: TestSubCommandRequired
func TestSubCommandRequired(t *testing.T) {
app := newTestApp()
c0 := app.Command("c0", "")
c0.Command("c1", "")
_, err := app.Parse([]string{"c0"})
assert.Error(t, err)
}
示例6: TestTopLevelArgCantBeUsedWithCommands
func TestTopLevelArgCantBeUsedWithCommands(t *testing.T) {
c := newTestApp()
c.Arg("arg", "help").String()
c.Command("cmd", "help")
_, err := c.Parse([]string{})
assert.Error(t, err)
}
示例7: TestInvalidDefaultArgValueErrors
func TestInvalidDefaultArgValueErrors(t *testing.T) {
c := newTestApp()
cmd := c.Command("cmd", "cmd")
cmd.Arg("arg", "arg").Default("one").Int()
_, err := c.Parse([]string{"cmd"})
assert.Error(t, err)
}
示例8: TestDuplicateLongFlag
func TestDuplicateLongFlag(t *testing.T) {
app := newTestApp()
app.Flag("a", "").String()
app.Flag("a", "").String()
_, err := app.Parse([]string{})
assert.Error(t, err)
}
示例9: TestDuplicateAlias
func TestDuplicateAlias(t *testing.T) {
app := newTestApp()
app.Command("one", "")
app.Command("two", "").Alias("one")
_, err := app.Parse([]string{"one"})
assert.Error(t, err)
}
示例10: TestMultipleDefaultCommands
func TestMultipleDefaultCommands(t *testing.T) {
app := newTestApp()
app.Command("c0", "").Default()
app.Command("c1", "").Default()
_, err := app.Parse([]string{})
assert.Error(t, err)
}
示例11: TestNestedCommandWithDuplicateFlagErrors
func TestNestedCommandWithDuplicateFlagErrors(t *testing.T) {
app := New("app", "")
app.Flag("test", "").Bool()
app.Command("cmd0", "").Flag("test", "").Bool()
err := app.init()
assert.Error(t, err)
}
示例12: TestArgsRequiredAfterNonRequiredErrors
func TestArgsRequiredAfterNonRequiredErrors(t *testing.T) {
c := newTestApp()
cmd := c.Command("cmd", "")
cmd.Arg("a", "a").String()
cmd.Arg("b", "b").Required().String()
_, err := c.Parse([]string{"cmd"})
assert.Error(t, err)
}
示例13: TestArgMultipleRequired
func TestArgMultipleRequired(t *testing.T) {
terminated := false
app := New("test", "")
app.Version("0.0.0").Writer(ioutil.Discard)
app.Arg("a", "").Required().String()
app.Arg("b", "").Required().String()
app.Terminate(func(int) { terminated = true })
_, err := app.Parse([]string{})
assert.Error(t, err)
_, err = app.Parse([]string{"A"})
assert.Error(t, err)
_, err = app.Parse([]string{"A", "B"})
assert.NoError(t, err)
_, err = app.Parse([]string{"--version"})
assert.True(t, terminated)
}
示例14: TestRepeatableFlags
func TestRepeatableFlags(t *testing.T) {
c := newTestApp()
c.Flag("a", "a").String()
c.Flag("b", "b").Strings()
_, err := c.Parse([]string{"--a=foo", "--a=bar"})
assert.Error(t, err)
_, err = c.Parse([]string{"--b=foo", "--b=bar"})
assert.NoError(t, err)
}
示例15: TestEnum
func TestEnum(t *testing.T) {
app := New("", "")
a := app.Arg("a", "").Enum("one", "two", "three")
_, err := app.Parse([]string{"moo"})
assert.Error(t, err)
_, err = app.Parse([]string{"one"})
assert.NoError(t, err)
assert.Equal(t, "one", *a)
}