MCPcopy Index your code
hub / github.com/google/seesaw / TestReIPVserver

Function TestReIPVserver

engine/vserver_test.go:1764–1841  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1762}
1763
1764func TestReIPVserver(t *testing.T) {
1765 e := newTestEngine()
1766 vserver := newTestVserver(e)
1767 lbIF := e.lbInterface.(*ncclient.DummyLBInterface)
1768 clusterName := "au-syd"
1769 serviceName := "dns.resolver@au-syd"
1770 tests := []struct {
1771 desc string
1772 file string
1773 health healthcheck.State
1774 wantIPs []string
1775 }{
1776 {desc: "initial", file: "re-ip/config_1.pb", wantIPs: []string{"192.168.36.1"}},
1777 {desc: "re-ip unicast", file: "re-ip/config_2.pb", wantIPs: []string{"192.168.36.5"}},
1778 {desc: "unicast unhealthy", health: healthcheck.StateUnhealthy, wantIPs: []string{"192.168.36.5"}},
1779 {desc: "unicast disabled", file: "re-ip/config_3.pb", wantIPs: nil},
1780 {desc: "re-ip anycast (unhealthy)", file: "re-ip/config_4.pb", wantIPs: nil},
1781 {desc: "anycast health", health: healthcheck.StateHealthy, wantIPs: []string{"192.168.255.1"}},
1782 {desc: "anycast disabled", file: "re-ip/config_5.pb", wantIPs: nil},
1783 {desc: "back to unicast", file: "re-ip/config_1.pb", wantIPs: []string{"192.168.36.1"}},
1784 }
1785 for _, tc := range tests {
1786 log.Infof("Applying config: %s", tc.desc)
1787 if tc.file != "" {
1788 if err := applyConfig(vserver, tc.file, clusterName, serviceName); err != nil {
1789 t.Fatalf("Failed to apply configuration: %v", err)
1790 }
1791 }
1792
1793 if tc.health != healthcheck.StateUnknown {
1794 for k := range vserver.checks {
1795 n := &checkNotification{
1796 key: k,
1797 description: fmt.Sprintf("forced health=%v for step %q", tc.health, tc.desc),
1798 status: healthcheck.Status{State: tc.health},
1799 }
1800 vserver.handleCheckNotification(n)
1801 }
1802 }
1803
1804 wantVIPs := make(map[string]bool)
1805 for _, s := range tc.wantIPs {
1806 wantVIPs[s] = true
1807 }
1808
1809 if seesaw.IsAnycast(vserver.config.IPv4Addr) {
1810 // vserver.vips only tracks unicast VIPs today, so we can only check that
1811 // there are none.
1812 if len(vserver.vips) > 0 {
1813 t.Errorf("vserver(%q).vips = %v, wanted no unicast vips", tc.desc, vserver.vips)
1814 }
1815 } else {
1816 gotVIPs := make(map[string]bool)
1817 for v := range vserver.vips {
1818 gotVIPs[v.IP.String()] = true
1819 }
1820 if diff := pretty.Compare(wantVIPs, gotVIPs); diff != "" {
1821 t.Errorf("vserver(%q).vips unexpected (-want +got):\n%s", tc.desc, diff)

Callers

nothing calls this directly

Calls 6

IsAnycastFunction · 0.92
newTestEngineFunction · 0.85
newTestVserverFunction · 0.85
applyConfigFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected