func TestVipsSync(t *testing.T) { 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}) iface := "lo" config := &config.BalancerConfig{ Interfaces: config.Interfaces{ Inbound: iface, Outbound: iface, }, } vipMngr, err := vip.New(config) assert.Nil(t, err) vipMngr.Sync(state) vips, err := net.GetFusisVipsIps(iface) assert.Nil(t, err) assert.Len(t, vips, 2) assert.Contains(t, vips, "10.0.1.1") assert.Contains(t, vips, "10.0.1.2") // Asserting remove state = &mocks.State{} state.On("GetServices").Return([]types.Service{s2}) err = vipMngr.Sync(state) vips, err = net.GetFusisVipsIps(iface) assert.Nil(t, err) assert.Len(t, vips, 1) assert.Contains(t, vips, "10.0.1.2") net.DelVips(iface) }
func (s *NetSuite) TestDelVips(c *C) { err := net.AddIp("192.168.0.1/32", "lo") c.Assert(err, IsNil) err = net.AddIp("192.168.0.2/32", "lo") c.Assert(err, IsNil) err = net.DelVips(s.iface) c.Assert(err, IsNil) addrs, err := net.GetVips(s.iface) c.Assert(err, IsNil) found := false for _, a := range addrs { if a.IPNet.String() == "192.168.0.1/32" || a.IPNet.String() == "192.168.0.2/32" { found = true } } c.Assert(found, Equals, false) }
func (s *NetSuite) TearDownTest(c *C) { net.DelVips("") }
func (s *NetSuite) SetUpTest(c *C) { net.DelVips(s.iface) }