| 500 | } |
| 501 | |
| 502 | func TestWSNoMixingScheme(t *testing.T) { |
| 503 | // Check opts.Connect() first |
| 504 | for _, test := range []struct { |
| 505 | url string |
| 506 | servers []string |
| 507 | }{ |
| 508 | {"ws://127.0.0.1:1234", []string{"nats://127.0.0.1:1235"}}, |
| 509 | {"ws://127.0.0.1:1234", []string{"ws://127.0.0.1:1235", "nats://127.0.0.1:1236"}}, |
| 510 | {"ws://127.0.0.1:1234", []string{"wss://127.0.0.1:1235", "nats://127.0.0.1:1236"}}, |
| 511 | {"wss://127.0.0.1:1234", []string{"nats://127.0.0.1:1235"}}, |
| 512 | {"wss://127.0.0.1:1234", []string{"wss://127.0.0.1:1235", "nats://127.0.0.1:1236"}}, |
| 513 | {"wss://127.0.0.1:1234", []string{"ws://127.0.0.1:1235", "nats://127.0.0.1:1236"}}, |
| 514 | } { |
| 515 | t.Run("Options", func(t *testing.T) { |
| 516 | opts := GetDefaultOptions() |
| 517 | opts.Url = test.url |
| 518 | opts.Servers = test.servers |
| 519 | nc, err := opts.Connect() |
| 520 | if err == nil || !strings.Contains(err.Error(), "mixing") { |
| 521 | if nc != nil { |
| 522 | nc.Close() |
| 523 | } |
| 524 | t.Fatalf("Expected error about mixing, got %v", err) |
| 525 | } |
| 526 | }) |
| 527 | } |
| 528 | // Check Connect() now. |
| 529 | for _, test := range []struct { |
| 530 | urls string |
| 531 | servers []string |
| 532 | }{ |
| 533 | {"ws://127.0.0.1:1234,nats://127.0.0.1:1235", nil}, |
| 534 | {"ws://127.0.0.1:1234,tcp://127.0.0.1:1235", nil}, |
| 535 | {"ws://127.0.0.1:1234,tls://127.0.0.1:1235", nil}, |
| 536 | {"nats://127.0.0.1:1234,ws://127.0.0.1:1235", nil}, |
| 537 | {"nats://127.0.0.1:1234,wss://127.0.0.1:1235", nil}, |
| 538 | {"nats://127.0.0.1:1234,tls://127.0.0.1:1235,ws://127.0.0.1:1236", nil}, |
| 539 | {"nats://127.0.0.1:1234,tls://127.0.0.1:1235,wss://127.0.0.1:1236", nil}, |
| 540 | // In Connect(), the URL is ignored when Servers() is provided. |
| 541 | {"", []string{"nats://127.0.0.1:1235", "ws://127.0.0.1:1236"}}, |
| 542 | {"", []string{"nats://127.0.0.1:1235", "wss://127.0.0.1:1236"}}, |
| 543 | {"", []string{"ws://127.0.0.1:1235", "nats://127.0.0.1:1236"}}, |
| 544 | {"", []string{"wss://127.0.0.1:1235", "nats://127.0.0.1:1236"}}, |
| 545 | } { |
| 546 | t.Run("Connect", func(t *testing.T) { |
| 547 | var opt Option |
| 548 | if len(test.servers) > 0 { |
| 549 | opt = func(o *Options) error { |
| 550 | o.Servers = test.servers |
| 551 | return nil |
| 552 | } |
| 553 | } |
| 554 | nc, err := Connect(test.urls, opt) |
| 555 | if err == nil || !strings.Contains(err.Error(), "mixing") { |
| 556 | if nc != nil { |
| 557 | nc.Close() |
| 558 | } |
| 559 | t.Fatalf("Expected error about mixing, got %v", err) |