11package main
22
33import (
4+ "os"
45 "testing"
56
7+ "github.com/AliyunContainerService/terway/pkg/utils/nodecap"
68 "github.com/Jeffail/gabs/v2"
79 "github.com/stretchr/testify/assert"
810)
@@ -202,6 +204,8 @@ func TestVeth(t *testing.T) {
202204 _switchDataPathV2 = func () bool {
203205 return true
204206 }
207+
208+ _ = os .Remove (nodeCapabilitiesFile )
205209 out , err := mergeConfigList ([][]byte {
206210 []byte (`{
207211 "type":"terway",
@@ -225,6 +229,8 @@ func TestVethWithNoPolicy(t *testing.T) {
225229 _switchDataPathV2 = func () bool {
226230 return true
227231 }
232+
233+ _ = os .Remove (nodeCapabilitiesFile )
228234 out , err := mergeConfigList ([][]byte {
229235 []byte (`{
230236 "type":"terway",
@@ -249,6 +255,8 @@ func TestVethToDatapathV2(t *testing.T) {
249255 _switchDataPathV2 = func () bool {
250256 return true
251257 }
258+
259+ _ = os .Remove (nodeCapabilitiesFile )
252260 out , err := mergeConfigList ([][]byte {
253261 []byte (`{
254262 "type":"terway",
@@ -269,3 +277,34 @@ func TestVethToDatapathV2(t *testing.T) {
269277 assert .Equal (t , "datapathv2" , g .Path ("plugins.0.eniip_virtual_type" ).Data ())
270278 assert .Equal (t , "cilium-cni" , g .Path ("plugins.1.type" ).Data ())
271279}
280+
281+ func TestVethNotAllowToSwitch (t * testing.T ) {
282+ _switchDataPathV2 = func () bool {
283+ return true
284+ }
285+
286+ _ = os .Remove (nodeCapabilitiesFile )
287+ store := nodecap .NewFileNodeCapabilities (nodeCapabilitiesFile )
288+ store .Set (nodecap .NodeCapabilityHasCiliumChainer , False )
289+ err := store .Save ()
290+ assert .NoError (t , err )
291+
292+ out , err := mergeConfigList ([][]byte {
293+ []byte (`{
294+ "type":"terway",
295+ "foo":"bar",
296+ "network_policy_provider": "ebpf"
297+ }` )}, & feature {
298+ EBPF : true ,
299+ EDT : true ,
300+ EnableNetworkPolicy : true ,
301+ })
302+ assert .NoError (t , err )
303+
304+ g , err := gabs .ParseJSON ([]byte (out ))
305+ assert .NoError (t , err )
306+
307+ assert .Equal (t , "terway" , g .Path ("plugins.0.type" ).Data ())
308+ assert .Equal (t , 1 , len (g .Path ("plugins" ).Children ()))
309+ assert .Equal (t , "veth" , g .Path ("plugins.0.eniip_virtual_type" ).Data ())
310+ }
0 commit comments