(t *testing.T)
| 103 | } |
| 104 | |
| 105 | func TestRun_ConfigFileWithPeers(t *testing.T) { |
| 106 | ctx, cancel := context.WithCancel(context.Background()) |
| 107 | |
| 108 | proxy1Addr, proxy2Addr := testAddr, generateTestAddr(testAddr, 1) |
| 109 | clusterPort, clusterAddr, proxy1BindAddr, httpBindAddr := generateTestAddrs(proxy1Addr) |
| 110 | cluster := proxycore.NewMockCluster(net.ParseIP(testStartAddr), clusterPort) |
| 111 | |
| 112 | defer cluster.Shutdown() |
| 113 | err := cluster.Add(ctx, 1) |
| 114 | require.NoError(t, err) |
| 115 | |
| 116 | configFileName, err := writeTempYaml(struct { |
| 117 | Bind string |
| 118 | Port int |
| 119 | RPCAddr string `yaml:"rpc-address"` |
| 120 | DataCenter string `yaml:"data-center"` |
| 121 | ContactPoints []string `yaml:"contact-points"` |
| 122 | HealthCheck bool `yaml:"health-check"` |
| 123 | HttpBind string `yaml:"http-bind"` |
| 124 | Peers []PeerConfig |
| 125 | }{ |
| 126 | Bind: proxy1BindAddr, |
| 127 | RPCAddr: proxy1Addr, |
| 128 | DataCenter: "dc-1", |
| 129 | Port: clusterPort, |
| 130 | ContactPoints: []string{clusterAddr}, |
| 131 | HealthCheck: true, |
| 132 | HttpBind: httpBindAddr, |
| 133 | Peers: []PeerConfig{{ |
| 134 | RPCAddr: proxy1Addr, |
| 135 | DC: "dc-1", |
| 136 | }, { |
| 137 | RPCAddr: proxy2Addr, |
| 138 | DC: "dc-2", |
| 139 | }}, |
| 140 | }) |
| 141 | |
| 142 | var wg sync.WaitGroup |
| 143 | wg.Add(1) |
| 144 | |
| 145 | go func() { |
| 146 | rc := Run(ctx, []string{ |
| 147 | "--config", configFileName, |
| 148 | }) |
| 149 | assert.Equal(t, 0, rc) |
| 150 | wg.Done() |
| 151 | }() |
| 152 | |
| 153 | defer func() { |
| 154 | cancel() |
| 155 | wg.Wait() |
| 156 | }() |
| 157 | |
| 158 | require.True(t, waitUntil(10*time.Second, func() bool { |
| 159 | return checkLiveness(httpBindAddr) |
| 160 | })) |
| 161 | |
| 162 | cl := connectTestClient(t, ctx, proxy1BindAddr) |
nothing calls this directly
no test coverage detected