github.com/google/cadvisor@v0.49.1/container/crio/client_test.go (about) 1 // Copyright 2017 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 crio 16 17 import "fmt" 18 19 type crioClientMock struct { 20 info Info 21 containersInfo map[string]*ContainerInfo 22 err error 23 } 24 25 func (c *crioClientMock) Info() (Info, error) { 26 if c.err != nil { 27 return Info{}, c.err 28 } 29 return c.info, nil 30 } 31 32 func (c *crioClientMock) ContainerInfo(id string) (*ContainerInfo, error) { 33 if c.err != nil { 34 return nil, c.err 35 } 36 cInfo, ok := c.containersInfo[id] 37 if !ok { 38 return nil, fmt.Errorf("no container with id %s", id) 39 } 40 return cInfo, nil 41 } 42 43 func mockCrioClient(info Info, containersInfo map[string]*ContainerInfo, err error) CrioClient { 44 return &crioClientMock{ 45 err: err, 46 info: info, 47 containersInfo: containersInfo, 48 } 49 }