...
1
16
17 package stats
18
19 import (
20 "reflect"
21 "testing"
22
23 cadvisorapiv2 "github.com/google/cadvisor/info/v2"
24
25 kubecontainertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
26
27 "k8s.io/apimachinery/pkg/types"
28 statsapi "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
29 )
30
31 func Test_hostStatsProvider_getPodEtcHostsStats(t *testing.T) {
32 tests := []struct {
33 name string
34 podEtcHostsPathFunc PodEtcHostsPathFunc
35 podUID types.UID
36 rootFsInfo *cadvisorapiv2.FsInfo
37 want *statsapi.FsStats
38 wantErr bool
39 }{
40 {
41 name: "Should return nil for runtimes that do not support etc host file",
42 podEtcHostsPathFunc: func(podUID types.UID) string {
43 return ""
44 },
45 podUID: "fake0001",
46 rootFsInfo: nil,
47 want: nil,
48 wantErr: false,
49 },
50 }
51 for _, tt := range tests {
52 t.Run(tt.name, func(t *testing.T) {
53 h := hostStatsProvider{
54 osInterface: &kubecontainertest.FakeOS{},
55 podEtcHostsPathFunc: tt.podEtcHostsPathFunc,
56 }
57 got, err := h.getPodEtcHostsStats(tt.podUID, tt.rootFsInfo)
58 if (err != nil) != tt.wantErr {
59 t.Errorf("getPodEtcHostsStats() error = %v, wantErr %v", err, tt.wantErr)
60 return
61 }
62 if !reflect.DeepEqual(got, tt.want) {
63 t.Errorf("getPodEtcHostsStats() got = %v, want %v", got, tt.want)
64 }
65 })
66 }
67 }
68
View as plain text