本文整理汇总了Golang中github.com/google/cadvisor/info/test.GenerateRandomContainerInfo函数的典型用法代码示例。如果您正苦于以下问题:Golang GenerateRandomContainerInfo函数的具体用法?Golang GenerateRandomContainerInfo怎么用?Golang GenerateRandomContainerInfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GenerateRandomContainerInfo函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestHTTPContainerInfoGetterGetRootInfoWithError
func TestHTTPContainerInfoGetterGetRootInfoWithError(t *testing.T) {
req := &info.ContainerInfoRequest{
NumStats: 10,
}
cinfo := itest.GenerateRandomContainerInfo(
"dockerIDWhichWillNotBeChecked", // docker ID
2, // Number of cores
req,
1*time.Second,
)
testHTTPContainerInfoGetter(req, cinfo, "", "", http.StatusNotFound, t)
}
示例2: TestHTTPContainerInfoGetterGetContainerInfoSuccessfully
func TestHTTPContainerInfoGetterGetContainerInfoSuccessfully(t *testing.T) {
req := &info.ContainerInfoRequest{
NumStats: 10,
}
cinfo := itest.GenerateRandomContainerInfo(
"dockerIDWhichWillNotBeChecked", // docker ID
2, // Number of cores
req,
1*time.Second,
)
testHTTPContainerInfoGetter(req, cinfo, "somePodID", "containerNameInK8S", 0, t)
}
示例3: TestHTTPContainerInfoGetterGetContainerInfoWithError
func TestHTTPContainerInfoGetterGetContainerInfoWithError(t *testing.T) {
req := &info.ContainerInfoRequest{
NumStats: 10,
NumSamples: 10,
}
req = req.FillDefaults()
cinfo := itest.GenerateRandomContainerInfo(
"dockerIDWhichWillNotBeChecked", // docker ID
2, // Number of cores
req,
1*time.Second,
)
testHTTPContainerInfoGetter(req, cinfo, "somePodID", "containerNameInK8S", http.StatusNotFound, t)
}
示例4: TestHTTPContainerInfoGetterGetRootInfoSuccessfully
func TestHTTPContainerInfoGetterGetRootInfoSuccessfully(t *testing.T) {
req := &info.ContainerInfoRequest{
NumStats: 10,
NumSamples: 10,
}
req = req.FillDefaults()
cinfo := itest.GenerateRandomContainerInfo(
"dockerIDWhichWillNotBeChecked", // docker ID
2, // Number of cores
req,
1*time.Second,
)
testHTTPContainerInfoGetter(req, cinfo, "", "", 0, t)
}
示例5: TestHTTPContainerInfoGetterGetRootInfoWithError
func TestHTTPContainerInfoGetterGetRootInfoWithError(t *testing.T) {
req := &info.ContainerInfoRequest{
NumStats: 10,
NumSamples: 10,
CpuUsagePercentiles: []int{20, 30},
MemoryUsagePercentiles: []int{40, 50},
}
cinfo := itest.GenerateRandomContainerInfo(
"dockerIDWhichWillNotBeChecked", // docker ID
2, // Number of cores
req,
1*time.Second,
)
testHTTPContainerInfoGetter(req, cinfo, "", "", http.StatusNotFound, t)
}
示例6: TestHTTPContainerInfoGetterGetContainerInfoSuccessfully
func TestHTTPContainerInfoGetterGetContainerInfoSuccessfully(t *testing.T) {
req := &info.ContainerInfoRequest{
NumStats: 10,
NumSamples: 10,
CpuUsagePercentiles: []int{20, 30},
MemoryUsagePercentiles: []int{40, 50},
}
cinfo := itest.GenerateRandomContainerInfo(
"dockerIDWhichWillNotBeChecked", // docker ID
2, // Number of cores
req,
1*time.Second,
)
testHTTPContainerInfoGetter(req, cinfo, "somePodID", "containerNameInK8S", 0, t)
}
示例7: TestGetSubcontainersInfo
func TestGetSubcontainersInfo(t *testing.T) {
query := &info.ContainerInfoRequest{
NumStats: 3,
}
containerName := "/some/container"
cinfo := itest.GenerateRandomContainerInfo(containerName, 4, query, 1*time.Second)
cinfo1 := itest.GenerateRandomContainerInfo(path.Join(containerName, "sub1"), 4, query, 1*time.Second)
cinfo2 := itest.GenerateRandomContainerInfo(path.Join(containerName, "sub2"), 4, query, 1*time.Second)
response := []info.ContainerInfo{
*cinfo,
*cinfo1,
*cinfo2,
}
client, server, err := cadvisorTestClient(fmt.Sprintf("/api/v1.1/subcontainers%v", containerName), query, &info.ContainerInfoRequest{}, response, t)
if err != nil {
t.Fatalf("unable to get a client %v", err)
}
defer server.Close()
returned, err := client.SubcontainersInfo(containerName, query)
if err != nil {
t.Fatal(err)
}
if len(returned) != 3 {
t.Errorf("unexpected number of results: got %d, expected 3", len(returned))
}
if !returned[0].Eq(cinfo) {
t.Error("received unexpected ContainerInfo")
}
if !returned[1].Eq(cinfo1) {
t.Error("received unexpected ContainerInfo")
}
if !returned[2].Eq(cinfo2) {
t.Error("received unexpected ContainerInfo")
}
}
示例8: expectManagerWithContainers
// Expect a manager with the specified containers and query. Returns the manager, map of ContainerInfo objects,
// and map of MockContainerHandler objects.}
func expectManagerWithContainers(containers []string, query *info.ContainerInfoRequest, t *testing.T) (*manager, map[string]*info.ContainerInfo, map[string]*container.MockContainerHandler) {
infosMap := make(map[string]*info.ContainerInfo, len(containers))
handlerMap := make(map[string]*container.MockContainerHandler, len(containers))
for _, container := range containers {
infosMap[container] = itest.GenerateRandomContainerInfo(container, 4, query, 1*time.Second)
}
driver := &stest.MockStorageDriver{}
sysfs := &fakesysfs.FakeSysFs{}
m := createManagerAndAddContainers(
driver,
sysfs,
containers,
func(h *container.MockContainerHandler) {
cinfo := infosMap[h.Name]
stats := cinfo.Stats
spec := cinfo.Spec
driver.On(
"RecentStats",
h.Name,
query.NumStats,
).Return(
stats,
nil,
)
h.On("ListContainers", container.ListSelf).Return(
[]info.ContainerReference(nil),
nil,
)
h.On("GetSpec").Return(
spec,
nil,
)
handlerMap[h.Name] = h
},
t,
)
return m, infosMap, handlerMap
}
示例9: TestGetContainerInfo
func TestGetContainerInfo(t *testing.T) {
query := &info.ContainerInfoRequest{
NumStats: 3,
}
containerName := "/some/container"
cinfo := itest.GenerateRandomContainerInfo(containerName, 4, query, 1*time.Second)
client, server, err := cadvisorTestClient(fmt.Sprintf("/api/v1.0/containers%v", containerName), query, &info.ContainerInfoRequest{}, cinfo, t)
if err != nil {
t.Fatalf("unable to get a client %v", err)
}
defer server.Close()
returned, err := client.ContainerInfo(containerName, query)
if err != nil {
t.Fatal(err)
}
if !returned.Eq(cinfo) {
t.Error("received unexpected ContainerInfo")
}
}
示例10: TestGetContainerInfo
func TestGetContainerInfo(t *testing.T) {
containers := []string{
"/c1",
"/c2",
}
query := &info.ContainerInfoRequest{
NumStats: 256,
NumSamples: 128,
CpuUsagePercentiles: []int{10, 50, 90},
MemoryUsagePercentages: []int{10, 80, 90},
}
infosMap := make(map[string]*info.ContainerInfo, len(containers))
handlerMap := make(map[string]*ctest.MockContainerHandler, len(containers))
for _, container := range containers {
infosMap[container] = itest.GenerateRandomContainerInfo(container, 4, query, 1*time.Second)
}
driver := &stest.MockStorageDriver{}
m := createManagerAndAddContainers(
driver,
containers,
func(h *ctest.MockContainerHandler) {
cinfo := infosMap[h.Name]
stats := cinfo.Stats
samples := cinfo.Samples
percentiles := cinfo.StatsPercentiles
spec := cinfo.Spec
driver.On(
"Percentiles",
h.Name,
query.CpuUsagePercentiles,
query.MemoryUsagePercentages,
).Return(
percentiles,
nil,
)
driver.On(
"Samples",
h.Name,
query.NumSamples,
).Return(
samples,
nil,
)
driver.On(
"RecentStats",
h.Name,
query.NumStats,
).Return(
stats,
nil,
)
h.On("ListContainers", container.LIST_SELF).Return(
[]info.ContainerReference(nil),
nil,
)
h.On("GetSpec").Return(
spec,
nil,
)
handlerMap[h.Name] = h
},
t,
)
returnedInfos := make(map[string]*info.ContainerInfo, len(containers))
for _, container := range containers {
cinfo, err := m.GetContainerInfo(container, query)
if err != nil {
t.Fatalf("Unable to get info for container %v: %v", container, err)
}
returnedInfos[container] = cinfo
}
for container, handler := range handlerMap {
handler.AssertExpectations(t)
returned := returnedInfos[container]
expected := infosMap[container]
if !reflect.DeepEqual(returned, expected) {
t.Errorf("returned unexpected info for container %v; returned %+v; expected %+v", container, returned, expected)
}
}
}