@@ -12,14 +12,13 @@ import (
12
12
"testing"
13
13
"time"
14
14
15
+ "github.com/gitpod-io/gitpod/common-go/log"
16
+ gitpod "github.com/gitpod-io/gitpod/gitpod-protocol"
17
+ "github.com/gitpod-io/gitpod/supervisor/api"
15
18
"github.com/google/go-cmp/cmp"
16
19
"github.com/google/go-cmp/cmp/cmpopts"
17
20
"github.com/sirupsen/logrus"
18
21
"golang.org/x/sync/errgroup"
19
-
20
- "github.com/gitpod-io/gitpod/common-go/log"
21
- gitpod "github.com/gitpod-io/gitpod/gitpod-protocol"
22
- "github.com/gitpod-io/gitpod/supervisor/api"
23
22
)
24
23
25
24
func TestPortsUpdateState (t * testing.T ) {
@@ -556,7 +555,7 @@ func TestPortsUpdateState(t *testing.T) {
556
555
for _ , c := range test .Changes {
557
556
if c .Config != nil {
558
557
change := & Configs {}
559
- change .workspaceConfigs = parseWorkspaceConfigs (c .Config .workspace )
558
+ change .workspaceConfigs , change . workspaceConfigsOrder = parseWorkspaceConfigs (c .Config .workspace )
560
559
portConfigs , rangeConfigs := parseInstanceConfigs (c .Config .instance )
561
560
change .instancePortConfigs = portConfigs
562
561
change .instanceRangeConfigs = rangeConfigs
@@ -746,3 +745,95 @@ func TestPortsConcurrentSubscribe(t *testing.T) {
746
745
747
746
wg .Wait ()
748
747
}
748
+
749
+ func TestManager_getStatus (t * testing.T ) {
750
+ type fields struct {
751
+ orderInYaml []uint32
752
+ state map [uint32 ]bool
753
+ }
754
+ tests := []struct {
755
+ name string
756
+ fields fields
757
+ want []uint32
758
+ }{
759
+ {
760
+ name : "happy path" ,
761
+ fields : fields {
762
+ orderInYaml : []uint32 {1002 , 1000 , 1001 },
763
+ state : map [uint32 ]bool {
764
+ 1000 : true ,
765
+ 1001 : true ,
766
+ 1002 : true ,
767
+ 4002 : true ,
768
+ 4000 : true ,
769
+ 5000 : false ,
770
+ 5005 : true ,
771
+ },
772
+ },
773
+ want : []uint32 {1002 , 1000 , 1001 , 4000 , 4002 , 5005 },
774
+ },
775
+ {
776
+ name : "ignore ports that not served and not exists in yaml" ,
777
+ fields : fields {
778
+ orderInYaml : []uint32 {1002 , 1000 , 1001 },
779
+ state : map [uint32 ]bool {
780
+ 1000 : true ,
781
+ 1001 : true ,
782
+ 1002 : true ,
783
+ 4000 : false ,
784
+ },
785
+ },
786
+ want : []uint32 {1002 , 1000 , 1001 },
787
+ },
788
+ {
789
+ name : "not ignore ports that not served but exists in yaml" ,
790
+ fields : fields {
791
+ orderInYaml : []uint32 {1002 , 1000 , 1001 },
792
+ state : map [uint32 ]bool {1002 : false , 1000 : false , 1001 : false },
793
+ },
794
+ want : []uint32 {1002 , 1000 , 1001 },
795
+ },
796
+ {
797
+ name : "served ports order by number ASC" ,
798
+ fields : fields {
799
+ orderInYaml : []uint32 {},
800
+ state : map [uint32 ]bool {
801
+ 4000 : true ,
802
+ 4003 : true ,
803
+ 4007 : true ,
804
+ 4001 : true ,
805
+ 4006 : false ,
806
+ },
807
+ },
808
+ want : []uint32 {4000 , 4001 , 4003 , 4007 },
809
+ },
810
+ }
811
+ for _ , tt := range tests {
812
+ t .Run (tt .name , func (t * testing.T ) {
813
+ state := make (map [uint32 ]* managedPort )
814
+ for port , served := range tt .fields .state {
815
+ state [port ] = & managedPort {
816
+ Served : served ,
817
+ LocalhostPort : port ,
818
+ TunneledTargetPort : port ,
819
+ TunneledClients : map [string ]uint32 {},
820
+ }
821
+ }
822
+ pm := & Manager {
823
+ configs : & Configs {
824
+ workspaceConfigsOrder : tt .fields .orderInYaml ,
825
+ },
826
+ state : state ,
827
+ }
828
+ got := pm .getStatus ()
829
+ if len (got ) != len (tt .want ) {
830
+ t .Errorf ("Manager.getStatus() length = %v, want %v" , len (got ), len (tt .want ))
831
+ }
832
+ for i := 0 ; i < len (got ); i ++ {
833
+ if got [i ].LocalPort != tt .want [i ] {
834
+ t .Errorf ("Manager.getStatus() %v, want %v" , got , tt .want )
835
+ }
836
+ }
837
+ })
838
+ }
839
+ }
0 commit comments