本文整理汇总了Golang中github.com/samalba/dockerclient/mockclient.NewMockClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewMockClient函数的具体用法?Golang NewMockClient怎么用?Golang NewMockClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewMockClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestEngineCpusMemory
func TestEngineCpusMemory(t *testing.T) {
engine := NewEngine("test", 0, engOpts)
engine.setState(stateUnhealthy)
assert.False(t, engine.isConnected())
client := mockclient.NewMockClient()
apiClient := engineapimock.NewMockClient()
apiClient.On("Info", mock.Anything).Return(mockInfo, nil)
apiClient.On("ServerVersion", mock.Anything).Return(mockVersion, nil)
apiClient.On("NetworkList", mock.Anything,
mock.AnythingOfType("NetworkListOptions"),
).Return([]types.NetworkResource{}, nil)
apiClient.On("VolumeList", mock.Anything,
mock.AnythingOfType("Args"),
).Return(types.VolumesListResponse{}, nil)
apiClient.On("ImageList", mock.Anything, mock.AnythingOfType("ImageListOptions")).Return([]types.Image{}, nil)
apiClient.On("ContainerList", mock.Anything, types.ContainerListOptions{All: true, Size: false}).Return([]types.Container{}, nil)
apiClient.On("Events", mock.Anything, mock.AnythingOfType("EventsOptions")).Return(&nopCloser{infiniteRead{}}, nil)
assert.NoError(t, engine.ConnectWithClient(client, apiClient))
assert.True(t, engine.isConnected())
assert.True(t, engine.IsHealthy())
assert.Equal(t, engine.UsedCpus(), int64(0))
assert.Equal(t, engine.UsedMemory(), int64(0))
client.Mock.AssertExpectations(t)
apiClient.Mock.AssertExpectations(t)
}
开发者ID:cbbs,项目名称:swarm,代码行数:29,代码来源:engine_test.go
示例2: TestEngineSpecs
func TestEngineSpecs(t *testing.T) {
engine := NewEngine("test", 0)
assert.False(t, engine.isConnected())
client := mockclient.NewMockClient()
client.On("Info").Return(mockInfo, nil)
client.On("Version").Return(mockVersion, nil)
client.On("ListContainers", true, false, "").Return([]dockerclient.Container{}, nil)
client.On("ListImages").Return([]*dockerclient.Image{}, nil)
client.On("StartMonitorEvents", mock.Anything, mock.Anything, mock.Anything).Return()
assert.NoError(t, engine.ConnectWithClient(client))
assert.True(t, engine.isConnected())
assert.True(t, engine.IsHealthy())
assert.Equal(t, engine.Cpus, mockInfo.NCPU)
assert.Equal(t, engine.Memory, mockInfo.MemTotal)
assert.Equal(t, engine.Labels["storagedriver"], mockInfo.Driver)
assert.Equal(t, engine.Labels["executiondriver"], mockInfo.ExecutionDriver)
assert.Equal(t, engine.Labels["kernelversion"], mockInfo.KernelVersion)
assert.Equal(t, engine.Labels["operatingsystem"], mockInfo.OperatingSystem)
assert.Equal(t, engine.Labels["foo"], "bar")
client.Mock.AssertExpectations(t)
}
开发者ID:ealang,项目名称:swarm,代码行数:25,代码来源:engine_test.go
示例3: TestStopContainer_DefaultSuccess
func TestStopContainer_DefaultSuccess(t *testing.T) {
c := Container{
containerInfo: &dockerclient.ContainerInfo{
Name: "foo",
Id: "abc123",
Config: &dockerclient.ContainerConfig{},
},
}
ci := &dockerclient.ContainerInfo{
State: &dockerclient.State{
Running: false,
},
}
api := mockclient.NewMockClient()
api.On("KillContainer", "abc123", "SIGTERM").Return(nil)
api.On("InspectContainer", "abc123").Return(ci, nil).Once()
api.On("RemoveContainer", "abc123", true, false).Return(nil)
api.On("InspectContainer", "abc123").Return(&dockerclient.ContainerInfo{}, errors.New("Not Found"))
client := dockerClient{api: api}
err := client.StopContainer(c, time.Second)
assert.NoError(t, err)
api.AssertExpectations(t)
}
开发者ID:ChrisMcKenzie,项目名称:watchtower,代码行数:27,代码来源:client_test.go
示例4: TestNodeContainerLookup
func TestNodeContainerLookup(t *testing.T) {
node := NewNode("test-node", 0)
assert.False(t, node.isConnected())
client := mockclient.NewMockClient()
client.On("Info").Return(mockInfo, nil)
client.On("StartMonitorEvents", mock.Anything, mock.Anything, mock.Anything).Return()
client.On("ListContainers", true, false, "").Return([]dockerclient.Container{{Id: "container-id", Names: []string{"/container-name1", "/container-name2"}}}, nil).Once()
client.On("ListImages").Return([]*dockerclient.Image{}, nil).Once()
client.On("InspectContainer", "container-id").Return(&dockerclient.ContainerInfo{Config: &dockerclient.ContainerConfig{CpuShares: 100}}, nil).Once()
assert.NoError(t, node.connectClient(client))
assert.True(t, node.isConnected())
// Invalid lookup
assert.Nil(t, node.Container("invalid-id"))
assert.Nil(t, node.Container(""))
// Container ID lookup.
assert.NotNil(t, node.Container("container-id"))
// Container ID prefix lookup.
assert.NotNil(t, node.Container("container-"))
// Container name lookup.
assert.NotNil(t, node.Container("container-name1"))
assert.NotNil(t, node.Container("container-name2"))
// Container node/name matching.
assert.NotNil(t, node.Container("id/container-name1"))
assert.NotNil(t, node.Container("id/container-name2"))
client.Mock.AssertExpectations(t)
}
开发者ID:josephwinston,项目名称:libswarm,代码行数:31,代码来源:node_test.go
示例5: TestUsedCpus
func TestUsedCpus(t *testing.T) {
var (
containerNcpu = []int64{1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}
hostNcpu = []int64{1, 2, 4, 8, 10, 12, 16, 20, 32, 36, 40, 48}
)
engine := NewEngine("test", 0)
client := mockclient.NewMockClient()
for _, hn := range hostNcpu {
for _, cn := range containerNcpu {
if cn <= hn {
mockInfo.NCPU = hn
cpuShares := int64(math.Ceil(float64(cn*1024) / float64(mockInfo.NCPU)))
client.On("Info").Return(mockInfo, nil)
client.On("Version").Return(mockVersion, nil)
client.On("StartMonitorEvents", mock.Anything, mock.Anything, mock.Anything).Return()
client.On("ListImages").Return([]*dockerclient.Image{}, nil).Once()
client.On("ListContainers", true, false, "").Return([]dockerclient.Container{{Id: "test"}}, nil).Once()
client.On("InspectContainer", "test").Return(&dockerclient.ContainerInfo{Config: &dockerclient.ContainerConfig{CpuShares: cpuShares}}, nil).Once()
engine.ConnectWithClient(client)
assert.Equal(t, engine.UsedCpus(), cn)
}
}
}
}
开发者ID:ealang,项目名称:swarm,代码行数:28,代码来源:engine_test.go
示例6: TestContainerRemovedDuringRefresh
func TestContainerRemovedDuringRefresh(t *testing.T) {
var (
container1 = dockerclient.Container{Id: "c1"}
container2 = dockerclient.Container{Id: "c2"}
info1 *dockerclient.ContainerInfo
info2 = &dockerclient.ContainerInfo{Id: "c2", Config: &dockerclient.ContainerConfig{}}
)
engine := NewEngine("test", 0)
assert.False(t, engine.isConnected())
// A container is removed before it can be inspected.
client := mockclient.NewMockClient()
client.On("Info").Return(mockInfo, nil)
client.On("Version").Return(mockVersion, nil)
client.On("ListImages").Return([]*dockerclient.Image{}, nil)
client.On("StartMonitorEvents", mock.Anything, mock.Anything, mock.Anything).Return()
client.On("ListContainers", true, false, "").Return([]dockerclient.Container{container1, container2}, nil)
client.On("InspectContainer", "c1").Return(info1, errors.New("Not found"))
client.On("InspectContainer", "c2").Return(info2, nil)
assert.NoError(t, engine.ConnectWithClient(client))
assert.Nil(t, engine.RefreshContainers(true))
// List of containers is still valid
containers := engine.Containers()
assert.Len(t, containers, 1)
assert.Equal(t, containers[0].Id, "c2")
client.Mock.AssertExpectations(t)
}
开发者ID:ealang,项目名称:swarm,代码行数:32,代码来源:engine_test.go
示例7: TestEngineSpecs
func TestEngineSpecs(t *testing.T) {
engine := NewEngine("test", 0, engOpts)
engine.setState(stateUnhealthy)
assert.False(t, engine.isConnected())
client := mockclient.NewMockClient()
apiClient := engineapimock.NewMockClient()
apiClient.On("Info", mock.Anything).Return(mockInfo, nil)
apiClient.On("ServerVersion", mock.Anything).Return(mockVersion, nil)
apiClient.On("NetworkList", mock.Anything,
mock.AnythingOfType("NetworkListOptions"),
).Return([]types.NetworkResource{}, nil)
apiClient.On("VolumeList", mock.Anything,
mock.AnythingOfType("Args"),
).Return(types.VolumesListResponse{}, nil)
apiClient.On("ImageList", mock.Anything, mock.AnythingOfType("ImageListOptions")).Return([]types.Image{}, nil)
apiClient.On("ContainerList", mock.Anything, types.ContainerListOptions{All: true, Size: false}).Return([]types.Container{}, nil)
apiClient.On("Events", mock.Anything, mock.AnythingOfType("EventsOptions")).Return(&nopCloser{infiniteRead{}}, nil)
assert.NoError(t, engine.ConnectWithClient(client, apiClient))
assert.True(t, engine.isConnected())
assert.True(t, engine.IsHealthy())
assert.Equal(t, engine.Cpus, int64(mockInfo.NCPU))
assert.Equal(t, engine.Memory, mockInfo.MemTotal)
assert.Equal(t, engine.Labels["storagedriver"], mockInfo.Driver)
assert.Equal(t, engine.Labels["executiondriver"], mockInfo.ExecutionDriver)
assert.Equal(t, engine.Labels["kernelversion"], mockInfo.KernelVersion)
assert.Equal(t, engine.Labels["operatingsystem"], mockInfo.OperatingSystem)
assert.Equal(t, engine.Labels["foo"], "bar")
client.Mock.AssertExpectations(t)
apiClient.Mock.AssertExpectations(t)
}
开发者ID:cbbs,项目名称:swarm,代码行数:34,代码来源:engine_test.go
示例8: TestStopContainer_CustomSignalSuccess
func TestStopContainer_CustomSignalSuccess(t *testing.T) {
c := Container{
containerInfo: &dockerclient.ContainerInfo{
Name: "foo",
Id: "abc123",
Config: &dockerclient.ContainerConfig{
Labels: map[string]string{"com.centurylinklabs.watchtower.stop-signal": "SIGUSR1"}},
},
}
ci := &dockerclient.ContainerInfo{
State: &dockerclient.State{
Running: false,
},
}
api := mockclient.NewMockClient()
api.On("KillContainer", "abc123", "SIGUSR1").Return(nil)
api.On("InspectContainer", "abc123").Return(ci, nil).Once()
api.On("RemoveContainer", "abc123", true, false).Return(nil)
api.On("InspectContainer", "abc123").Return(&dockerclient.ContainerInfo{}, errors.New("Not Found"))
client := dockerClient{api: api}
err := client.StopContainer(c, time.Second)
assert.NoError(t, err)
api.AssertExpectations(t)
}
开发者ID:ChrisMcKenzie,项目名称:watchtower,代码行数:28,代码来源:client_test.go
示例9: TestCreateContainer
func TestCreateContainer(t *testing.T) {
var (
config = &ContainerConfig{dockerclient.ContainerConfig{
Image: "busybox",
CpuShares: 1,
Cmd: []string{"date"},
Tty: false,
}}
engine = NewEngine("test", 0)
client = mockclient.NewMockClient()
)
client.On("Info").Return(mockInfo, nil)
client.On("Version").Return(mockVersion, nil)
client.On("StartMonitorEvents", mock.Anything, mock.Anything, mock.Anything).Return()
client.On("ListContainers", true, false, "").Return([]dockerclient.Container{}, nil).Once()
client.On("ListImages").Return([]*dockerclient.Image{}, nil).Once()
assert.NoError(t, engine.ConnectWithClient(client))
assert.True(t, engine.isConnected())
mockConfig := config.ContainerConfig
mockConfig.CpuShares = int64(math.Ceil(float64(config.CpuShares*1024) / float64(mockInfo.NCPU)))
mockConfig.HostConfig.CpuShares = mockConfig.CpuShares
// Everything is ok
name := "test1"
id := "id1"
client.On("CreateContainer", &mockConfig, name).Return(id, nil).Once()
client.On("ListContainers", true, false, fmt.Sprintf(`{"id":[%q]}`, id)).Return([]dockerclient.Container{{Id: id}}, nil).Once()
client.On("ListImages").Return([]*dockerclient.Image{}, nil).Once()
client.On("InspectContainer", id).Return(&dockerclient.ContainerInfo{Config: &config.ContainerConfig}, nil).Once()
container, err := engine.Create(config, name, false)
assert.Nil(t, err)
assert.Equal(t, container.Id, id)
assert.Len(t, engine.Containers(), 1)
// Image not found, pullImage == false
name = "test2"
mockConfig.CpuShares = int64(math.Ceil(float64(config.CpuShares*1024) / float64(mockInfo.NCPU)))
client.On("CreateContainer", &mockConfig, name).Return("", dockerclient.ErrNotFound).Once()
container, err = engine.Create(config, name, false)
assert.Equal(t, err, dockerclient.ErrNotFound)
assert.Nil(t, container)
// Image not found, pullImage == true, and the image can be pulled successfully
name = "test3"
id = "id3"
mockConfig.CpuShares = int64(math.Ceil(float64(config.CpuShares*1024) / float64(mockInfo.NCPU)))
client.On("PullImage", config.Image+":latest", mock.Anything).Return(nil).Once()
client.On("CreateContainer", &mockConfig, name).Return("", dockerclient.ErrNotFound).Once()
client.On("CreateContainer", &mockConfig, name).Return(id, nil).Once()
client.On("ListContainers", true, false, fmt.Sprintf(`{"id":[%q]}`, id)).Return([]dockerclient.Container{{Id: id}}, nil).Once()
client.On("ListImages").Return([]*dockerclient.Image{}, nil).Once()
client.On("InspectContainer", id).Return(&dockerclient.ContainerInfo{Config: &config.ContainerConfig}, nil).Once()
container, err = engine.Create(config, name, true)
assert.Nil(t, err)
assert.Equal(t, container.Id, id)
assert.Len(t, engine.Containers(), 2)
}
开发者ID:ealang,项目名称:swarm,代码行数:59,代码来源:engine_test.go
示例10: TestResolveImage_WhenImageExisting
func TestResolveImage_WhenImageExisting(t *testing.T) {
c := mockclient.NewMockClient()
c.On("InspectImage", "Foo").Return(&dockerclient.ImageInfo{Id: "ytu678"}, nil)
e := DockerEndpoint{client: c}
imageID, err := e.ResolveImage("Foo")
assert.NoError(t, err)
assert.Equal(t, "ytu678", imageID)
}
开发者ID:rupakg,项目名称:zodiac,代码行数:9,代码来源:endpoint_test.go
示例11: TestDockerEndpointVersion_ErroredClient
func TestDockerEndpointVersion_ErroredClient(t *testing.T) {
c := mockclient.NewMockClient()
c.On("Version").Return(&dockerclient.Version{Version: ""}, errors.New("test error"))
e := DockerEndpoint{client: c}
v, err := e.Version()
assert.Empty(t, "", v)
assert.EqualError(t, err, "test error")
}
开发者ID:rupakg,项目名称:zodiac,代码行数:9,代码来源:endpoint_test.go
示例12: TestOutdatedNode
func TestOutdatedNode(t *testing.T) {
node := NewNode("test", 0)
client := mockclient.NewMockClient()
client.On("Info").Return(&dockerclient.Info{}, nil)
assert.Error(t, node.connectClient(client))
assert.False(t, node.IsConnected())
client.Mock.AssertExpectations(t)
}
开发者ID:SivagnanamCiena,项目名称:swarm,代码行数:10,代码来源:node_test.go
示例13: TestDockerEndpointVersion_Successful
func TestDockerEndpointVersion_Successful(t *testing.T) {
c := mockclient.NewMockClient()
c.On("Version").Return(&dockerclient.Version{Version: "1.6.1"}, nil).Once()
e := DockerEndpoint{client: c}
v, err := e.Version()
assert.NoError(t, err)
assert.Equal(t, "1.6.1", v)
c.AssertExpectations(t)
}
开发者ID:rupakg,项目名称:zodiac,代码行数:10,代码来源:endpoint_test.go
示例14: TestRemoveContainer_Success
func TestRemoveContainer_Success(t *testing.T) {
c := mockclient.NewMockClient()
c.On("RemoveContainer", "foo", true, false).Return(nil)
e := DockerEndpoint{client: c}
err := e.RemoveContainer("foo")
assert.NoError(t, err)
c.AssertExpectations(t)
}
开发者ID:rupakg,项目名称:zodiac,代码行数:10,代码来源:endpoint_test.go
示例15: TestOutdatedEngine
func TestOutdatedEngine(t *testing.T) {
engine := NewEngine("test", 0)
client := mockclient.NewMockClient()
client.On("Info").Return(&dockerclient.Info{}, nil)
assert.Error(t, engine.ConnectWithClient(client))
assert.False(t, engine.isConnected())
client.Mock.AssertExpectations(t)
}
开发者ID:ealang,项目名称:swarm,代码行数:10,代码来源:engine_test.go
示例16: TestListContainers_ListError
func TestListContainers_ListError(t *testing.T) {
api := mockclient.NewMockClient()
api.On("ListContainers", false, false, "").Return([]dockerclient.Container{}, errors.New("oops"))
client := dockerClient{api: api}
_, err := client.ListContainers(allContainers)
assert.Error(t, err)
assert.EqualError(t, err, "oops")
api.AssertExpectations(t)
}
开发者ID:ChrisMcKenzie,项目名称:watchtower,代码行数:11,代码来源:client_test.go
示例17: TestResolveImage_WhenInitialInspectErrors
func TestResolveImage_WhenInitialInspectErrors(t *testing.T) {
c := mockclient.NewMockClient()
c.On("InspectImage", "Foo").Return(&dockerclient.ImageInfo{}, errors.New("oops"))
e := DockerEndpoint{client: c}
imageID, err := e.ResolveImage("Foo")
assert.Equal(t, "", imageID)
assert.EqualError(t, err, "oops")
c.AssertExpectations(t)
}
开发者ID:rupakg,项目名称:zodiac,代码行数:11,代码来源:endpoint_test.go
示例18: TestResolveImage_WhenImageDoesNotExist
func TestResolveImage_WhenImageDoesNotExist(t *testing.T) {
c := mockclient.NewMockClient()
c.On("InspectImage", "Foo").Return(&dockerclient.ImageInfo{}, dockerclient.ErrNotFound).Once()
c.On("PullImage", "Foo", mock.Anything).Return(nil)
c.On("InspectImage", "Foo").Return(&dockerclient.ImageInfo{Id: "yui890"}, nil).Once()
e := DockerEndpoint{client: c}
imageID, err := e.ResolveImage("Foo")
assert.NoError(t, err)
assert.Equal(t, "yui890", imageID)
c.AssertExpectations(t)
}
开发者ID:rupakg,项目名称:zodiac,代码行数:12,代码来源:endpoint_test.go
示例19: TestResolveImage_WhenPullErrors
func TestResolveImage_WhenPullErrors(t *testing.T) {
c := mockclient.NewMockClient()
c.On("InspectImage", "Foo").Return(&dockerclient.ImageInfo{}, dockerclient.ErrNotFound).Once()
c.On("PullImage", "Foo", mock.Anything).Return(errors.New("uh-oh"))
e := DockerEndpoint{client: c}
imageID, err := e.ResolveImage("Foo")
assert.Equal(t, "", imageID)
assert.EqualError(t, err, "uh-oh")
c.AssertExpectations(t)
}
开发者ID:rupakg,项目名称:zodiac,代码行数:12,代码来源:endpoint_test.go
示例20: TestInspectContainer_Success
func TestInspectContainer_Success(t *testing.T) {
expected := &dockerclient.ContainerInfo{Id: "foo"}
c := mockclient.NewMockClient()
c.On("InspectContainer", "foo").Return(expected, nil)
e := DockerEndpoint{client: c}
container, err := e.InspectContainer("foo")
assert.NoError(t, err)
assert.Equal(t, expected, container)
c.AssertExpectations(t)
}
开发者ID:rupakg,项目名称:zodiac,代码行数:12,代码来源:endpoint_test.go
注:本文中的github.com/samalba/dockerclient/mockclient.NewMockClient函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论