本文整理汇总了Golang中github.com/docker/docker/cli/internal/test.NewFakeCli函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFakeCli函数的具体用法?Golang NewFakeCli怎么用?Golang NewFakeCli使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFakeCli函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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)
}
}
开发者ID:docker,项目名称:docker,代码行数:28,代码来源:remove_test.go
示例2: 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)
}
}
开发者ID:docker,项目名称:docker,代码行数:31,代码来源:leave_test.go
示例3: TestSwarmLeave
func TestSwarmLeave(t *testing.T) {
buf := new(bytes.Buffer)
cmd := newLeaveCommand(
test.NewFakeCli(&fakeClient{}, buf))
assert.NilError(t, cmd.Execute())
assert.Equal(t, strings.TrimSpace(buf.String()), "Node left the swarm.")
}
开发者ID:docker,项目名称:docker,代码行数:7,代码来源:leave_test.go
示例4: 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)
}
}
开发者ID:docker,项目名称:docker,代码行数:57,代码来源:update_test.go
示例5: TestNodeListQuietShouldOnlyPrintIDs
func TestNodeListQuietShouldOnlyPrintIDs(t *testing.T) {
buf := new(bytes.Buffer)
cmd := newListCommand(
test.NewFakeCli(&fakeClient{
nodeListFunc: func() ([]swarm.Node, error) {
return []swarm.Node{
*Node(),
}, nil
},
}, buf))
cmd.Flags().Set("quiet", "true")
assert.NilError(t, cmd.Execute())
assert.Contains(t, buf.String(), "nodeID")
}
开发者ID:docker,项目名称:docker,代码行数:14,代码来源:list_test.go
示例6: TestNodePsErrors
func TestNodePsErrors(t *testing.T) {
testCases := []struct {
args []string
flags map[string]string
infoFunc func() (types.Info, error)
nodeInspectFunc func() (swarm.Node, []byte, error)
taskListFunc func(options types.TaskListOptions) ([]swarm.Task, error)
taskInspectFunc func(taskID string) (swarm.Task, []byte, error)
expectedError string
}{
{
infoFunc: func() (types.Info, error) {
return types.Info{}, fmt.Errorf("error asking for node info")
},
expectedError: "error asking for node info",
},
{
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"},
taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) {
return []swarm.Task{}, fmt.Errorf("error returning the task list")
},
expectedError: "error returning the task list",
},
}
for _, tc := range testCases {
buf := new(bytes.Buffer)
cmd := newPsCommand(
test.NewFakeCli(&fakeClient{
infoFunc: tc.infoFunc,
nodeInspectFunc: tc.nodeInspectFunc,
taskInspectFunc: tc.taskInspectFunc,
taskListFunc: tc.taskListFunc,
}, 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)
}
}
开发者ID:docker,项目名称:docker,代码行数:48,代码来源:ps_test.go
示例7: TestSwarmInit
func TestSwarmInit(t *testing.T) {
testCases := []struct {
name string
flags map[string]string
swarmInitFunc func() (string, error)
swarmInspectFunc func() (swarm.Swarm, error)
swarmGetUnlockKeyFunc func() (types.SwarmUnlockKeyResponse, error)
nodeInspectFunc func() (swarm.Node, []byte, error)
}{
{
name: "init",
swarmInitFunc: func() (string, error) {
return "nodeID", nil
},
},
{
name: "init-autolock",
flags: map[string]string{
flagAutolock: "true",
},
swarmInitFunc: func() (string, error) {
return "nodeID", nil
},
swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) {
return types.SwarmUnlockKeyResponse{
UnlockKey: "unlock-key",
}, nil
},
},
}
for _, tc := range testCases {
buf := new(bytes.Buffer)
cmd := newInitCommand(
test.NewFakeCli(&fakeClient{
swarmInitFunc: tc.swarmInitFunc,
swarmInspectFunc: tc.swarmInspectFunc,
swarmGetUnlockKeyFunc: tc.swarmGetUnlockKeyFunc,
nodeInspectFunc: tc.nodeInspectFunc,
}, buf))
for key, value := range tc.flags {
cmd.Flags().Set(key, value)
}
assert.NilError(t, cmd.Execute())
actual := buf.String()
expected := golden.Get(t, []byte(actual), fmt.Sprintf("init-%s.golden", tc.name))
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
}
}
开发者ID:docker,项目名称:docker,代码行数:48,代码来源:init_test.go
示例8: TestSwarmJoinErrors
func TestSwarmJoinErrors(t *testing.T) {
testCases := []struct {
name string
args []string
swarmJoinFunc func() error
infoFunc func() (types.Info, error)
expectedError string
}{
{
name: "not-enough-args",
expectedError: "requires exactly 1 argument",
},
{
name: "too-many-args",
args: []string{"remote1", "remote2"},
expectedError: "requires exactly 1 argument",
},
{
name: "join-failed",
args: []string{"remote"},
swarmJoinFunc: func() error {
return fmt.Errorf("error joining the swarm")
},
expectedError: "error joining the swarm",
},
{
name: "join-failed-on-init",
args: []string{"remote"},
infoFunc: func() (types.Info, error) {
return types.Info{}, fmt.Errorf("error asking for node info")
},
expectedError: "error asking for node info",
},
}
for _, tc := range testCases {
buf := new(bytes.Buffer)
cmd := newJoinCommand(
test.NewFakeCli(&fakeClient{
swarmJoinFunc: tc.swarmJoinFunc,
infoFunc: tc.infoFunc,
}, buf))
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
assert.Error(t, cmd.Execute(), tc.expectedError)
}
}
开发者ID:docker,项目名称:docker,代码行数:46,代码来源:join_test.go
示例9: TestNodeDemoteMultipleNode
func TestNodeDemoteMultipleNode(t *testing.T) {
buf := new(bytes.Buffer)
cmd := newDemoteCommand(
test.NewFakeCli(&fakeClient{
nodeInspectFunc: func() (swarm.Node, []byte, error) {
return *Node(Manager()), []byte{}, nil
},
nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error {
if node.Role != swarm.NodeRoleWorker {
return fmt.Errorf("expected role worker, got %s", node.Role)
}
return nil
},
}, buf))
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
assert.NilError(t, cmd.Execute())
}
开发者ID:docker,项目名称:docker,代码行数:17,代码来源:demote_test.go
示例10: TestSwarmJoin
func TestSwarmJoin(t *testing.T) {
testCases := []struct {
name string
infoFunc func() (types.Info, error)
expected string
}{
{
name: "join-as-manager",
infoFunc: func() (types.Info, error) {
return types.Info{
Swarm: swarm.Info{
ControlAvailable: true,
},
}, nil
},
expected: "This node joined a swarm as a manager.",
},
{
name: "join-as-worker",
infoFunc: func() (types.Info, error) {
return types.Info{
Swarm: swarm.Info{
ControlAvailable: false,
},
}, nil
},
expected: "This node joined a swarm as a worker.",
},
}
for _, tc := range testCases {
buf := new(bytes.Buffer)
cmd := newJoinCommand(
test.NewFakeCli(&fakeClient{
infoFunc: tc.infoFunc,
}, buf))
cmd.SetArgs([]string{"remote"})
assert.NilError(t, cmd.Execute())
assert.Equal(t, strings.TrimSpace(buf.String()), tc.expected)
}
}
开发者ID:docker,项目名称:docker,代码行数:40,代码来源:join_test.go
示例11: TestNodeInspectPretty
func TestNodeInspectPretty(t *testing.T) {
testCases := []struct {
name string
nodeInspectFunc func() (swarm.Node, []byte, error)
}{
{
name: "simple",
nodeInspectFunc: func() (swarm.Node, []byte, error) {
return *Node(NodeLabels(map[string]string{
"lbl1": "value1",
})), []byte{}, nil
},
},
{
name: "manager",
nodeInspectFunc: func() (swarm.Node, []byte, error) {
return *Node(Manager()), []byte{}, nil
},
},
{
name: "manager-leader",
nodeInspectFunc: func() (swarm.Node, []byte, error) {
return *Node(Manager(Leader())), []byte{}, nil
},
},
}
for _, tc := range testCases {
buf := new(bytes.Buffer)
cmd := newInspectCommand(
test.NewFakeCli(&fakeClient{
nodeInspectFunc: tc.nodeInspectFunc,
}, buf))
cmd.SetArgs([]string{"nodeID"})
cmd.Flags().Set("pretty", "true")
assert.NilError(t, cmd.Execute())
actual := buf.String()
expected := golden.Get(t, []byte(actual), fmt.Sprintf("node-inspect-pretty.%s.golden", tc.name))
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
}
}
开发者ID:docker,项目名称:docker,代码行数:40,代码来源:inspect_test.go
示例12: TestSwarmUnlock
func TestSwarmUnlock(t *testing.T) {
input := "unlockKey"
buf := new(bytes.Buffer)
dockerCli := test.NewFakeCli(&fakeClient{
infoFunc: func() (types.Info, error) {
return types.Info{
Swarm: swarm.Info{
LocalNodeState: swarm.LocalNodeStateLocked,
},
}, nil
},
swarmUnlockFunc: func(req swarm.UnlockRequest) error {
if req.UnlockKey != input {
return fmt.Errorf("Invalid unlock key")
}
return nil
},
}, buf)
dockerCli.SetIn(ioutil.NopCloser(strings.NewReader(input)))
cmd := newUnlockCommand(dockerCli)
assert.NilError(t, cmd.Execute())
}
开发者ID:docker,项目名称:docker,代码行数:22,代码来源:unlock_test.go
示例13: TestNodeListErrorOnAPIFailure
func TestNodeListErrorOnAPIFailure(t *testing.T) {
testCases := []struct {
nodeListFunc func() ([]swarm.Node, error)
infoFunc func() (types.Info, error)
expectedError string
}{
{
nodeListFunc: func() ([]swarm.Node, error) {
return []swarm.Node{}, fmt.Errorf("error listing nodes")
},
expectedError: "error listing nodes",
},
{
nodeListFunc: func() ([]swarm.Node, error) {
return []swarm.Node{
{
ID: "nodeID",
},
}, nil
},
infoFunc: func() (types.Info, error) {
return types.Info{}, fmt.Errorf("error asking for node info")
},
expectedError: "error asking for node info",
},
}
for _, tc := range testCases {
buf := new(bytes.Buffer)
cmd := newListCommand(
test.NewFakeCli(&fakeClient{
nodeListFunc: tc.nodeListFunc,
infoFunc: tc.infoFunc,
}, buf))
cmd.SetOutput(ioutil.Discard)
assert.Error(t, cmd.Execute(), tc.expectedError)
}
}
开发者ID:docker,项目名称:docker,代码行数:37,代码来源:list_test.go
示例14: TestNodeDemoteErrors
func TestNodeDemoteErrors(t *testing.T) {
testCases := []struct {
args []string
nodeInspectFunc func() (swarm.Node, []byte, error)
nodeUpdateFunc func(nodeID string, version swarm.Version, node swarm.NodeSpec) error
expectedError string
}{
{
expectedError: "requires at least 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",
},
}
for _, tc := range testCases {
buf := new(bytes.Buffer)
cmd := newDemoteCommand(
test.NewFakeCli(&fakeClient{
nodeInspectFunc: tc.nodeInspectFunc,
nodeUpdateFunc: tc.nodeUpdateFunc,
}, buf))
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
assert.Error(t, cmd.Execute(), tc.expectedError)
}
}
开发者ID:docker,项目名称:docker,代码行数:37,代码来源:demote_test.go
示例15: TestNodeList
func TestNodeList(t *testing.T) {
buf := new(bytes.Buffer)
cmd := newListCommand(
test.NewFakeCli(&fakeClient{
nodeListFunc: func() ([]swarm.Node, error) {
return []swarm.Node{
*Node(NodeID("nodeID1"), Hostname("nodeHostname1"), Manager(Leader())),
*Node(NodeID("nodeID2"), Hostname("nodeHostname2"), Manager()),
*Node(NodeID("nodeID3"), Hostname("nodeHostname3")),
}, nil
},
infoFunc: func() (types.Info, error) {
return types.Info{
Swarm: swarm.Info{
NodeID: "nodeID1",
},
}, nil
},
}, buf))
assert.NilError(t, cmd.Execute())
assert.Contains(t, buf.String(), `nodeID1 * nodeHostname1 Ready Active Leader`)
assert.Contains(t, buf.String(), `nodeID2 nodeHostname2 Ready Active Reachable`)
assert.Contains(t, buf.String(), `nodeID3 nodeHostname3 Ready Active`)
}
开发者ID:docker,项目名称:docker,代码行数:24,代码来源:list_test.go
示例16: TestNodeListContainsHostname
// Test case for #24090
func TestNodeListContainsHostname(t *testing.T) {
buf := new(bytes.Buffer)
cmd := newListCommand(test.NewFakeCli(&fakeClient{}, buf))
assert.NilError(t, cmd.Execute())
assert.Contains(t, buf.String(), "HOSTNAME")
}
开发者ID:docker,项目名称:docker,代码行数:7,代码来源:list_test.go
示例17: TestSwarmUnlockErrors
func TestSwarmUnlockErrors(t *testing.T) {
testCases := []struct {
name string
args []string
input string
swarmUnlockFunc func(req swarm.UnlockRequest) error
infoFunc func() (types.Info, error)
expectedError string
}{
{
name: "too-many-args",
args: []string{"foo"},
expectedError: "accepts no argument(s)",
},
{
name: "is-not-part-of-a-swarm",
infoFunc: func() (types.Info, error) {
return types.Info{
Swarm: swarm.Info{
LocalNodeState: swarm.LocalNodeStateInactive,
},
}, nil
},
expectedError: "This node is not part of a swarm",
},
{
name: "is-not-locked",
infoFunc: func() (types.Info, error) {
return types.Info{
Swarm: swarm.Info{
LocalNodeState: swarm.LocalNodeStateActive,
},
}, nil
},
expectedError: "Error: swarm is not locked",
},
{
name: "unlockrequest-failed",
infoFunc: func() (types.Info, error) {
return types.Info{
Swarm: swarm.Info{
LocalNodeState: swarm.LocalNodeStateLocked,
},
}, nil
},
swarmUnlockFunc: func(req swarm.UnlockRequest) error {
return fmt.Errorf("error unlocking the swarm")
},
expectedError: "error unlocking the swarm",
},
}
for _, tc := range testCases {
buf := new(bytes.Buffer)
cmd := newUnlockCommand(
test.NewFakeCli(&fakeClient{
infoFunc: tc.infoFunc,
swarmUnlockFunc: tc.swarmUnlockFunc,
}, buf))
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
assert.Error(t, cmd.Execute(), tc.expectedError)
}
}
开发者ID:docker,项目名称:docker,代码行数:63,代码来源:unlock_test.go
示例18: TestSwarmJoinTokenErrors
func TestSwarmJoinTokenErrors(t *testing.T) {
testCases := []struct {
name string
args []string
flags map[string]string
infoFunc func() (types.Info, error)
swarmInspectFunc func() (swarm.Swarm, error)
swarmUpdateFunc func(swarm swarm.Spec, flags swarm.UpdateFlags) error
nodeInspectFunc func() (swarm.Node, []byte, error)
expectedError string
}{
{
name: "not-enough-args",
expectedError: "requires exactly 1 argument",
},
{
name: "too-many-args",
args: []string{"worker", "manager"},
expectedError: "requires exactly 1 argument",
},
{
name: "invalid-args",
args: []string{"foo"},
expectedError: "unknown role foo",
},
{
name: "swarm-inspect-failed",
args: []string{"worker"},
swarmInspectFunc: func() (swarm.Swarm, error) {
return swarm.Swarm{}, fmt.Errorf("error inspecting the swarm")
},
expectedError: "error inspecting the swarm",
},
{
name: "swarm-inspect-rotate-failed",
args: []string{"worker"},
flags: map[string]string{
flagRotate: "true",
},
swarmInspectFunc: func() (swarm.Swarm, error) {
return swarm.Swarm{}, fmt.Errorf("error inspecting the swarm")
},
expectedError: "error inspecting the swarm",
},
{
name: "swarm-update-failed",
args: []string{"worker"},
flags: map[string]string{
flagRotate: "true",
},
swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error {
return fmt.Errorf("error updating the swarm")
},
expectedError: "error updating the swarm",
},
{
name: "node-inspect-failed",
args: []string{"worker"},
nodeInspectFunc: func() (swarm.Node, []byte, error) {
return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting node")
},
expectedError: "error inspecting node",
},
{
name: "info-failed",
args: []string{"worker"},
infoFunc: func() (types.Info, error) {
return types.Info{}, fmt.Errorf("error asking for node info")
},
expectedError: "error asking for node info",
},
}
for _, tc := range testCases {
buf := new(bytes.Buffer)
cmd := newJoinTokenCommand(
test.NewFakeCli(&fakeClient{
swarmInspectFunc: tc.swarmInspectFunc,
swarmUpdateFunc: tc.swarmUpdateFunc,
infoFunc: tc.infoFunc,
nodeInspectFunc: tc.nodeInspectFunc,
}, 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)
}
}
开发者ID:docker,项目名称:docker,代码行数:89,代码来源:join_token_test.go
示例19: TestNodeInspectErrors
func TestNodeInspectErrors(t *testing.T) {
testCases := []struct {
args []string
flags map[string]string
nodeInspectFunc func() (swarm.Node, []byte, error)
infoFunc func() (types.Info, error)
expectedError string
}{
{
expectedError: "requires at least 1 argument",
},
{
args: []string{"self"},
infoFunc: func() (types.Info, error) {
return types.Info{}, fmt.Errorf("error asking for node info")
},
expectedError: "error asking for node info",
},
{
args: []string{"nodeID"},
nodeInspectFunc: func() (swarm.Node, []byte, error) {
return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node")
},
infoFunc: func() (types.Info, error) {
return types.Info{}, fmt.Errorf("error asking for node info")
},
expectedError: "error inspecting the node",
},
{
args: []string{"self"},
nodeInspectFunc: func() (swarm.Node, []byte, error) {
return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node")
},
infoFunc: func() (types.Info, error) {
return types.Info{}, nil
},
expectedError: "error inspecting the node",
},
{
args: []string{"self"},
flags: map[string]string{
"pretty": "true",
},
infoFunc: func() (types.Info, error) {
return types.Info{}, fmt.Errorf("error asking for node info")
},
expectedError: "error asking for node info",
},
}
for _, tc := range testCases {
buf := new(bytes.Buffer)
cmd := newInspectCommand(
test.NewFakeCli(&fakeClient{
nodeInspectFunc: tc.nodeInspectFunc,
infoFunc: tc.infoFunc,
}, 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)
}
}
开发者ID:docker,项目名称:docker,代码行数:64,代码来源:inspect_test.go
示例20: TestSwarmUnlockKey
func TestSwarmUnlockKey(t *testing.T) {
testCases := []struct {
name string
args []string
flags map[string]string
swarmInspectFunc func() (swarm.Swarm, error)
swarmUpdateFunc func(swarm swarm.Spec, flags swarm.UpdateFlags) error
swarmGetUnlockKeyFunc func() (types.SwarmUnlockKeyResponse, error)
}{
{
name: "unlock-key",
swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) {
return types.SwarmUnlockKeyResponse{
UnlockKey: "unlock-key",
}, nil
},
},
{
name: "unlock-key-quiet",
flags: map[string]string{
flagQuiet: "true",
},
swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) {
return types.SwarmUnlockKeyResponse{
UnlockKey: "unlock-key",
}, nil
},
},
{
name: "unlock-key-rotate",
flags: map[string]string{
flagRotate: "true",
},
swarmInspectFunc: func() (swarm.Swarm, error) {
return *Swarm(Autolock()), nil
},
swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) {
return types.SwarmUnlockKeyResponse{
UnlockKey: "unlock-key",
}, nil
},
},
{
name: "unlock-key-rotate-quiet",
flags: map[string]string{
flagQuiet: "true",
flagRotate: "true",
},
swarmInspectFunc: func() (swarm.Swarm, error) {
return *Swarm(Autolock()), nil
},
swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) {
return types.SwarmUnlockKeyResponse{
UnlockKey: "unlock-key",
}, nil
},
},
}
for _, tc := range testCases {
buf := new(bytes.Buffer)
cmd := newUnlockKeyCommand(
test.NewFakeCli(&fakeClient{
swarmInspectFunc: tc.swarmInspectFunc,
swarmUpdateFunc: tc.swarmUpdateFunc,
swarmGetUnlockKeyFunc: tc.swarmGetUnlockKeyFunc,
}, buf))
cmd.SetArgs(tc.args)
for key, value := range tc.flags {
cmd.Flags().Set(key, value)
}
assert.NilError(t, cmd.Execute())
actual := buf.String()
expected := golden.Get(t, []byte(actual), fmt.Sprintf("unlockkeys-%s.golden", tc.name))
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
}
}
开发者ID:docker,项目名称:docker,代码行数:76,代码来源:unlock_key_test.go
注:本文中的github.com/docker/docker/cli/internal/test.NewFakeCli函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论