passed unit test

This commit is contained in:
Nan Deng 2014-06-12 14:59:03 -07:00
parent bd4ecafad8
commit 5a8bceb43e
7 changed files with 33 additions and 22 deletions

View File

@ -32,7 +32,7 @@ type ListType int
type ContainerHandler interface {
GetSpec() (*info.ContainerSpec, error)
GetStats() (*info.ContainerStats, error)
ListContainers(listType ListType) ([]string, error)
ListContainers(listType ListType) ([]info.ContainerRef, error)
ListThreads(listType ListType) ([]int, error)
ListProcesses(listType ListType) ([]int, error)
StatsSummary() (*info.ContainerStatsPercentiles, error)

View File

@ -34,7 +34,7 @@ func (self *containerListFilter) GetStats() (*info.ContainerStats, error) {
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)
if err != nil {
return nil, err
@ -42,9 +42,9 @@ func (self *containerListFilter) ListContainers(listType ListType) ([]string, er
if len(containers) == 0 {
return nil, nil
}
ret := make([]string, 0, len(containers))
ret := make([]info.ContainerRef, 0, len(containers))
for _, c := range containers {
if self.filter(c) {
if self.filter(c.Name) {
ret = append(ret, c)
}
}

View File

@ -37,9 +37,9 @@ func (self *mockContainerHandler) GetStats() (*info.ContainerStats, error) {
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)
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) {
@ -55,10 +55,10 @@ func (self *mockContainerHandler) ListProcesses(listType ListType) ([]int, error
func TestWhiteListContainerFilter(t *testing.T) {
mockc := &mockContainerHandler{}
mockc.On("ListContainers", LIST_RECURSIVE).Return(
[]string{
"/docker/ee0103",
"/container/created/by/lmctfy",
"/user/something",
[]info.ContainerRef{
info.ContainerRef{Name: "/docker/ee0103"},
info.ContainerRef{Name: "/container/created/by/lmctfy"},
info.ContainerRef{Name: "/user/something"},
},
nil,
)
@ -76,7 +76,7 @@ func TestWhiteListContainerFilter(t *testing.T) {
for _, c := range containers {
legal := false
for _, prefix := range filterPaths {
if strings.HasPrefix(c, prefix) {
if strings.HasPrefix(c.Name, prefix) {
legal = true
}
}
@ -90,10 +90,10 @@ func TestWhiteListContainerFilter(t *testing.T) {
func TestBlackListContainerFilter(t *testing.T) {
mockc := &mockContainerHandler{}
mockc.On("ListContainers", LIST_RECURSIVE).Return(
[]string{
"/docker/ee0103",
"/container/created/by/lmctfy",
"/user/something",
[]info.ContainerRef{
info.ContainerRef{Name: "/docker/ee0103"},
info.ContainerRef{Name: "/container/created/by/lmctfy"},
info.ContainerRef{Name: "/user/something"},
},
nil,
)
@ -111,7 +111,7 @@ func TestBlackListContainerFilter(t *testing.T) {
for _, c := range containers {
legal := true
for _, prefix := range filterPaths {
if strings.HasPrefix(c, prefix) {
if strings.HasPrefix(c.Name, prefix) {
legal = false
}
}

View File

@ -94,7 +94,7 @@ func (self *percentilesContainerHandlerWrapper) GetStats() (*info.ContainerStats
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)
}

View File

@ -29,7 +29,7 @@ type mockContainer struct {
func (self *mockContainer) GetSpec() (*info.ContainerSpec, error) {
return nil, nil
}
func (self *mockContainer) ListContainers(listType ListType) ([]string, error) {
func (self *mockContainer) ListContainers(listType ListType) ([]info.ContainerRef, error) {
return nil, nil
}

View File

@ -49,12 +49,19 @@ type ContainerSpec struct {
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.
Name string `json:"name"`
Aliases []string `json:"aliases,omitempty"`
}
type ContainerInfo struct {
ContainerRef
// The direct subcontainers of the current container.
Subcontainers []string `json:"subcontainers,omitempty"`
Subcontainers []ContainerRef `json:"subcontainers,omitempty"`
// The isolation used in the container.
Spec *ContainerSpec `json:"spec,omitempty"`

View File

@ -30,7 +30,9 @@ func TestStatsStartTime(t *testing.T) {
stats = append(stats, s)
}
cinfo := &ContainerInfo{
Name: "/some/container",
ContainerRef: ContainerRef{
Name: "/some/container",
},
Stats: stats,
}
ref := ct.Add(time.Duration(N-1) * time.Second)
@ -52,7 +54,9 @@ func TestStatsEndTime(t *testing.T) {
stats = append(stats, s)
}
cinfo := &ContainerInfo{
Name: "/some/container",
ContainerRef: ContainerRef{
Name: "/some/container",
},
Stats: stats,
}
ref := ct