github.com/google/cadvisor@v0.49.1/container/common/container_hints_test.go (about) 1 // Copyright 2014 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package common 16 17 import ( 18 "testing" 19 ) 20 21 func TestGetContainerHintsFromFile(t *testing.T) { 22 cHints, err := GetContainerHintsFromFile("test_resources/container_hints.json") 23 24 if err != nil { 25 t.Fatalf("Error in unmarshalling: %s", err) 26 } 27 28 if cHints.AllHosts[0].NetworkInterface.VethHost != "veth24031eth1" && 29 cHints.AllHosts[0].NetworkInterface.VethChild != "eth1" { 30 t.Errorf("Cannot find network interface in %+v", cHints) 31 } 32 33 correctMountDirs := [...]string{ 34 "/var/run/nm-sdc1", 35 "/var/run/nm-sdb3", 36 "/var/run/nm-sda3", 37 "/var/run/netns/root", 38 "/var/run/openvswitch/db.sock", 39 } 40 41 if len(cHints.AllHosts[0].Mounts) == 0 { 42 t.Errorf("Cannot find any mounts") 43 } 44 45 for i, mountDir := range cHints.AllHosts[0].Mounts { 46 if correctMountDirs[i] != mountDir.HostDir { 47 t.Errorf("Cannot find mount %s in %+v", mountDir.HostDir, cHints) 48 } 49 } 50 } 51 52 func TestFileNotExist(t *testing.T) { 53 _, err := GetContainerHintsFromFile("/file_does_not_exist.json") 54 if err != nil { 55 t.Fatalf("GetContainerHintsFromFile must not error for blank file: %s", err) 56 } 57 }