Debian Codegraph @

plugins/ipam/dhcp/options_test.go

raw symbols SCIP
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 mainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/
16
17 import (
18 "netscip-go gomod github.com/golang/go/src go1.24.2 net/"
19 "reflectscip-go gomod github.com/golang/go/src go1.24.2 reflect/"
20 "testingscip-go gomod github.com/golang/go/src go1.24.2 testing/"
21
22 dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/ "github.com/insomniacslk/dhcp/dhcpv4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/"
23
24 "github.com/containernetworking/cni/pkg/typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/"
25 )
26
27 func validateRoutesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/validateRoutes().(t *testingscip-go gomod github.com/golang/go/src go1.24.2 testing/.Tscip-go gomod github.com/golang/go/src go1.24.2 testing/T#, routes []*typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.Routescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#) {
28 expected := []*typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.Routescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#{
29 {
30 Dstscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#Dst.: netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPNetscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#{
31 IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP.: netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPv4scip-go gomod github.com/golang/go/src go1.24.2 net/IPv4().(10, 0, 0, 0),
32 Maskscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Mask.: netscip-go gomod github.com/golang/go/src go1.24.2 net/.CIDRMaskscip-go gomod github.com/golang/go/src go1.24.2 net/CIDRMask().(8, 32),
33 },
34 GWscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#GW.: netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPv4scip-go gomod github.com/golang/go/src go1.24.2 net/IPv4().(10, 1, 2, 3),
35 },
36 {
37 Dstscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#Dst.: netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPNetscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#{
38 IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP.: netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPv4scip-go gomod github.com/golang/go/src go1.24.2 net/IPv4().(192, 168, 1, 0),
39 Maskscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Mask.: netscip-go gomod github.com/golang/go/src go1.24.2 net/.CIDRMaskscip-go gomod github.com/golang/go/src go1.24.2 net/CIDRMask().(24, 32),
40 },
41 GWscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#GW.: netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPv4scip-go gomod github.com/golang/go/src go1.24.2 net/IPv4().(192, 168, 2, 3),
42 },
43 }
44
45 if len(routes) != len(expected) {
46 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.2 testing/common#Fatalf().("wrong length slice; expected %v, got %v", len(expected), len(routes))
47 }
48
49 for i := 0; i < len(routes); i++ {
50 a := routes[i]
51 e := expected[i]
52
53 if a.Dstscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#Dst..Stringscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#String().() != e.Dstscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#Dst..Stringscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#String().() {
54 t.Errorfscip-go gomod github.com/golang/go/src go1.24.2 testing/common#Errorf().("route.Dst mismatch: expected %v, got %v", e.Dstscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#Dst., a.Dstscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#Dst.)
55 }
56
57 if !a.GWscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#GW..Equalscip-go gomod github.com/golang/go/src go1.24.2 net/IP#Equal().(e.GWscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#GW.) {
58 t.Errorfscip-go gomod github.com/golang/go/src go1.24.2 testing/common#Errorf().("route.GW mismatch: expected %v, got %v", e.GWscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#GW., a.GWscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#GW.)
59 }
60 }
61 }
62
63 func TestParseRoutesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/TestParseRoutes().(t *testingscip-go gomod github.com/golang/go/src go1.24.2 testing/.Tscip-go gomod github.com/golang/go/src go1.24.2 testing/T#) {
64 data := []byte{10, 0, 0, 0, 10, 1, 2, 3, 192, 168, 1, 0, 192, 168, 2, 3}
65 routes := parseRoutesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/parseRoutes().(data)
66
67 validateRoutesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/validateRoutes().(t, routes)
68 }
69
70 func TestParseOptionNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/TestParseOptionName().(t *testingscip-go gomod github.com/golang/go/src go1.24.2 testing/.Tscip-go gomod github.com/golang/go/src go1.24.2 testing/T#) {
71 tests := []struct {
72 name string
73 option string
74 want dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.OptionCodescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/OptionCode#
75 wantErr bool
76 }{
77 {
78 "hostname", "host-name", dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.OptionHostNamescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/OptionHostName., false,
79 },
80 {
81 "hostname in number", "12", dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.GenericOptionCodescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/GenericOptionCode#(12), false,
82 },
83 {
84 "random string", "doNotparseMe", dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.OptionPadscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/OptionPad., true,
85 },
86 }
87 for _, tt := range tests {
88 t.Runscip-go gomod github.com/golang/go/src go1.24.2 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24.2 testing/.Tscip-go gomod github.com/golang/go/src go1.24.2 testing/T#) {
89 got, err := parseOptionNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/parseOptionName().(tt.option)
90 if (err != nil) != tt.wantErr {
91 t.Errorfscip-go gomod github.com/golang/go/src go1.24.2 testing/common#Errorf().("parseOptionName() error = %v, wantErr %v", err, tt.wantErr)
92 return
93 }
94 if !reflectscip-go gomod github.com/golang/go/src go1.24.2 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.24.2 reflect/DeepEqual().(got, tt.want) {
95 t.Errorfscip-go gomod github.com/golang/go/src go1.24.2 testing/common#Errorf().("parseOptionName() = %v, want %v", got, tt.want)
96 }
97 })
98 }
99 }