| 1 | // Copyright 2017 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 allocatorscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/ |
| 16 | |
| 17 | import ( |
| 18 | "netscip-go gomod github.com/golang/go/src go1.24.2 net/" |
| 19 | |
| 20 | . "github.com/onsi/ginkgo/v2scip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/" |
| 21 | . "github.com/onsi/gomegascip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/" |
| 22 | ) |
| 23 | |
| 24 | var _ = Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("range sets", func() { |
| 25 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("should detect set membership correctly", func() { |
| 26 | p := RangeSetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#{ |
| 27 | Rangescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#{Subnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Subnet.: mustSubnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/mustSubnet().("192.168.0.0/24")}, |
| 28 | Rangescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#{Subnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Subnet.: mustSubnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/mustSubnet().("172.16.1.0/24")}, |
| 29 | } |
| 30 | |
| 31 | err := p.Canonicalizescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#Canonicalize().() |
| 32 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 33 | |
| 34 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(p.Containsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#Contains().(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#{192, 168, 0, 55})).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeTruescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeTrue().()) |
| 35 | |
| 36 | r, err := p.RangeForscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#RangeFor().(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#{192, 168, 0, 55}) |
| 37 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 38 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(r).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().(&p[0])) |
| 39 | |
| 40 | r, err = p.RangeForscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#RangeFor().(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#{192, 168, 99, 99}) |
| 41 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(r).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeNilscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeNil().()) |
| 42 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(MatchErrorscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/MatchError().("192.168.99.99 not in range set 192.168.0.1-192.168.0.254,172.16.1.1-172.16.1.254")) |
| 43 | }) |
| 44 | |
| 45 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("should discover overlaps within a set", func() { |
| 46 | p := RangeSetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#{ |
| 47 | {Subnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Subnet.: mustSubnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/mustSubnet().("192.168.0.0/20")}, |
| 48 | {Subnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Subnet.: mustSubnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/mustSubnet().("192.168.2.0/24")}, |
| 49 | } |
| 50 | |
| 51 | err := p.Canonicalizescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#Canonicalize().() |
| 52 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(MatchErrorscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/MatchError().("subnets 192.168.0.1-192.168.15.254 and 192.168.2.1-192.168.2.254 overlap")) |
| 53 | }) |
| 54 | |
| 55 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("should discover overlaps outside a set", func() { |
| 56 | p1 := RangeSetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#{ |
| 57 | {Subnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Subnet.: mustSubnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/mustSubnet().("192.168.0.0/20")}, |
| 58 | } |
| 59 | p2 := RangeSetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#{ |
| 60 | {Subnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Subnet.: mustSubnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/mustSubnet().("192.168.2.0/24")}, |
| 61 | } |
| 62 | |
| 63 | p1.Canonicalizescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#Canonicalize().() |
| 64 | p2.Canonicalizescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#Canonicalize().() |
| 65 | |
| 66 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(p1.Overlapsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#Overlaps().(&p2)).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeTruescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeTrue().()) |
| 67 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(p2.Overlapsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#Overlaps().(&p1)).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeTruescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeTrue().()) |
| 68 | }) |
| 69 | }) |