test get info
This commit is contained in:
parent
4df4b0ee2e
commit
7df7989849
@ -15,6 +15,7 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"math"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
@ -48,3 +49,20 @@ func GenerateRandomStats(numStats, numCores int, duration time.Duration) []*info
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func GenerateRandomContainerSpec(numCores int) *info.ContainerSpec {
|
||||
ret := &info.ContainerSpec{
|
||||
Cpu: &info.CpuSpec{},
|
||||
Memory: &info.MemorySpec{},
|
||||
}
|
||||
ret.Cpu.Limit = uint64(1000 + rand.Int63n(2000))
|
||||
ret.Cpu.MaxLimit = uint64(1000 + rand.Int63n(2000))
|
||||
n := (numCores + 63) / 64
|
||||
ret.Cpu.Mask.Data = make([]uint64, n)
|
||||
for i := 0; i < n; i++ {
|
||||
ret.Cpu.Mask.Data[i] = math.MaxUint64
|
||||
}
|
||||
|
||||
ret.Memory.Limit = uint64(4096 + rand.Int63n(4096))
|
||||
return ret
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package manager
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -134,3 +135,84 @@ func TestContainerUpdateStats(t *testing.T) {
|
||||
|
||||
handler.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestContainerUpdateSpec(t *testing.T) {
|
||||
var handler *ctest.MockContainerHandler
|
||||
spec := itest.GenerateRandomContainerSpec(4)
|
||||
cd := createContainerDataAndSetHandler(
|
||||
nil,
|
||||
func(h *ctest.MockContainerHandler) {
|
||||
h.On("GetSpec").Return(
|
||||
spec,
|
||||
nil,
|
||||
)
|
||||
handler = h
|
||||
},
|
||||
t,
|
||||
)
|
||||
|
||||
err := cd.updateSpec()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
handler.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestContainerGetInfo(t *testing.T) {
|
||||
var handler *ctest.MockContainerHandler
|
||||
spec := itest.GenerateRandomContainerSpec(4)
|
||||
subcontainers := []info.ContainerReference{
|
||||
{Name: "/container/ee0103"},
|
||||
{Name: "/container/abcd"},
|
||||
{Name: "/container/something"},
|
||||
}
|
||||
aliases := []string{"a1", "a2"}
|
||||
cd := createContainerDataAndSetHandler(
|
||||
nil,
|
||||
func(h *ctest.MockContainerHandler) {
|
||||
h.On("GetSpec").Return(
|
||||
spec,
|
||||
nil,
|
||||
)
|
||||
h.On("ListContainers", container.LIST_SELF).Return(
|
||||
subcontainers,
|
||||
nil,
|
||||
)
|
||||
h.Aliases = aliases
|
||||
handler = h
|
||||
},
|
||||
t,
|
||||
)
|
||||
|
||||
info, err := cd.GetInfo()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
handler.AssertExpectations(t)
|
||||
|
||||
if len(info.Subcontainers) != len(subcontainers) {
|
||||
t.Errorf("Received %v subcontainers, should be %v", len(info.Subcontainers), len(subcontainers))
|
||||
}
|
||||
|
||||
for _, sub := range info.Subcontainers {
|
||||
found := false
|
||||
for _, sub2 := range subcontainers {
|
||||
if sub.Name == sub2.Name {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Errorf("Received unknown sub container %v", sub)
|
||||
}
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(spec, info.Spec) {
|
||||
t.Errorf("received wrong container spec")
|
||||
}
|
||||
|
||||
if info.Name != handler.Name {
|
||||
t.Errorf("received wrong container name: received %v; should be %v", info.Name, handler.Name)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user