mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
more unit test for GetContainerStats()
This commit is contained in:
parent
3080262f12
commit
b01a12fe34
@ -1006,3 +1006,33 @@ func TestGetContainerStats(t *testing.T) {
|
||||
areSamePercentiles(containerInfo.StatsPercentiles.MemoryUsagePercentiles, stats.MemoryUsagePercentiles, t)
|
||||
mockCadvisor.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestGetContainerStatsWithoutCadvisor(t *testing.T) {
|
||||
fakeDocker := FakeDockerClient{
|
||||
err: nil,
|
||||
}
|
||||
|
||||
kubelet := Kubelet{
|
||||
DockerClient: &fakeDocker,
|
||||
}
|
||||
fakeDocker.containerList = []docker.APIContainers{
|
||||
{
|
||||
Names: []string{"foo"},
|
||||
},
|
||||
}
|
||||
|
||||
stats, _ := kubelet.GetContainerStats("foo")
|
||||
// When there's no cAdvisor, the stats should be either nil or empty
|
||||
if stats == nil {
|
||||
return
|
||||
}
|
||||
if stats.MaxMemoryUsage != 0 {
|
||||
t.Errorf("MaxMemoryUsage is %v even if there's no cadvisor", stats.MaxMemoryUsage)
|
||||
}
|
||||
if len(stats.CpuUsagePercentiles) > 0 {
|
||||
t.Errorf("Cpu usage percentiles is not empty (%+v) even if there's no cadvisor", stats.CpuUsagePercentiles)
|
||||
}
|
||||
if len(stats.MemoryUsagePercentiles) > 0 {
|
||||
t.Errorf("Memory usage percentiles is not empty (%+v) even if there's no cadvisor", stats.MemoryUsagePercentiles)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user