@@ -511,10 +511,12 @@ func TestWorkspaceAgentTailnetDirectDisabled(t *testing.T) {
511
511
func TestWorkspaceAgentListeningPorts (t * testing.T ) {
512
512
t .Parallel ()
513
513
514
- setup := func (t * testing.T , apps []* proto.App ) (* codersdk.Client , uint16 , uuid.UUID ) {
514
+ setup := func (t * testing.T , apps []* proto.App , dv * codersdk. DeploymentValues ) (* codersdk.Client , uint16 , uuid.UUID ) {
515
515
t .Helper ()
516
516
517
- client , db := coderdtest .NewWithDatabase (t , nil )
517
+ client , db := coderdtest .NewWithDatabase (t , & coderdtest.Options {
518
+ DeploymentValues : dv ,
519
+ })
518
520
coderdPort , err := strconv .Atoi (client .URL .Port ())
519
521
require .NoError (t , err )
520
522
@@ -608,61 +610,82 @@ func TestWorkspaceAgentListeningPorts(t *testing.T) {
608
610
return
609
611
}
610
612
611
- t .Run ("OK" , func (t * testing.T ) {
612
- t .Parallel ()
613
-
614
- client , coderdPort , agentID := setup (t , nil )
615
-
616
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
617
- defer cancel ()
618
-
619
- // Generate a random unfiltered port.
620
- l , lPort := generateUnfilteredPort (t )
621
-
622
- // List ports and ensure that the port we expect to see is there.
623
- res , err := client .WorkspaceAgentListeningPorts (ctx , agentID )
624
- require .NoError (t , err )
625
-
626
- expected := map [uint16 ]bool {
627
- // expect the listener we made
628
- lPort : false ,
629
- // expect the coderdtest server
630
- coderdPort : false ,
631
- }
632
- for _ , port := range res .Ports {
633
- if port .Network == "tcp" {
634
- if val , ok := expected [port .Port ]; ok {
635
- if val {
636
- t .Fatalf ("expected to find TCP port %d only once in response" , port .Port )
613
+ for _ , tc := range []struct {
614
+ name string
615
+ setDV func (t * testing.T , dv * codersdk.DeploymentValues )
616
+ }{
617
+ {
618
+ name : "Mainline" ,
619
+ setDV : func (* testing.T , * codersdk.DeploymentValues ) {},
620
+ },
621
+ {
622
+ name : "BlockDirect" ,
623
+ setDV : func (t * testing.T , dv * codersdk.DeploymentValues ) {
624
+ err := dv .DERP .Config .BlockDirect .Set ("true" )
625
+ require .NoError (t , err )
626
+ require .True (t , dv .DERP .Config .BlockDirect .Value ())
627
+ },
628
+ },
629
+ } {
630
+ tc := tc
631
+ t .Run ("OK_" + tc .name , func (t * testing.T ) {
632
+ t .Parallel ()
633
+
634
+ dv := coderdtest .DeploymentValues (t )
635
+ tc .setDV (t , dv )
636
+ client , coderdPort , agentID := setup (t , nil , dv )
637
+
638
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
639
+ defer cancel ()
640
+
641
+ // Generate a random unfiltered port.
642
+ l , lPort := generateUnfilteredPort (t )
643
+
644
+ // List ports and ensure that the port we expect to see is there.
645
+ res , err := client .WorkspaceAgentListeningPorts (ctx , agentID )
646
+ require .NoError (t , err )
647
+
648
+ expected := map [uint16 ]bool {
649
+ // expect the listener we made
650
+ lPort : false ,
651
+ // expect the coderdtest server
652
+ coderdPort : false ,
653
+ }
654
+ for _ , port := range res .Ports {
655
+ if port .Network == "tcp" {
656
+ if val , ok := expected [port .Port ]; ok {
657
+ if val {
658
+ t .Fatalf ("expected to find TCP port %d only once in response" , port .Port )
659
+ }
637
660
}
661
+ expected [port .Port ] = true
638
662
}
639
- expected [port .Port ] = true
640
663
}
641
- }
642
- for port , found := range expected {
643
- if ! found {
644
- t .Fatalf ("expected to find TCP port %d in response" , port )
645
- }
646
- }
647
-
648
- // Close the listener and check that the port is no longer in the response.
649
- require .NoError (t , l .Close ())
650
- t .Log ("checking for ports after listener close:" )
651
- require .Eventually (t , func () bool {
652
- res , err = client .WorkspaceAgentListeningPorts (ctx , agentID )
653
- if ! assert .NoError (t , err ) {
654
- return false
664
+ for port , found := range expected {
665
+ if ! found {
666
+ t .Fatalf ("expected to find TCP port %d in response" , port )
667
+ }
655
668
}
656
669
657
- for _ , port := range res .Ports {
658
- if port .Network == "tcp" && port .Port == lPort {
659
- t .Logf ("expected to not find TCP port %d in response" , lPort )
670
+ // Close the listener and check that the port is no longer in the response.
671
+ require .NoError (t , l .Close ())
672
+ t .Log ("checking for ports after listener close:" )
673
+ require .Eventually (t , func () bool {
674
+ res , err = client .WorkspaceAgentListeningPorts (ctx , agentID )
675
+ if ! assert .NoError (t , err ) {
660
676
return false
661
677
}
662
- }
663
- return true
664
- }, testutil .WaitLong , testutil .IntervalMedium )
665
- })
678
+
679
+ for _ , port := range res .Ports {
680
+ if port .Network == "tcp" && port .Port == lPort {
681
+ t .Logf ("expected to not find TCP port %d in response" , lPort )
682
+ return false
683
+ }
684
+ }
685
+ return true
686
+ }, testutil .WaitLong , testutil .IntervalMedium )
687
+ })
688
+ }
666
689
667
690
t .Run ("Filter" , func (t * testing.T ) {
668
691
t .Parallel ()
@@ -678,7 +701,7 @@ func TestWorkspaceAgentListeningPorts(t *testing.T) {
678
701
// Generate a filtered port that should not exist in the response.
679
702
_ , filteredLPort := generateFilteredPort (t )
680
703
681
- client , coderdPort , agentID := setup (t , []* proto.App {app })
704
+ client , coderdPort , agentID := setup (t , []* proto.App {app }, nil )
682
705
683
706
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
684
707
defer cancel ()
@@ -713,7 +736,7 @@ func TestWorkspaceAgentListeningPorts(t *testing.T) {
713
736
return
714
737
}
715
738
716
- client , _ , agentID := setup (t , nil )
739
+ client , _ , agentID := setup (t , nil , nil )
717
740
718
741
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
719
742
defer cancel ()
0 commit comments