@@ -622,6 +622,26 @@ func TestPortsUpdateState(t *testing.T) {
622
622
},
623
623
},
624
624
},
625
+ {
626
+ // Please make sure this test pass for code browser resolveExternalPort
627
+ // see also https://github.com/gitpod-io/openvscode-server/blob/5ab7644a8bbf37d28e23212bc6f1529cafd8bf7b/extensions/gitpod-web/src/extension.ts#L310-L339
628
+ Desc : "expose port without served, port should be responded for use case of openvscode-server" ,
629
+ Changes : []Change {
630
+ {
631
+ Exposed : []ExposedPort {{LocalPort : 3000 , Public : false , URL : "foobar" }},
632
+ },
633
+ },
634
+ // this will not exposed because test manager didn't implement it properly
635
+ // ExpectedExposure: []ExposedPort{
636
+ // {LocalPort: 3000},
637
+ // },
638
+ ExpectedUpdates : UpdateExpectation {
639
+ {},
640
+ {
641
+ {LocalPort : 3000 , OnOpen : api .PortsStatus_notify_private , Exposed : & api.ExposedPortInfo {Visibility : api .PortVisibility_private , OnExposed : api .OnPortExposedAction_notify_private , Url : "foobar" }},
642
+ },
643
+ },
644
+ },
625
645
}
626
646
627
647
log .Log .Logger .SetLevel (logrus .FatalLevel )
@@ -873,9 +893,13 @@ func TestPortsConcurrentSubscribe(t *testing.T) {
873
893
}
874
894
875
895
func TestManager_getStatus (t * testing.T ) {
896
+ type portState struct {
897
+ port uint32
898
+ notServed bool
899
+ }
876
900
type fields struct {
877
901
orderInYaml []any
878
- state []uint32
902
+ state []portState
879
903
}
880
904
tests := []struct {
881
905
name string
@@ -887,27 +911,36 @@ func TestManager_getStatus(t *testing.T) {
887
911
fields : fields {
888
912
// The port number (e.g. 1337) or range (e.g. 3000-3999) to expose.
889
913
orderInYaml : []any {1002 , 1000 , "3000-3999" , 1001 },
890
- state : []uint32 { 1000 , 1001 , 1002 , 3003 , 3001 , 3002 , 4002 , 4000 , 5000 , 5005 },
914
+ state : []portState {{ port : 1000 }, { port : 1001 }, { port : 1002 }, { port : 3003 }, { port : 3001 }, { port : 3002 }, { port : 4002 }, { port : 4000 }, { port : 5000 }, { port : 5005 } },
891
915
},
892
916
want : []uint32 {1002 , 1000 , 3001 , 3002 , 3003 , 1001 , 4000 , 4002 , 5000 , 5005 },
893
917
},
894
918
{
895
919
name : "order for ranged ports and inside ranged order by number ASC" ,
896
920
fields : fields {
897
921
orderInYaml : []any {1002 , "3000-3999" , 1009 , "4000-4999" },
898
- state : []uint32 { 5000 , 1000 , 1009 , 4000 , 4001 , 3000 , 3009 },
922
+ state : []portState {{ port : 5000 }, { port : 1000 }, { port : 1009 }, { port : 4000 }, { port : 4001 }, { port : 3000 }, { port : 3009 } },
899
923
},
900
924
want : []uint32 {3000 , 3009 , 1009 , 4000 , 4001 , 1000 , 5000 },
901
925
},
902
926
{
903
927
name : "served ports order by number ASC" ,
904
928
fields : fields {
905
929
orderInYaml : []any {},
906
- state : []uint32 { 4000 , 4003 , 4007 , 4001 , 4006 },
930
+ state : []portState {{ port : 4000 }, { port : 4003 }, { port : 4007 }, { port : 4001 }, { port : 4006 } },
907
931
},
908
932
want : []uint32 {4000 , 4001 , 4003 , 4006 , 4007 },
909
933
},
910
-
934
+ {
935
+ // Please make sure this test pass for code browser resolveExternalPort
936
+ // see also https://github.com/gitpod-io/openvscode-server/blob/5ab7644a8bbf37d28e23212bc6f1529cafd8bf7b/extensions/gitpod-web/src/extension.ts#L310-L339
937
+ name : "expose not served ports should respond their status" ,
938
+ fields : fields {
939
+ orderInYaml : []any {},
940
+ state : []portState {{port : 4000 , notServed : true }},
941
+ },
942
+ want : []uint32 {4000 },
943
+ },
911
944
// It will not works because we do not `Run` ports Manger
912
945
// As ports Manger will autoExpose those ports (but not ranged port) in yaml
913
946
// and they will exists in state
@@ -923,11 +956,11 @@ func TestManager_getStatus(t *testing.T) {
923
956
for _ , tt := range tests {
924
957
t .Run (tt .name , func (t * testing.T ) {
925
958
state := make (map [uint32 ]* managedPort )
926
- for _ , port := range tt .fields .state {
927
- state [port ] = & managedPort {
928
- Served : true ,
929
- LocalhostPort : port ,
930
- TunneledTargetPort : port ,
959
+ for _ , s := range tt .fields .state {
960
+ state [s . port ] = & managedPort {
961
+ Served : ! s . notServed ,
962
+ LocalhostPort : s . port ,
963
+ TunneledTargetPort : s . port ,
931
964
TunneledClients : map [string ]uint32 {},
932
965
}
933
966
}
0 commit comments