(t *testing.T)
| 1145 | } |
| 1146 | |
| 1147 | func TestConnServers(t *testing.T) { |
| 1148 | opts := GetDefaultOptions() |
| 1149 | c := &Conn{Opts: opts} |
| 1150 | c.ps = &parseState{} |
| 1151 | c.setupServerPool() |
| 1152 | |
| 1153 | validateURLs := func(serverUrls []string, expectedUrls ...string) { |
| 1154 | var found bool |
| 1155 | if len(serverUrls) != len(expectedUrls) { |
| 1156 | stackFatalf(t, "Array should have %d elements, has %d", len(expectedUrls), len(serverUrls)) |
| 1157 | } |
| 1158 | |
| 1159 | for _, ev := range expectedUrls { |
| 1160 | found = false |
| 1161 | for _, av := range serverUrls { |
| 1162 | if ev == av { |
| 1163 | found = true |
| 1164 | break |
| 1165 | } |
| 1166 | } |
| 1167 | if !found { |
| 1168 | stackFatalf(t, "array is missing %q in %v", ev, serverUrls) |
| 1169 | } |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | // check the default url |
| 1174 | validateURLs(c.Servers(), "nats://127.0.0.1:4222") |
| 1175 | if len(c.DiscoveredServers()) != 0 { |
| 1176 | t.Fatalf("Expected no discovered servers") |
| 1177 | } |
| 1178 | |
| 1179 | // Add a new URL |
| 1180 | err := c.parse([]byte("INFO {\"connect_urls\":[\"localhost:5222\"]}\r\n")) |
| 1181 | if err != nil { |
| 1182 | t.Fatalf("Unexpected: %d : %v\n", c.ps.state, err) |
| 1183 | } |
| 1184 | // Server list should now contain both the default and the new url. |
| 1185 | validateURLs(c.Servers(), "nats://127.0.0.1:4222", "nats://localhost:5222") |
| 1186 | // Discovered servers should only contain the new url. |
| 1187 | validateURLs(c.DiscoveredServers(), "nats://localhost:5222") |
| 1188 | |
| 1189 | // verify user credentials are stripped out. |
| 1190 | opts.Servers = []string{"nats://user:pass@localhost:4333", "nats://token@localhost:4444"} |
| 1191 | c = &Conn{Opts: opts} |
| 1192 | c.ps = &parseState{} |
| 1193 | c.setupServerPool() |
| 1194 | |
| 1195 | validateURLs(c.Servers(), "nats://localhost:4333", "nats://localhost:4444") |
| 1196 | } |
| 1197 | |
| 1198 | func TestIgnoreDiscoveredServers(t *testing.T) { |
| 1199 | opts := GetDefaultOptions() |
nothing calls this directly
no test coverage detected