| 1 | // Copyright 2015 CNI authors |
| 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 testingscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/ |
| 16 | |
| 17 | import ( |
| 18 | "netscip-go gomod github.com/golang/go/src go1.24.2 net/" |
| 19 | "osscip-go gomod github.com/golang/go/src go1.24.2 os/" |
| 20 | |
| 21 | "github.com/containernetworking/plugins/plugins/ipam/host-local/backendscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/" |
| 22 | ) |
| 23 | |
| 24 | type FakeStorescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore# struct { |
| 25 | ipMapscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#ipMap. map[string]string |
| 26 | lastReservedIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#lastReservedIP. map[string]netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPscip-go gomod github.com/golang/go/src go1.24.2 net/IP# |
| 27 | } |
| 28 | |
| 29 | // FakeStore implements the Store interface |
| 30 | var _ backendscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/.Storescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/Store# = &FakeStorescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#{} |
| 31 | |
| 32 | func NewFakeStorescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/NewFakeStore().(ipmap map[string]string, lastIPs map[string]netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPscip-go gomod github.com/golang/go/src go1.24.2 net/IP#) *FakeStorescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore# { |
| 33 | return &FakeStorescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#{ipmap, lastIPs} |
| 34 | } |
| 35 | |
| 36 | func (s *FakeStorescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#) Lockscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#Lock().() error { |
| 37 | return nil |
| 38 | } |
| 39 | |
| 40 | func (s *FakeStorescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#) Unlockscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#Unlock().() error { |
| 41 | return nil |
| 42 | } |
| 43 | |
| 44 | func (s *FakeStorescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#) Closescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#Close().() error { |
| 45 | return nil |
| 46 | } |
| 47 | |
| 48 | func (s *FakeStorescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#) Reservescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#Reserve().(id string, _ string, ip netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPscip-go gomod github.com/golang/go/src go1.24.2 net/IP#, rangeID string) (bool, error) { |
| 49 | key := ip.Stringscip-go gomod github.com/golang/go/src go1.24.2 net/IP#String().() |
| 50 | if _, ok := s.ipMapscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#ipMap.[key]; !ok { |
| 51 | s.ipMapscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#ipMap.[key] = id |
| 52 | s.lastReservedIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#lastReservedIP.[rangeID] = ip |
| 53 | return true, nil |
| 54 | } |
| 55 | return false, nil |
| 56 | } |
| 57 | |
| 58 | func (s *FakeStorescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#) LastReservedIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#LastReservedIP().(rangeID string) (netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPscip-go gomod github.com/golang/go/src go1.24.2 net/IP#, error) { |
| 59 | ip, ok := s.lastReservedIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#lastReservedIP.[rangeID] |
| 60 | if !ok { |
| 61 | return nil, osscip-go gomod github.com/golang/go/src go1.24.2 os/.ErrNotExistscip-go gomod github.com/golang/go/src go1.24.2 os/ErrNotExist. |
| 62 | } |
| 63 | return ip, nil |
| 64 | } |
| 65 | |
| 66 | func (s *FakeStorescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#) ReleaseByIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#ReleaseByID().(id string, _ string) error { |
| 67 | toDelete := []string{} |
| 68 | for k, v := range s.ipMapscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#ipMap. { |
| 69 | if v == id { |
| 70 | toDelete = append(toDelete, k) |
| 71 | } |
| 72 | } |
| 73 | for _, ip := range toDelete { |
| 74 | delete(s.ipMapscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#ipMap., ip) |
| 75 | } |
| 76 | return nil |
| 77 | } |
| 78 | |
| 79 | func (s *FakeStorescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#) GetByIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#GetByID().(id string, _ string) []netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPscip-go gomod github.com/golang/go/src go1.24.2 net/IP# { |
| 80 | var ips []netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPscip-go gomod github.com/golang/go/src go1.24.2 net/IP# |
| 81 | for k, v := range s.ipMapscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#ipMap. { |
| 82 | if v == id { |
| 83 | ips = append(ips, netscip-go gomod github.com/golang/go/src go1.24.2 net/.ParseIPscip-go gomod github.com/golang/go/src go1.24.2 net/ParseIP().(k)) |
| 84 | } |
| 85 | } |
| 86 | return ips |
| 87 | } |
| 88 | |
| 89 | func (s *FakeStorescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#) SetIPMapscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#SetIPMap().(m map[string]string) { |
| 90 | s.ipMapscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing`/FakeStore#ipMap. = m |
| 91 | } |