@@ -246,191 +246,191 @@ func TestParseArgs_StructFields(t *testing.T) {
246246
247247// TestGetSSHControlPath tests the SSH control path generation
248248func TestGetSSHControlPath (t * testing.T ) {
249- tests := []struct {
250- name string
251- codespaceName string
252- shouldContain string
253- }{
254- {
255- name : "basic codespace name" ,
256- codespaceName : "my-codespace" ,
257- shouldContain : "my-codespace" ,
258- },
259- {
260- name : "codespace name with special chars" ,
261- codespaceName : "user/repo-codespace:test" ,
262- shouldContain : "user-repo-codespace-test" ,
263- },
264- {
265- name : "empty codespace name" ,
266- codespaceName : "" ,
267- shouldContain : "unknown" ,
268- },
269- }
270-
271- for _ , tt := range tests {
272- t .Run (tt .name , func (t * testing.T ) {
273- path := GetSSHControlPath (tt .codespaceName )
274-
275- // Check that path contains expected sanitized name
276- if ! strings .Contains (path , tt .shouldContain ) {
277- t .Errorf ("GetSSHControlPath() = %v, should contain %v" , path , tt .shouldContain )
278- }
249+ tests := []struct {
250+ name string
251+ codespaceName string
252+ shouldContain string
253+ }{
254+ {
255+ name : "basic codespace name" ,
256+ codespaceName : "my-codespace" ,
257+ shouldContain : "my-codespace" ,
258+ },
259+ {
260+ name : "codespace name with special chars" ,
261+ codespaceName : "user/repo-codespace:test" ,
262+ shouldContain : "user-repo-codespace-test" ,
263+ },
264+ {
265+ name : "empty codespace name" ,
266+ codespaceName : "" ,
267+ shouldContain : "unknown" ,
268+ },
269+ }
279270
280- // Check that path is in temp directory
281- if ! strings .Contains (path , "gh-ado-codespaces" ) || ! strings .Contains (path , "ssh-control" ) {
282- t .Errorf ("GetSSHControlPath() = %v, should contain gh-ado-codespaces/ssh-control" , path )
283- }
284- })
285- }
271+ for _ , tt := range tests {
272+ t .Run (tt .name , func (t * testing.T ) {
273+ path := GetSSHControlPath (tt .codespaceName )
274+
275+ // Check that path contains expected sanitized name
276+ if ! strings .Contains (path , tt .shouldContain ) {
277+ t .Errorf ("GetSSHControlPath() = %v, should contain %v" , path , tt .shouldContain )
278+ }
279+
280+ // Check that path is in temp directory
281+ if ! strings .Contains (path , "gh-ado-codespaces" ) || ! strings .Contains (path , "ssh-control" ) {
282+ t .Errorf ("GetSSHControlPath() = %v, should contain gh-ado-codespaces/ssh-control" , path )
283+ }
284+ })
285+ }
286286}
287287
288288// TestBuildSSHMultiplexArgs tests SSH multiplexing argument generation
289289func TestBuildSSHMultiplexArgs (t * testing.T ) {
290- tests := []struct {
291- name string
292- controlPath string
293- isMaster bool
294- wantMaster string
295- }{
296- {
297- name : "master connection" ,
298- controlPath : "/tmp/control-socket" ,
299- isMaster : true ,
300- wantMaster : "ControlMaster=auto" ,
301- },
302- {
303- name : "slave connection" ,
304- controlPath : "/tmp/control-socket" ,
305- isMaster : false ,
306- wantMaster : "ControlMaster=no" ,
307- },
308- }
309-
310- for _ , tt := range tests {
311- t .Run (tt .name , func (t * testing.T ) {
312- args := BuildSSHMultiplexArgs (tt .controlPath , tt .isMaster )
313-
314- // Check that it contains the expected ControlMaster setting
315- found := false
316- for _ , arg := range args {
317- if arg == tt .wantMaster {
318- found = true
319- break
320- }
321- }
322- if ! found {
323- t .Errorf ("BuildSSHMultiplexArgs() = %v, should contain %v" , args , tt .wantMaster )
324- }
325-
326- // Check that it contains ControlPath
327- foundPath := false
328- expectedPath := fmt .Sprintf ("ControlPath=%s" , tt .controlPath )
329- for _ , arg := range args {
330- if arg == expectedPath {
331- foundPath = true
332- break
333- }
334- }
335- if ! foundPath {
336- t .Errorf ("BuildSSHMultiplexArgs() = %v, should contain %v" , args , expectedPath )
337- }
290+ tests := []struct {
291+ name string
292+ controlPath string
293+ isMaster bool
294+ wantMaster string
295+ }{
296+ {
297+ name : "master connection" ,
298+ controlPath : "/tmp/control-socket" ,
299+ isMaster : true ,
300+ wantMaster : "ControlMaster=auto" ,
301+ },
302+ {
303+ name : "slave connection" ,
304+ controlPath : "/tmp/control-socket" ,
305+ isMaster : false ,
306+ wantMaster : "ControlMaster=no" ,
307+ },
308+ }
338309
339- // Check that it contains ControlPersist
340- foundPersist := false
341- for _ , arg := range args {
342- if strings .HasPrefix (arg , "ControlPersist=" ) {
343- foundPersist = true
344- break
345- }
346- }
347- if ! foundPersist {
348- t .Errorf ("BuildSSHMultiplexArgs() = %v, should contain ControlPersist" , args )
349- }
350- })
351- }
310+ for _ , tt := range tests {
311+ t .Run (tt .name , func (t * testing.T ) {
312+ args := BuildSSHMultiplexArgs (tt .controlPath , tt .isMaster )
313+
314+ // Check that it contains the expected ControlMaster setting
315+ found := false
316+ for _ , arg := range args {
317+ if arg == tt .wantMaster {
318+ found = true
319+ break
320+ }
321+ }
322+ if ! found {
323+ t .Errorf ("BuildSSHMultiplexArgs() = %v, should contain %v" , args , tt .wantMaster )
324+ }
325+
326+ // Check that it contains ControlPath
327+ foundPath := false
328+ expectedPath := fmt .Sprintf ("ControlPath=%s" , tt .controlPath )
329+ for _ , arg := range args {
330+ if arg == expectedPath {
331+ foundPath = true
332+ break
333+ }
334+ }
335+ if ! foundPath {
336+ t .Errorf ("BuildSSHMultiplexArgs() = %v, should contain %v" , args , expectedPath )
337+ }
338+
339+ // Check that it contains ControlPersist
340+ foundPersist := false
341+ for _ , arg := range args {
342+ if strings .HasPrefix (arg , "ControlPersist=" ) {
343+ foundPersist = true
344+ break
345+ }
346+ }
347+ if ! foundPersist {
348+ t .Errorf ("BuildSSHMultiplexArgs() = %v, should contain ControlPersist" , args )
349+ }
350+ })
351+ }
352352}
353353
354354// TestSSHMultiplexingIntegration tests that SSH multiplexing arguments are properly formatted
355355func TestSSHMultiplexingIntegration (t * testing.T ) {
356- codespaceName := "test-codespace"
357- controlPath := GetSSHControlPath (codespaceName )
358-
359- // Test master connection args
360- masterArgs := BuildSSHMultiplexArgs (controlPath , true )
361-
362- // Verify master args structure
363- expectedMasterPairs := map [string ]string {
364- "-o" : "ControlMaster=auto" ,
365- }
366-
367- for i := 0 ; i < len (masterArgs )- 1 ; i ++ {
368- if masterArgs [i ] == "-o" {
369- if expectedValue , exists := expectedMasterPairs ["-o" ]; exists {
370- if masterArgs [i + 1 ] == expectedValue {
371- delete (expectedMasterPairs , "-o" )
372- break
373- }
374- }
375- }
376- }
377-
378- if len (expectedMasterPairs ) > 0 {
379- t .Errorf ("Master args missing expected values: %v" , expectedMasterPairs )
380- }
381-
382- // Test slave connection args
383- slaveArgs := BuildSSHMultiplexArgs (controlPath , false )
384-
385- // Verify slave args have ControlMaster=no
386- foundNo := false
387- for i := 0 ; i < len (slaveArgs )- 1 ; i ++ {
388- if slaveArgs [i ] == "-o" && slaveArgs [i + 1 ] == "ControlMaster=no" {
389- foundNo = true
390- break
391- }
392- }
393-
394- if ! foundNo {
395- t .Errorf ("Slave args should contain ControlMaster=no, got: %v" , slaveArgs )
396- }
356+ codespaceName := "test-codespace"
357+ controlPath := GetSSHControlPath (codespaceName )
358+
359+ // Test master connection args
360+ masterArgs := BuildSSHMultiplexArgs (controlPath , true )
361+
362+ // Verify master args structure
363+ expectedMasterPairs := map [string ]string {
364+ "-o" : "ControlMaster=auto" ,
365+ }
366+
367+ for i := 0 ; i < len (masterArgs )- 1 ; i ++ {
368+ if masterArgs [i ] == "-o" {
369+ if expectedValue , exists := expectedMasterPairs ["-o" ]; exists {
370+ if masterArgs [i + 1 ] == expectedValue {
371+ delete (expectedMasterPairs , "-o" )
372+ break
373+ }
374+ }
375+ }
376+ }
377+
378+ if len (expectedMasterPairs ) > 0 {
379+ t .Errorf ("Master args missing expected values: %v" , expectedMasterPairs )
380+ }
381+
382+ // Test slave connection args
383+ slaveArgs := BuildSSHMultiplexArgs (controlPath , false )
384+
385+ // Verify slave args have ControlMaster=no
386+ foundNo := false
387+ for i := 0 ; i < len (slaveArgs )- 1 ; i ++ {
388+ if slaveArgs [i ] == "-o" && slaveArgs [i + 1 ] == "ControlMaster=no" {
389+ foundNo = true
390+ break
391+ }
392+ }
393+
394+ if ! foundNo {
395+ t .Errorf ("Slave args should contain ControlMaster=no, got: %v" , slaveArgs )
396+ }
397397}
398398
399399// TestSanitizeCodespaceNameForControl tests codespace name sanitization for control paths
400400func TestSanitizeCodespaceNameForControl (t * testing.T ) {
401- tests := []struct {
402- name string
403- input string
404- expected string
405- }{
406- {
407- name : "simple name" ,
408- input : "my-codespace" ,
409- expected : "my-codespace" ,
410- },
411- {
412- name : "name with slashes" ,
413- input : "user/repo" ,
414- expected : "user-repo" ,
415- },
416- {
417- name : "name with colons and spaces" ,
418- input : "test: codespace" ,
419- expected : "test--codespace" ,
420- },
421- {
422- name : "empty name" ,
423- input : "" ,
424- expected : "unknown" ,
425- },
426- }
401+ tests := []struct {
402+ name string
403+ input string
404+ expected string
405+ }{
406+ {
407+ name : "simple name" ,
408+ input : "my-codespace" ,
409+ expected : "my-codespace" ,
410+ },
411+ {
412+ name : "name with slashes" ,
413+ input : "user/repo" ,
414+ expected : "user-repo" ,
415+ },
416+ {
417+ name : "name with colons and spaces" ,
418+ input : "test: codespace" ,
419+ expected : "test--codespace" ,
420+ },
421+ {
422+ name : "empty name" ,
423+ input : "" ,
424+ expected : "unknown" ,
425+ },
426+ }
427427
428- for _ , tt := range tests {
429- t .Run (tt .name , func (t * testing.T ) {
430- result := sanitizeCodespaceNameForControl (tt .input )
431- if result != tt .expected {
432- t .Errorf ("sanitizeCodespaceNameForControl(%q) = %q, want %q" , tt .input , result , tt .expected )
433- }
434- })
435- }
428+ for _ , tt := range tests {
429+ t .Run (tt .name , func (t * testing.T ) {
430+ result := sanitizeCodespaceNameForControl (tt .input )
431+ if result != tt .expected {
432+ t .Errorf ("sanitizeCodespaceNameForControl(%q) = %q, want %q" , tt .input , result , tt .expected )
433+ }
434+ })
435+ }
436436}
0 commit comments