(t *testing.T)
| 1762 | } |
| 1763 | |
| 1764 | func 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) |
nothing calls this directly
no test coverage detected