@@ -19,6 +19,8 @@ package stats
19
19
import (
20
20
"context"
21
21
"fmt"
22
+ "runtime"
23
+ "strings"
22
24
"testing"
23
25
"time"
24
26
@@ -505,6 +507,39 @@ func checkFsStats(t *testing.T, label string, seed int, stats *statsapi.FsStats)
505
507
assert .EqualValues (t , seed + offsetFsInodesFree , * stats .InodesFree , label + ".InodesFree" )
506
508
}
507
509
510
+ func checkContainersSwapStats (t * testing.T , podStats statsapi.PodStats , containerStats ... cadvisorapiv2.ContainerInfo ) {
511
+ if runtime .GOOS != "linux" {
512
+ return
513
+ }
514
+
515
+ podContainers := make (map [string ]struct {}, len (podStats .Containers ))
516
+ for _ , container := range podStats .Containers {
517
+ podContainers [container .Name ] = struct {}{}
518
+ }
519
+
520
+ for _ , container := range containerStats {
521
+ found := false
522
+ containerName := container .Spec .Labels ["io.kubernetes.container.name" ]
523
+ for _ , containerPodStats := range podStats .Containers {
524
+ if containerPodStats .Name == containerName {
525
+ assert .Equal (t , container .Stats [0 ].Memory .Swap , * containerPodStats .Swap .SwapUsageBytes )
526
+ found = true
527
+ }
528
+ }
529
+ assert .True (t , found , "container %s not found in pod stats" , container .Spec .Labels ["io.kubernetes.container.name" ])
530
+ delete (podContainers , containerName )
531
+ }
532
+
533
+ var missingContainerNames []string
534
+ for containerName := range podContainers {
535
+ missingContainerNames = append (missingContainerNames , containerName )
536
+ }
537
+ assert .Emptyf (t , podContainers , "containers not found in pod stats: %v" , strings .Join (missingContainerNames , " " ))
538
+ if len (missingContainerNames ) > 0 {
539
+ assert .FailNow (t , "containers not found in pod stats" )
540
+ }
541
+ }
542
+
508
543
func checkEphemeralStats (t * testing.T , label string , containerSeeds []int , volumeSeeds []int , containerLogStats []* volume.Metrics , stats * statsapi.FsStats ) {
509
544
var usedBytes , inodeUsage int
510
545
for _ , cseed := range containerSeeds {
0 commit comments