(t *testing.T)
| 2683 | } |
| 2684 | |
| 2685 | func TestConnectWithSimplifiedURLs(t *testing.T) { |
| 2686 | urls := []string{ |
| 2687 | "nats://127.0.0.1:4222", |
| 2688 | "nats://127.0.0.1:", |
| 2689 | "nats://127.0.0.1", |
| 2690 | "127.0.0.1:", |
| 2691 | "127.0.0.1", |
| 2692 | } |
| 2693 | |
| 2694 | connect := func(t *testing.T, url string, useRootCA bool) { |
| 2695 | t.Helper() |
| 2696 | var opt nats.Option |
| 2697 | if useRootCA { |
| 2698 | opt = nats.RootCAs("./configs/certs/ca.pem") |
| 2699 | } |
| 2700 | nc, err := nats.Connect(url, opt) |
| 2701 | if err != nil { |
| 2702 | t.Fatalf("URL %q expected to connect, got %v", url, err) |
| 2703 | } |
| 2704 | nc.Close() |
| 2705 | } |
| 2706 | |
| 2707 | // Start a server that listens on default port 4222. |
| 2708 | s := RunDefaultServer() |
| 2709 | defer s.Shutdown() |
| 2710 | |
| 2711 | // Try for every connection in the urls array. |
| 2712 | for _, u := range urls { |
| 2713 | connect(t, u, false) |
| 2714 | } |
| 2715 | |
| 2716 | s.Shutdown() |
| 2717 | |
| 2718 | // Use this to build the options for us... |
| 2719 | s, opts := RunServerWithConfig("configs/tls.conf") |
| 2720 | s.Shutdown() |
| 2721 | // Now change listen port to 4222 and remove auth |
| 2722 | opts.Port = 4222 |
| 2723 | opts.Username = "" |
| 2724 | opts.Password = "" |
| 2725 | // and restart the server |
| 2726 | s = RunServerWithOptions(opts) |
| 2727 | defer s.Shutdown() |
| 2728 | |
| 2729 | // Test again against a server that wants TLS and check |
| 2730 | // that we automatically switch to Secure. |
| 2731 | for _, u := range urls { |
| 2732 | connect(t, u, true) |
| 2733 | } |
| 2734 | } |
| 2735 | |
| 2736 | func TestNilOpts(t *testing.T) { |
| 2737 | s := RunDefaultServer() |
nothing calls this directly
no test coverage detected