1 /* 2 Copyright 2015 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package container 18 19 import "context" 20 21 // TestRuntimeCache embeds runtimeCache with some additional methods for testing. 22 // It must be declared in the container package to have visibility to runtimeCache. 23 // It cannot be in a "..._test.go" file in order for runtime_cache_test.go to have cross-package visibility to it. 24 // (cross-package declarations in test files cannot be used from dot imports if this package is vendored) 25 type TestRuntimeCache struct { 26 runtimeCache 27 } 28 29 // UpdateCacheWithLock updates the cache with the lock. 30 func (r *TestRuntimeCache) UpdateCacheWithLock() error { 31 r.Lock() 32 defer r.Unlock() 33 return r.updateCache(context.Background()) 34 } 35 36 // GetCachedPods returns the cached pods. 37 func (r *TestRuntimeCache) GetCachedPods() []*Pod { 38 r.Lock() 39 defer r.Unlock() 40 return r.pods 41 } 42 43 // NewTestRuntimeCache creates a new instance of TestRuntimeCache. 44 func NewTestRuntimeCache(getter podsGetter) *TestRuntimeCache { 45 return &TestRuntimeCache{ 46 runtimeCache: runtimeCache{ 47 getter: getter, 48 }, 49 } 50 } 51