TestEditBackend should be executed with sudo
(t *testing.T)
| 31 | |
| 32 | // TestEditBackend should be executed with sudo |
| 33 | func TestDataplanesBackend(t *testing.T) { |
| 34 | // To run this test make sure HAProxy is installed on the machine and |
| 35 | // configs/haproxy.cfg is placed in /etc/haproxy/ folder |
| 36 | api := NewHAProxyAPI("dummy") |
| 37 | |
| 38 | api.DeleteAllDataplanes() |
| 39 | if k, _ := api.ListDataplanes(); len(k) != 0 { |
| 40 | t.Fatal("List of data planes should be empty.") |
| 41 | } |
| 42 | time.Sleep(5 * time.Second) |
| 43 | |
| 44 | api.AddDataplane("127.0.0.1", 8080, true) |
| 45 | if _, addresses := api.ListDataplanes(); addresses[0] != "127.0.0.1:8080" { |
| 46 | t.Fatal("Failed to add server 127.0.0.1:8080.") |
| 47 | } |
| 48 | time.Sleep(5 * time.Second) |
| 49 | |
| 50 | api.AddDataplane("127.0.0.1", 8090, true) |
| 51 | _, addresses := api.ListDataplanes() |
| 52 | if !((addresses[0] == "127.0.0.1:8080" && addresses[1] == "127.0.0.1:8090") || |
| 53 | (addresses[0] == "127.0.0.1:8090" && addresses[1] == "127.0.0.1:8080")) { |
| 54 | |
| 55 | t.Fatal("Failed to add server 127.0.0.1:8090") |
| 56 | } |
| 57 | time.Sleep(5 * time.Second) |
| 58 | |
| 59 | api.ReviseDataplanes([]string{"127.0.0.1:8080", "127.0.0.1:9000"}) |
| 60 | _, addresses = api.ListDataplanes() |
| 61 | if !((addresses[0] == "127.0.0.1:8080" && addresses[1] == "127.0.0.1:9000") || |
| 62 | (addresses[0] == "127.0.0.1:9000" && addresses[1] == "127.0.0.1:8080")) { |
| 63 | |
| 64 | t.Fatal("Failed to revise data plane (throw out 8090 and keep 8080 and 9000)") |
| 65 | } |
| 66 | time.Sleep(5 * time.Second) |
| 67 | |
| 68 | api.RemoveDataplane("127.0.0.1", 8080, true) |
| 69 | api.RemoveDataplane("127.0.0.1", 9000, true) |
| 70 | if k, _ := api.ListDataplanes(); len(k) != 0 { |
| 71 | t.Error("List of data planes should be empty.") |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // TestRegistrationServerBackend should be executed with sudo |
| 76 | func TestRegistrationServerBackend(t *testing.T) { |
nothing calls this directly
no test coverage detected