@@ -20,118 +20,118 @@ import (
2020// This file is for unit tests. Where relevant, prefer to add e2e tests in e2e/*.test.go instead
2121
2222func TestClient_URLParsing (t * testing.T ) {
23- t .Run ("should parse port-only URL format" , func (t * testing.T ) {
24- client := NewClient (& ClientOptions {
25- Connection : UriConnection {URL : "8080" },
26- })
27- if client .actualPort != 8080 {
28- t .Errorf ("Expected port 8080, got %d" , client .actualPort )
29- }
30- if client .actualHost != "localhost" {
31- t .Errorf ("Expected host localhost, got %s" , client .actualHost )
32- }
33- if ! client .isExternalServer {
34- t .Error ("Expected isExternalServer to be true" )
35- }
36- })
37-
38- t .Run ("should parse host:port URL format" , func (t * testing.T ) {
39- client := NewClient (& ClientOptions {
40- Connection : UriConnection {URL : "127.0.0.1:9000" },
41- })
42- if client .actualPort != 9000 || client .actualHost != "127.0.0.1" {
43- t .Errorf ("Expected 127.0.0.1:9000, got %s:%d" , client .actualHost , client .actualPort )
44- }
45- })
46-
47- t .Run ("should parse http://host:port URL format" , func (t * testing.T ) {
48- client := NewClient (& ClientOptions {
49- Connection : UriConnection {URL : "http://localhost:7000" },
50- })
51- if client .actualPort != 7000 || client .actualHost != "localhost" {
52- t .Errorf ("Expected localhost:7000, got %s:%d" , client .actualHost , client .actualPort )
53- }
54- })
55-
56- t .Run ("should parse https://host:port URL format" , func (t * testing.T ) {
57- client := NewClient (& ClientOptions {
58- Connection : UriConnection {URL : "https://example.com:443" },
59- })
60- if client .actualPort != 443 || client .actualHost != "example.com" {
61- t .Errorf ("Expected example.com:443, got %s:%d" , client .actualHost , client .actualPort )
62- }
63- })
23+ t .Run ("should parse port-only URL format" , func (t * testing.T ) {
24+ client := NewClient (& ClientOptions {
25+ Connection : UriConnection {URL : "8080" },
26+ })
27+ if client .actualPort != 8080 {
28+ t .Errorf ("Expected port 8080, got %d" , client .actualPort )
29+ }
30+ if client .actualHost != "localhost" {
31+ t .Errorf ("Expected host localhost, got %s" , client .actualHost )
32+ }
33+ if ! client .isExternalServer {
34+ t .Error ("Expected isExternalServer to be true" )
35+ }
36+ })
6437
65- t .Run ("should panic for invalid URL format" , func (t * testing.T ) {
66- defer func () {
67- if r := recover (); r == nil {
68- t .Error ("Expected panic for invalid URL format" )
69- }
70- }()
71- NewClient (& ClientOptions {Connection : UriConnection {URL : "invalid-url" }})
72- })
73-
74- t .Run ("should panic for invalid port - too high" , func (t * testing.T ) {
75- defer func () {
76- if r := recover (); r == nil {
77- t .Error ("Expected panic" )
78- }
79- }()
80- NewClient (& ClientOptions {Connection : UriConnection {URL : "localhost:99999" }})
81- })
82-
83- t .Run ("should panic for invalid port - zero" , func (t * testing.T ) {
84- defer func () {
85- if r := recover (); r == nil {
86- t .Error ("Expected panic" )
87- }
88- }()
89- NewClient (& ClientOptions {Connection : UriConnection {URL : "localhost:0" }})
90- })
91-
92- t .Run ("should panic for invalid port - negative" , func (t * testing.T ) {
93- defer func () {
94- if r := recover (); r == nil {
95- t .Error ("Expected panic" )
96- }
97- }()
98- NewClient (& ClientOptions {Connection : UriConnection {URL : "localhost:-1" }})
99- })
100-
101- t .Run ("should panic when UriConnection has empty URL" , func (t * testing.T ) {
102- defer func () {
103- if r := recover (); r == nil {
104- t .Error ("Expected panic for empty URL" )
105- }
106- }()
107- NewClient (& ClientOptions {Connection : UriConnection {}})
108- })
109-
110- t .Run ("stdio connection uses stdio transport" , func (t * testing.T ) {
111- client := NewClient (& ClientOptions {Connection : StdioConnection {}})
112- if ! client .useStdio {
113- t .Error ("Expected useStdio=true for StdioConnection" )
114- }
115- })
38+ t .Run ("should parse host:port URL format" , func (t * testing.T ) {
39+ client := NewClient (& ClientOptions {
40+ Connection : UriConnection {URL : "127.0.0.1:9000" },
41+ })
42+ if client .actualPort != 9000 || client .actualHost != "127.0.0.1" {
43+ t .Errorf ("Expected 127.0.0.1:9000, got %s:%d" , client .actualHost , client .actualPort )
44+ }
45+ })
11646
117- t .Run ("tcp connection uses tcp transport" , func (t * testing.T ) {
118- client := NewClient (& ClientOptions {Connection : TcpConnection {Port : 8080 }})
119- if client .useStdio {
120- t .Error ("Expected useStdio=false for TcpConnection" )
121- }
122- if client .port != 8080 {
123- t .Errorf ("Expected port=8080, got %d" , client .port )
124- }
125- })
126-
127- t .Run ("uri connection is treated as external server" , func (t * testing.T ) {
128- client := NewClient (& ClientOptions {
129- Connection : UriConnection {URL : "localhost:8080" },
130- })
131- if ! client .isExternalServer {
132- t .Error ("Expected isExternalServer=true for UriConnection" )
133- }
134- })
47+ t .Run ("should parse http://host:port URL format" , func (t * testing.T ) {
48+ client := NewClient (& ClientOptions {
49+ Connection : UriConnection {URL : "http://localhost:7000" },
50+ })
51+ if client .actualPort != 7000 || client .actualHost != "localhost" {
52+ t .Errorf ("Expected localhost:7000, got %s:%d" , client .actualHost , client .actualPort )
53+ }
54+ })
55+
56+ t .Run ("should parse https://host:port URL format" , func (t * testing.T ) {
57+ client := NewClient (& ClientOptions {
58+ Connection : UriConnection {URL : "https://example.com:443" },
59+ })
60+ if client .actualPort != 443 || client .actualHost != "example.com" {
61+ t .Errorf ("Expected example.com:443, got %s:%d" , client .actualHost , client .actualPort )
62+ }
63+ })
64+
65+ t .Run ("should panic for invalid URL format" , func (t * testing.T ) {
66+ defer func () {
67+ if r := recover (); r == nil {
68+ t .Error ("Expected panic for invalid URL format" )
69+ }
70+ }()
71+ NewClient (& ClientOptions {Connection : UriConnection {URL : "invalid-url" }})
72+ })
73+
74+ t .Run ("should panic for invalid port - too high" , func (t * testing.T ) {
75+ defer func () {
76+ if r := recover (); r == nil {
77+ t .Error ("Expected panic" )
78+ }
79+ }()
80+ NewClient (& ClientOptions {Connection : UriConnection {URL : "localhost:99999" }})
81+ })
82+
83+ t .Run ("should panic for invalid port - zero" , func (t * testing.T ) {
84+ defer func () {
85+ if r := recover (); r == nil {
86+ t .Error ("Expected panic" )
87+ }
88+ }()
89+ NewClient (& ClientOptions {Connection : UriConnection {URL : "localhost:0" }})
90+ })
91+
92+ t .Run ("should panic for invalid port - negative" , func (t * testing.T ) {
93+ defer func () {
94+ if r := recover (); r == nil {
95+ t .Error ("Expected panic" )
96+ }
97+ }()
98+ NewClient (& ClientOptions {Connection : UriConnection {URL : "localhost:-1" }})
99+ })
100+
101+ t .Run ("should panic when UriConnection has empty URL" , func (t * testing.T ) {
102+ defer func () {
103+ if r := recover (); r == nil {
104+ t .Error ("Expected panic for empty URL" )
105+ }
106+ }()
107+ NewClient (& ClientOptions {Connection : UriConnection {}})
108+ })
109+
110+ t .Run ("stdio connection uses stdio transport" , func (t * testing.T ) {
111+ client := NewClient (& ClientOptions {Connection : StdioConnection {}})
112+ if ! client .useStdio {
113+ t .Error ("Expected useStdio=true for StdioConnection" )
114+ }
115+ })
116+
117+ t .Run ("tcp connection uses tcp transport" , func (t * testing.T ) {
118+ client := NewClient (& ClientOptions {Connection : TcpConnection {Port : 8080 }})
119+ if client .useStdio {
120+ t .Error ("Expected useStdio=false for TcpConnection" )
121+ }
122+ if client .port != 8080 {
123+ t .Errorf ("Expected port=8080, got %d" , client .port )
124+ }
125+ })
126+
127+ t .Run ("uri connection is treated as external server" , func (t * testing.T ) {
128+ client := NewClient (& ClientOptions {
129+ Connection : UriConnection {URL : "localhost:8080" },
130+ })
131+ if ! client .isExternalServer {
132+ t .Error ("Expected isExternalServer=true for UriConnection" )
133+ }
134+ })
135135}
136136
137137func TestClient_SessionFsConfig (t * testing.T ) {
0 commit comments