本文整理汇总了Golang中github.com/docker/docker/pkg/testutil/assert.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestAutoAcceptOptionSetConflict
func TestAutoAcceptOptionSetConflict(t *testing.T) {
opt := NewAutoAcceptOption()
assert.NilError(t, opt.Set("manager"))
assert.Error(t, opt.Set("none"), "value NONE is incompatible with MANAGER")
opt = NewAutoAcceptOption()
assert.NilError(t, opt.Set("none"))
assert.Error(t, opt.Set("worker"), "value NONE is incompatible with WORKER")
}
示例2: TestAutoAcceptOptionSetConflict
func TestAutoAcceptOptionSetConflict(t *testing.T) {
opt := NewAutoAcceptOption()
assert.Error(t, opt.Set("none,manager"), "value NONE cannot be specified alongside other node types")
opt = NewAutoAcceptOption()
assert.Error(t, opt.Set("none,worker"), "value NONE cannot be specified alongside other node types")
opt = NewAutoAcceptOption()
assert.Error(t, opt.Set("worker,none,manager"), "value NONE cannot be specified alongside other node types")
opt = NewAutoAcceptOption()
assert.Error(t, opt.Set("worker,manager,none"), "value NONE cannot be specified alongside other node types")
}
示例3: TestExitStatusForInvalidSubcommandWithHelpFlag
func TestExitStatusForInvalidSubcommandWithHelpFlag(t *testing.T) {
discard := ioutil.Discard
cmd := newDockerCommand(command.NewDockerCli(os.Stdin, discard, discard))
cmd.SetArgs([]string{"help", "invalid"})
err := cmd.Execute()
assert.Error(t, err, "unknown help topic: invalid")
}
示例4: TestExternalCAOptionErrors
func TestExternalCAOptionErrors(t *testing.T) {
testCases := []struct {
externalCA string
expectedError string
}{
{
externalCA: "",
expectedError: "EOF",
},
{
externalCA: "anything",
expectedError: "invalid field 'anything' must be a key=value pair",
},
{
externalCA: "foo=bar",
expectedError: "the external-ca option needs a protocol= parameter",
},
{
externalCA: "protocol=baz",
expectedError: "unrecognized external CA protocol baz",
},
{
externalCA: "protocol=cfssl",
expectedError: "the external-ca option needs a url= parameter",
},
}
for _, tc := range testCases {
opt := &ExternalCAOption{}
assert.Error(t, opt.Set(tc.externalCA), tc.expectedError)
}
}
示例5: TestDaemonCommand
func TestDaemonCommand(t *testing.T) {
cmd := newDaemonCommand()
cmd.SetArgs([]string{"--help"})
err := cmd.Execute()
assert.Error(t, err, "Please run `dockerd`")
}
示例6: TestNodeRemoveErrors
func TestNodeRemoveErrors(t *testing.T) {
testCases := []struct {
args []string
nodeRemoveFunc func() error
expectedError string
}{
{
expectedError: "requires at least 1 argument",
},
{
args: []string{"nodeID"},
nodeRemoveFunc: func() error {
return fmt.Errorf("error removing the node")
},
expectedError: "error removing the node",
},
}
for _, tc := range testCases {
buf := new(bytes.Buffer)
cmd := newRemoveCommand(
test.NewFakeCli(&fakeClient{
nodeRemoveFunc: tc.nodeRemoveFunc,
}, buf))
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
assert.Error(t, cmd.Execute(), tc.expectedError)
}
}
示例7: TestSwarmLeaveErrors
func TestSwarmLeaveErrors(t *testing.T) {
testCases := []struct {
name string
args []string
swarmLeaveFunc func() error
expectedError string
}{
{
name: "too-many-args",
args: []string{"foo"},
expectedError: "accepts no argument(s)",
},
{
name: "leave-failed",
swarmLeaveFunc: func() error {
return fmt.Errorf("error leaving the swarm")
},
expectedError: "error leaving the swarm",
},
}
for _, tc := range testCases {
buf := new(bytes.Buffer)
cmd := newLeaveCommand(
test.NewFakeCli(&fakeClient{
swarmLeaveFunc: tc.swarmLeaveFunc,
}, buf))
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
assert.Error(t, cmd.Execute(), tc.expectedError)
}
}
示例8: TestConvertHealthcheckDisableWithTest
func TestConvertHealthcheckDisableWithTest(t *testing.T) {
source := &composetypes.HealthCheckConfig{
Disable: true,
Test: []string{"EXEC", "touch"},
}
_, err := convertHealthcheck(source)
assert.Error(t, err, "test and disable can't be set")
}
示例9: TestHealthCheckOptionsToHealthConfigConflict
func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) {
opt := healthCheckOptions{
cmd: "curl",
noHealthcheck: true,
}
_, err := opt.toHealthConfig()
assert.Error(t, err, "--no-healthcheck conflicts with --health-* options")
}
示例10: TestConvertVolumeToMountInvalidFormat
func TestConvertVolumeToMountInvalidFormat(t *testing.T) {
namespace := NewNamespace("foo")
invalids := []string{"::", "::cc", ":bb:", "aa::", "aa::cc", "aa:bb:", " : : ", " : :cc", " :bb: ", "aa: : ", "aa: :cc", "aa:bb: "}
for _, vol := range invalids {
_, err := convertVolumeToMount(vol, volumes{}, namespace)
assert.Error(t, err, "invalid volume: "+vol)
}
}
示例11: TestUpdateDNSConfig
func TestUpdateDNSConfig(t *testing.T) {
flags := newUpdateCommand(nil).Flags()
// IPv4, with duplicates
flags.Set("dns-add", "1.1.1.1")
flags.Set("dns-add", "1.1.1.1")
flags.Set("dns-add", "2.2.2.2")
flags.Set("dns-rm", "3.3.3.3")
flags.Set("dns-rm", "2.2.2.2")
// IPv6
flags.Set("dns-add", "2001:db8:abc8::1")
// Invalid dns record
assert.Error(t, flags.Set("dns-add", "x.y.z.w"), "x.y.z.w is not an ip address")
// domains with duplicates
flags.Set("dns-search-add", "example.com")
flags.Set("dns-search-add", "example.com")
flags.Set("dns-search-add", "example.org")
flags.Set("dns-search-rm", "example.org")
// Invalid dns search domain
assert.Error(t, flags.Set("dns-search-add", "example$com"), "example$com is not a valid domain")
flags.Set("dns-option-add", "ndots:9")
flags.Set("dns-option-rm", "timeout:3")
config := &swarm.DNSConfig{
Nameservers: []string{"3.3.3.3", "5.5.5.5"},
Search: []string{"localdomain"},
Options: []string{"timeout:3"},
}
updateDNSConfig(flags, &config)
assert.Equal(t, len(config.Nameservers), 3)
assert.Equal(t, config.Nameservers[0], "1.1.1.1")
assert.Equal(t, config.Nameservers[1], "2001:db8:abc8::1")
assert.Equal(t, config.Nameservers[2], "5.5.5.5")
assert.Equal(t, len(config.Search), 2)
assert.Equal(t, config.Search[0], "example.com")
assert.Equal(t, config.Search[1], "localdomain")
assert.Equal(t, len(config.Options), 1)
assert.Equal(t, config.Options[0], "ndots:9")
}
示例12: TestLoadFileSyntaxError
func TestLoadFileSyntaxError(t *testing.T) {
reader := strings.NewReader(`{
"Version": "0.1",
"Services": unquoted string
}`)
_, err := LoadFile(reader)
assert.Error(t, err, "syntax error at byte 37: invalid character 'u'")
}
示例13: TestNodeUpdateErrors
func TestNodeUpdateErrors(t *testing.T) {
testCases := []struct {
args []string
flags map[string]string
nodeInspectFunc func() (swarm.Node, []byte, error)
nodeUpdateFunc func(nodeID string, version swarm.Version, node swarm.NodeSpec) error
expectedError string
}{
{
expectedError: "requires exactly 1 argument",
},
{
args: []string{"node1", "node2"},
expectedError: "requires exactly 1 argument",
},
{
args: []string{"nodeID"},
nodeInspectFunc: func() (swarm.Node, []byte, error) {
return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node")
},
expectedError: "error inspecting the node",
},
{
args: []string{"nodeID"},
nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error {
return fmt.Errorf("error updating the node")
},
expectedError: "error updating the node",
},
{
args: []string{"nodeID"},
nodeInspectFunc: func() (swarm.Node, []byte, error) {
return *Node(NodeLabels(map[string]string{
"key": "value",
})), []byte{}, nil
},
flags: map[string]string{
"label-rm": "notpresent",
},
expectedError: "key notpresent doesn't exist in node's labels",
},
}
for _, tc := range testCases {
buf := new(bytes.Buffer)
cmd := newUpdateCommand(
test.NewFakeCli(&fakeClient{
nodeInspectFunc: tc.nodeInspectFunc,
nodeUpdateFunc: tc.nodeUpdateFunc,
}, buf))
cmd.SetArgs(tc.args)
for key, value := range tc.flags {
cmd.Flags().Set(key, value)
}
cmd.SetOutput(ioutil.Discard)
assert.Error(t, cmd.Execute(), tc.expectedError)
}
}
示例14: TestFindConfigurationConflicts
func TestFindConfigurationConflicts(t *testing.T) {
config := map[string]interface{}{"authorization-plugins": "foobar"}
flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
flags.String("authorization-plugins", "", "")
assert.NilError(t, flags.Set("authorization-plugins", "asdf"))
assert.Error(t,
findConfigurationConflicts(config, flags),
"authorization-plugins: (from flag: asdf, from file: foobar)")
}
示例15: TestContainersPruneError
func TestContainersPruneError(t *testing.T) {
client := &Client{
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
version: "1.25",
}
filters := filters.NewArgs()
_, err := client.ContainersPrune(context.Background(), filters)
assert.Error(t, err, "Error response from daemon: Server error")
}