@@ -80,6 +80,23 @@ func TestClientOptionsBuilder_OptionsPassedThrough(t *testing.T) {
8080 assert .NotNil (t , opts .HeadersProvider )
8181}
8282
83+ func TestClientOptionsBuilder_NamespaceReplacementInAddress (t * testing.T ) {
84+ builder := & cliext.ClientOptionsBuilder {
85+ CommonOptions : cliext.CommonOptions {
86+ DisableConfigFile : true ,
87+ },
88+ ClientOptions : cliext.ClientOptions {
89+ Address : "${namespace}.api.temporal.io:7233" ,
90+ Namespace : "my-namespace" ,
91+ },
92+ }
93+
94+ opts , err := builder .Build (t .Context ())
95+
96+ require .NoError (t , err )
97+ assert .Equal (t , "my-namespace.api.temporal.io:7233" , opts .HostPort )
98+ }
99+
83100func TestClientOptionsBuilder_OAuth_ValidToken (t * testing.T ) {
84101 s := newMockOAuthServer (t )
85102 configFile := createTestOAuthConfig (t , s .tokenURL , time .Now ().Add (time .Hour ))
@@ -89,7 +106,8 @@ func TestClientOptionsBuilder_OAuth_ValidToken(t *testing.T) {
89106 ConfigFile : configFile ,
90107 },
91108 ClientOptions : cliext.ClientOptions {
92- Address : "localhost:17233" ,
109+ Address : "localhost:17233" ,
110+ Namespace : "my-namespace" ,
93111 },
94112 }
95113 opts , err := builder .Build (t .Context ())
@@ -111,7 +129,8 @@ func TestClientOptionsBuilder_OAuth_Refresh(t *testing.T) {
111129 ConfigFile : configFile ,
112130 },
113131 ClientOptions : cliext.ClientOptions {
114- Address : "localhost:17233" ,
132+ Address : "localhost:17233" ,
133+ Namespace : "my-namespace" ,
115134 },
116135 }
117136 opts , err := builder .Build (context .Background ())
@@ -141,7 +160,8 @@ func TestClientOptionsBuilder_OAuth_NoConfigFile(t *testing.T) {
141160 DisableConfigFile : true ,
142161 },
143162 ClientOptions : cliext.ClientOptions {
144- Address : "localhost:17233" ,
163+ Address : "localhost:17233" ,
164+ Namespace : "my-namespace" ,
145165 },
146166 }
147167 opts , err := builder .Build (t .Context ())
@@ -160,7 +180,8 @@ func TestClientOptionsBuilder_OAuth_NoOAuthConfigured(t *testing.T) {
160180 ConfigFile : configFile ,
161181 },
162182 ClientOptions : cliext.ClientOptions {
163- Address : "localhost:17233" ,
183+ Address : "localhost:17233" ,
184+ Namespace : "my-namespace" ,
164185 },
165186 }
166187 opts , err := builder .Build (t .Context ())
@@ -179,7 +200,8 @@ func TestClientOptionsBuilder_OAuth_DisableConfigFile(t *testing.T) {
179200 DisableConfigFile : true , // disables loading config file
180201 },
181202 ClientOptions : cliext.ClientOptions {
182- Address : "localhost:17233" ,
203+ Address : "localhost:17233" ,
204+ Namespace : "my-namespace" ,
183205 },
184206 }
185207 opts , err := builder .Build (t .Context ())
@@ -197,8 +219,9 @@ func TestClientOptionsBuilder_OAuth_APIKeyTakesPrecedence(t *testing.T) {
197219 ConfigFile : configFileWithOAuth ,
198220 },
199221 ClientOptions : cliext.ClientOptions {
200- Address : "localhost:17233" ,
201- ApiKey : "explicit-api-key" , // takes precedence
222+ Address : "localhost:17233" ,
223+ Namespace : "my-namespace" ,
224+ ApiKey : "explicit-api-key" , // takes precedence
202225 },
203226 }
204227 opts , err := builder .Build (t .Context ())
@@ -207,6 +230,25 @@ func TestClientOptionsBuilder_OAuth_APIKeyTakesPrecedence(t *testing.T) {
207230 assert .NotNil (t , opts .Credentials )
208231}
209232
233+ func TestClientOptionsBuilder_OAuth_NonDefaultNamespaceRequired (t * testing.T ) {
234+ configFileWithOAuth := createTestOAuthConfig (t , "" , time .Now ().Add (time .Hour ))
235+
236+ builder := & cliext.ClientOptionsBuilder {
237+ CommonOptions : cliext.CommonOptions {
238+ ConfigFile : configFileWithOAuth ,
239+ },
240+ ClientOptions : cliext.ClientOptions {
241+ Address : "localhost:17233" ,
242+ Namespace : "default" ,
243+ },
244+ }
245+
246+ _ , err := builder .Build (t .Context ())
247+
248+ require .Error (t , err )
249+ assert .Contains (t , err .Error (), "Please specify a namespace" )
250+ }
251+
210252func createTestOAuthConfig (t * testing.T , tokenURL string , expiry time.Time ) string {
211253 t .Helper ()
212254 configFile := filepath .Join (t .TempDir (), "config.toml" )
0 commit comments