passed unit test
This commit is contained in:
parent
bd4ecafad8
commit
5a8bceb43e
@ -32,7 +32,7 @@ type ListType int
|
|||||||
type ContainerHandler interface {
|
type ContainerHandler interface {
|
||||||
GetSpec() (*info.ContainerSpec, error)
|
GetSpec() (*info.ContainerSpec, error)
|
||||||
GetStats() (*info.ContainerStats, error)
|
GetStats() (*info.ContainerStats, error)
|
||||||
ListContainers(listType ListType) ([]string, error)
|
ListContainers(listType ListType) ([]info.ContainerRef, error)
|
||||||
ListThreads(listType ListType) ([]int, error)
|
ListThreads(listType ListType) ([]int, error)
|
||||||
ListProcesses(listType ListType) ([]int, error)
|
ListProcesses(listType ListType) ([]int, error)
|
||||||
StatsSummary() (*info.ContainerStatsPercentiles, error)
|
StatsSummary() (*info.ContainerStatsPercentiles, error)
|
||||||
|
@ -34,7 +34,7 @@ func (self *containerListFilter) GetStats() (*info.ContainerStats, error) {
|
|||||||
return self.handler.GetStats()
|
return self.handler.GetStats()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *containerListFilter) ListContainers(listType ListType) ([]string, error) {
|
func (self *containerListFilter) ListContainers(listType ListType) ([]info.ContainerRef, error) {
|
||||||
containers, err := self.handler.ListContainers(listType)
|
containers, err := self.handler.ListContainers(listType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -42,9 +42,9 @@ func (self *containerListFilter) ListContainers(listType ListType) ([]string, er
|
|||||||
if len(containers) == 0 {
|
if len(containers) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
ret := make([]string, 0, len(containers))
|
ret := make([]info.ContainerRef, 0, len(containers))
|
||||||
for _, c := range containers {
|
for _, c := range containers {
|
||||||
if self.filter(c) {
|
if self.filter(c.Name) {
|
||||||
ret = append(ret, c)
|
ret = append(ret, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,9 @@ func (self *mockContainerHandler) GetStats() (*info.ContainerStats, error) {
|
|||||||
return args.Get(0).(*info.ContainerStats), args.Error(1)
|
return args.Get(0).(*info.ContainerStats), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *mockContainerHandler) ListContainers(listType ListType) ([]string, error) {
|
func (self *mockContainerHandler) ListContainers(listType ListType) ([]info.ContainerRef, error) {
|
||||||
args := self.Called(listType)
|
args := self.Called(listType)
|
||||||
return args.Get(0).([]string), args.Error(1)
|
return args.Get(0).([]info.ContainerRef), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *mockContainerHandler) ListThreads(listType ListType) ([]int, error) {
|
func (self *mockContainerHandler) ListThreads(listType ListType) ([]int, error) {
|
||||||
@ -55,10 +55,10 @@ func (self *mockContainerHandler) ListProcesses(listType ListType) ([]int, error
|
|||||||
func TestWhiteListContainerFilter(t *testing.T) {
|
func TestWhiteListContainerFilter(t *testing.T) {
|
||||||
mockc := &mockContainerHandler{}
|
mockc := &mockContainerHandler{}
|
||||||
mockc.On("ListContainers", LIST_RECURSIVE).Return(
|
mockc.On("ListContainers", LIST_RECURSIVE).Return(
|
||||||
[]string{
|
[]info.ContainerRef{
|
||||||
"/docker/ee0103",
|
info.ContainerRef{Name: "/docker/ee0103"},
|
||||||
"/container/created/by/lmctfy",
|
info.ContainerRef{Name: "/container/created/by/lmctfy"},
|
||||||
"/user/something",
|
info.ContainerRef{Name: "/user/something"},
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
@ -76,7 +76,7 @@ func TestWhiteListContainerFilter(t *testing.T) {
|
|||||||
for _, c := range containers {
|
for _, c := range containers {
|
||||||
legal := false
|
legal := false
|
||||||
for _, prefix := range filterPaths {
|
for _, prefix := range filterPaths {
|
||||||
if strings.HasPrefix(c, prefix) {
|
if strings.HasPrefix(c.Name, prefix) {
|
||||||
legal = true
|
legal = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,10 +90,10 @@ func TestWhiteListContainerFilter(t *testing.T) {
|
|||||||
func TestBlackListContainerFilter(t *testing.T) {
|
func TestBlackListContainerFilter(t *testing.T) {
|
||||||
mockc := &mockContainerHandler{}
|
mockc := &mockContainerHandler{}
|
||||||
mockc.On("ListContainers", LIST_RECURSIVE).Return(
|
mockc.On("ListContainers", LIST_RECURSIVE).Return(
|
||||||
[]string{
|
[]info.ContainerRef{
|
||||||
"/docker/ee0103",
|
info.ContainerRef{Name: "/docker/ee0103"},
|
||||||
"/container/created/by/lmctfy",
|
info.ContainerRef{Name: "/container/created/by/lmctfy"},
|
||||||
"/user/something",
|
info.ContainerRef{Name: "/user/something"},
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
@ -111,7 +111,7 @@ func TestBlackListContainerFilter(t *testing.T) {
|
|||||||
for _, c := range containers {
|
for _, c := range containers {
|
||||||
legal := true
|
legal := true
|
||||||
for _, prefix := range filterPaths {
|
for _, prefix := range filterPaths {
|
||||||
if strings.HasPrefix(c, prefix) {
|
if strings.HasPrefix(c.Name, prefix) {
|
||||||
legal = false
|
legal = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ func (self *percentilesContainerHandlerWrapper) GetStats() (*info.ContainerStats
|
|||||||
return stats, nil
|
return stats, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *percentilesContainerHandlerWrapper) ListContainers(listType ListType) ([]string, error) {
|
func (self *percentilesContainerHandlerWrapper) ListContainers(listType ListType) ([]info.ContainerRef, error) {
|
||||||
return self.handler.ListContainers(listType)
|
return self.handler.ListContainers(listType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ type mockContainer struct {
|
|||||||
func (self *mockContainer) GetSpec() (*info.ContainerSpec, error) {
|
func (self *mockContainer) GetSpec() (*info.ContainerSpec, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
func (self *mockContainer) ListContainers(listType ListType) ([]string, error) {
|
func (self *mockContainer) ListContainers(listType ListType) ([]info.ContainerRef, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,12 +49,19 @@ type ContainerSpec struct {
|
|||||||
Memory *MemorySpec `json:"memory,omitempty"`
|
Memory *MemorySpec `json:"memory,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContainerInfo struct {
|
// Container reference contains enough information to uniquely identify a container
|
||||||
|
type ContainerRef struct {
|
||||||
// The absolute name of the container.
|
// The absolute name of the container.
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
Aliases []string `json:"aliases,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ContainerInfo struct {
|
||||||
|
ContainerRef
|
||||||
|
|
||||||
// The direct subcontainers of the current container.
|
// The direct subcontainers of the current container.
|
||||||
Subcontainers []string `json:"subcontainers,omitempty"`
|
Subcontainers []ContainerRef `json:"subcontainers,omitempty"`
|
||||||
|
|
||||||
// The isolation used in the container.
|
// The isolation used in the container.
|
||||||
Spec *ContainerSpec `json:"spec,omitempty"`
|
Spec *ContainerSpec `json:"spec,omitempty"`
|
||||||
|
@ -30,7 +30,9 @@ func TestStatsStartTime(t *testing.T) {
|
|||||||
stats = append(stats, s)
|
stats = append(stats, s)
|
||||||
}
|
}
|
||||||
cinfo := &ContainerInfo{
|
cinfo := &ContainerInfo{
|
||||||
|
ContainerRef: ContainerRef{
|
||||||
Name: "/some/container",
|
Name: "/some/container",
|
||||||
|
},
|
||||||
Stats: stats,
|
Stats: stats,
|
||||||
}
|
}
|
||||||
ref := ct.Add(time.Duration(N-1) * time.Second)
|
ref := ct.Add(time.Duration(N-1) * time.Second)
|
||||||
@ -52,7 +54,9 @@ func TestStatsEndTime(t *testing.T) {
|
|||||||
stats = append(stats, s)
|
stats = append(stats, s)
|
||||||
}
|
}
|
||||||
cinfo := &ContainerInfo{
|
cinfo := &ContainerInfo{
|
||||||
|
ContainerRef: ContainerRef{
|
||||||
Name: "/some/container",
|
Name: "/some/container",
|
||||||
|
},
|
||||||
Stats: stats,
|
Stats: stats,
|
||||||
}
|
}
|
||||||
ref := ct
|
ref := ct
|
||||||
|
Loading…
Reference in New Issue
Block a user