@@ -125,111 +125,14 @@ func TestWriteNetdevConfig(t *testing.T) {
125125 })
126126}
127127
128- func TestWriteEndpointConfig (t * testing.T ) {
129- writeConfig (t , "endpoint" , func (w io.Writer , dp datapath.ConfigWriter ) error {
130- return dp .WriteEndpointConfig (w , & dummyNodeCfg , & dummyEPCfg )
131- })
132-
133- // Create copy of config option so that it can be restored at the end of
134- // this test. In the future, we'd like to parallelize running unit tests.
135- // As it stands, this test would not be ready to parallelize until we
136- // remove our dependency on globals (e.g. option.Config).
137- oldEnableIPv6 := option .Config .EnableIPv6
138- defer func () {
139- option .Config .EnableIPv6 = oldEnableIPv6
140- }()
141-
142- testRun := func (te * testutils.TestEndpoint ) ([]byte , map [string ]uint64 ) {
143- cfg := & HeaderfileWriter {}
144- varSub := loader .ELFVariableSubstitutions (te )
145-
146- var buf bytes.Buffer
147- cfg .writeStaticData (nil , & buf , te )
148-
149- return buf .Bytes (), varSub
150- }
151-
152- lxcIPs := []string {"LXC_IP_1" , "LXC_IP_2" }
153-
154- tests := []struct {
155- description string
156- template testutils.TestEndpoint // Represents template bpf prog
157- endpoint testutils.TestEndpoint // Represents normal endpoint bpf prog
158- preTestRun func (t * testutils.TestEndpoint , e * testutils.TestEndpoint )
159- templateExp bool
160- endpointExp bool
161- }{
162- {
163- description : "IPv6 is disabled, endpoint does not have an IPv6 addr" ,
164- template : testutils .NewTestEndpoint (),
165- endpoint : testutils .NewTestEndpoint (),
166- preTestRun : func (t * testutils.TestEndpoint , e * testutils.TestEndpoint ) {
167- option .Config .EnableIPv6 = false
168- t .IPv6 = ipv6DummyAddr // Template bpf prog always has dummy IPv6
169- e .IPv6 = netip.Addr {} // This endpoint does not have an IPv6 addr
170- },
171- templateExp : true ,
172- endpointExp : false ,
173- },
174- {
175- description : "IPv6 is disabled, endpoint does have an IPv6 addr" ,
176- template : testutils .NewTestEndpoint (),
177- endpoint : testutils .NewTestEndpoint (),
178- preTestRun : func (t * testutils.TestEndpoint , e * testutils.TestEndpoint ) {
179- option .Config .EnableIPv6 = false
180- t .IPv6 = ipv6DummyAddr // Template bpf prog always has dummy IPv6
181- e .IPv6 = ipv6DummyAddr // This endpoint does have an IPv6 addr
182- },
183- templateExp : true ,
184- endpointExp : true ,
185- },
186- {
187- description : "IPv6 is enabled" ,
188- template : testutils .NewTestEndpoint (),
189- endpoint : testutils .NewTestEndpoint (),
190- preTestRun : func (t * testutils.TestEndpoint , e * testutils.TestEndpoint ) {
191- option .Config .EnableIPv6 = true
192- t .IPv6 = ipv6DummyAddr
193- e .IPv6 = ipv6DummyAddr
194- },
195- templateExp : true ,
196- endpointExp : true ,
197- },
198- {
199- description : "IPv6 is enabled, endpoint does not have IPv6 address" ,
200- template : testutils .NewTestEndpoint (),
201- endpoint : testutils .NewTestEndpoint (),
202- preTestRun : func (t * testutils.TestEndpoint , e * testutils.TestEndpoint ) {
203- option .Config .EnableIPv6 = true
204- t .IPv6 = ipv6DummyAddr
205- e .IPv6 = netip.Addr {}
206- },
207- templateExp : true ,
208- endpointExp : false ,
209- },
210- }
211- for _ , test := range tests {
212- t .Logf ("Testing %s" , test .description )
213- test .preTestRun (& test .template , & test .endpoint )
214-
215- b , vsub := testRun (& test .template )
216- require .Equal (t , test .templateExp , bytes .Contains (b , []byte ("DEFINE_IPV6" )))
217- assertKeysInsideMap (t , vsub , lxcIPs , test .templateExp )
218-
219- b , vsub = testRun (& test .endpoint )
220- require .Equal (t , test .endpointExp , bytes .Contains (b , []byte ("DEFINE_IPV6" )))
221- assertKeysInsideMap (t , vsub , lxcIPs , test .endpointExp )
222- }
223- }
224-
225128func TestWriteStaticData (t * testing.T ) {
226129 cfg := & HeaderfileWriter {}
227130 ep := & dummyEPCfg
228131
229132 mapSub := loader .ELFMapSubstitutions (ep )
230133
231134 var buf bytes.Buffer
232- cfg .writeStaticData (nil , & buf , ep )
135+ cfg .writeStaticData (& buf , ep )
233136 b := buf .Bytes ()
234137
235138 for _ , v := range mapSub {
@@ -238,13 +141,6 @@ func TestWriteStaticData(t *testing.T) {
238141 }
239142}
240143
241- func assertKeysInsideMap (t * testing.T , m map [string ]uint64 , keys []string , want bool ) {
242- for _ , v := range keys {
243- _ , ok := m [v ]
244- require .Equal (t , want , ok )
245- }
246- }
247-
248144func createMainLink (name string , t * testing.T ) * netlink.Dummy {
249145 link := & netlink.Dummy {
250146 LinkAttrs : netlink.LinkAttrs {
0 commit comments