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


Golang ContainerConfig.Labels方法代碼示例

本文整理匯總了Golang中github.com/docker/swarm/cluster.ContainerConfig.Labels方法的典型用法代碼示例。如果您正苦於以下問題:Golang ContainerConfig.Labels方法的具體用法?Golang ContainerConfig.Labels怎麽用?Golang ContainerConfig.Labels使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/docker/swarm/cluster.ContainerConfig的用法示例。


在下文中一共展示了ContainerConfig.Labels方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestCreateContainer

func TestCreateContainer(t *testing.T) {

	// create mock client
	config := new(cluster.ContainerConfig)
	config.Labels = make(map[string]string)
	config.Labels["upm.ip"] = "192.168.11.124/24:enp0s25"

	dockinfo := new(dockerclient.ContainerInfo)
	dockinfo.Id = "123456789"
	dockinfo.Config = &dockerclient.ContainerConfig{
		Labels: map[string]string{
			"upm.ip": "192.168.11.124/24:enp0s25",
		},
	}

	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", mock.Anything).Return([]*dockerclient.Image{}, nil)
	client.On("ListVolumes", mock.Anything).Return([]*dockerclient.Volume{}, nil)
	client.On("ListNetworks", mock.Anything).Return([]*dockerclient.NetworkResource{}, nil)
	client.On("ListVolumes", mock.Anything).Return([]*dockerclient.Volume{}, nil)
	client.On("CreateContainer", mock.Anything, mock.Anything).Return("123456789", nil)
	client.On("RemoveContainer", mock.AnythingOfType("string"), true, true).Return(nil)
	client.On("InspectContainer", "123456789").Return(dockinfo, nil)

	// create a cluster from mock client
	c := simpleCluster(client)
	ca, err := c.CreateContainer(config, "lee.test")
	assert.Nil(t, err)
	if err != nil {
		return
	}

	assert.Equal(t, ca.Id, "123456789")

	err = c.RemoveContainer(ca, true, true)
	assert.Nil(t, err)
}
開發者ID:upmio,項目名稱:swarm_proxy,代碼行數:41,代碼來源:cluster_test.go


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