/** TestIptablesSync checks if iptable rules are beeing synced with stored state */
TestIptablesSync checks if iptable rules are beeing synced with stored state
/ ** TestIptablesSync checks if iptable rules are beeing synced with stored state * /
func TestIptablesSync(t *testing.T) {
	if os.Getenv("TRAVIS") == "true" {
		t.Skip("Skipping test because travis-ci do not allow iptables")
	}
	iptablesMngr, err := New(defaultConfig())
	assert.Nil(t, err)
	err = exec.Command(iptablesMngr.path, "--wait", "-t", "nat", "-F", "FUSIS").Run()
	assert.Nil(t, err)
	s1 := types.Service{
		Name:     "test",
		Address:  "10.0.1.1",
		Port:     80,
		Mode:     "nat",
		Protocol: "tcp",
	}
	s2 := types.Service{
		Name:     "test2",
		Address:  "10.0.1.2",
		Port:     80,
		Protocol: "tcp",
		Mode:     "nat",
	}
	state := &mocks.State{}
	state.On("GetServices").Return([]types.Service{s1, s2})
	toSource, err := net.GetIpByInterface("lo")
	assert.Nil(t, err)
	rule2 := SnatRule{
		vaddr:    "10.0.1.2",
		vport:    "80",
		toSource: toSource,
	}
	rule3 := SnatRule{
		vaddr:    "10.0.1.3",
		vport:    "80",
		toSource: toSource,
	}
	err = iptablesMngr.addRule(rule2)
	assert.Nil(t, err)
	err = iptablesMngr.addRule(rule3)
	assert.Nil(t, err)
	err = iptablesMngr.Sync(state)
	assert.Nil(t, err)
	rules, err := iptablesMngr.getKernelRulesSet()
	assert.Nil(t, err)
	rule1, err := iptablesMngr.serviceToSnatRule(s1)
	assert.Nil(t, err)
	assert.Equal(t, true, rules.Contains(rule2, *rule1))
}
func TestIptablesSync ( t * testing . T ) { if os . Getenv ( " " ) == " " { t . Skip ( " " ) } iptablesMngr , err := New ( defaultConfig ( ) ) assert . Nil ( t , err ) err = exec . Command ( iptablesMngr . path , " " , " " , " " , " " , " " ) . Run ( ) assert . Nil ( t , err ) s1 := types . Service { Name : " " , Address : " " , Port : 80 , Mode : " " , Protocol : " " , } s2 := types . Service { Name : " " , Address : " " , Port : 80 , Protocol : " " , Mode : " " , } state := & mocks . State { } state . On ( " " ) . Return ( [ ] types . Service { s1 , s2 } ) toSource , err := net . GetIpByInterface ( " " ) assert . Nil ( t , err ) rule2 := SnatRule { vaddr : " " , vport : " " , toSource : toSource , } rule3 := SnatRule { vaddr : " " , vport : " " , toSource : toSource , } err = iptablesMngr . addRule ( rule2 ) assert . Nil ( t , err ) err = iptablesMngr . addRule ( rule3 ) assert . Nil ( t , err ) err = iptablesMngr . Sync ( state ) assert . Nil ( t , err ) rules , err := iptablesMngr . getKernelRulesSet ( ) assert . Nil ( t , err ) rule1 , err := iptablesMngr . serviceToSnatRule ( s1 ) assert . Nil ( t , err ) assert . Equal ( t , true , rules . Contains ( rule2 , * rule1 ) ) }
TestIptablesSync checks if iptable rules are beeing synced with stored state
TestIptablesSync checks if iptable rules are beeing synced with stored state
// create iptablesMngr based on mocked config // ensure the FUSIS chain is empty, flushed