github.com/imran-kn/cilium-fork@v1.6.9/pkg/policy/identifier_test.go (about) 1 // Copyright 2019 Authors of Cilium 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 // +build !privileged_tests 16 17 package policy 18 19 import ( 20 "sync" 21 22 "github.com/cilium/cilium/pkg/identity" 23 24 . "gopkg.in/check.v1" 25 ) 26 27 type DummyEndpoint struct { 28 rev uint64 29 } 30 31 func (d *DummyEndpoint) GetID16() uint16 { 32 return 0 33 } 34 35 func (d *DummyEndpoint) GetSecurityIdentity() *identity.Identity { 36 return nil 37 } 38 39 func (d *DummyEndpoint) PolicyRevisionBumpEvent(rev uint64) { 40 d.rev = rev 41 } 42 43 func (d *DummyEndpoint) RLockAlive() error { 44 return nil 45 } 46 47 func (d *DummyEndpoint) RUnlock() { 48 } 49 50 func (ds *PolicyTestSuite) TestNewEndpointSet(c *C) { 51 d := &DummyEndpoint{} 52 epSet := NewEndpointSet(map[Endpoint]struct{}{ 53 d: {}, 54 }) 55 c.Assert(epSet.Len(), Equals, 1) 56 epSet.Delete(d) 57 c.Assert(epSet.Len(), Equals, 0) 58 } 59 60 func (ds *PolicyTestSuite) TestForEach(c *C) { 61 var wg sync.WaitGroup 62 63 d0 := &DummyEndpoint{} 64 d1 := &DummyEndpoint{} 65 66 epSet := NewEndpointSet(map[Endpoint]struct{}{ 67 d0: {}, 68 d1: {}, 69 }) 70 epSet.ForEachGo(&wg, func(e Endpoint) { 71 e.PolicyRevisionBumpEvent(100) 72 }) 73 74 wg.Wait() 75 76 c.Assert(d0.rev, Equals, uint64(100)) 77 c.Assert(d1.rev, Equals, uint64(100)) 78 }