@@ -3,73 +3,50 @@ import { getContainerPort, getProtocol, hasHostBinding } from "./port";
33
44describe ( "port utilities" , ( ) => {
55 describe ( "getContainerPort" , ( ) => {
6- it ( "returns number as is " , ( ) => {
6+ it ( "should return the container port when defined as a number " , ( ) => {
77 expect ( getContainerPort ( 8080 ) ) . toBe ( 8080 ) ;
88 } ) ;
99
10- it ( "parses port from string" , ( ) => {
11- expect ( getContainerPort ( "8080" ) ) . toBe ( 8080 ) ;
12- } ) ;
13-
14- it ( "parses port from string with protocol" , ( ) => {
10+ it ( "should return the port when defined as a string with format `port/protocol`" , ( ) => {
1511 expect ( getContainerPort ( "8080/tcp" ) ) . toBe ( 8080 ) ;
1612 expect ( getContainerPort ( "8080/udp" ) ) . toBe ( 8080 ) ;
1713 } ) ;
1814
19- it ( "returns container port from object " , ( ) => {
15+ it ( "should return the container port from when defined as `PortWithBinding` " , ( ) => {
2016 expect ( getContainerPort ( { container : 8080 , host : 49000 } ) ) . toBe ( 8080 ) ;
2117 } ) ;
22-
23- it ( "throws error for invalid port format" , ( ) => {
24- expect ( ( ) => getContainerPort ( "invalid" ) ) . toThrow ( "Invalid port format: invalid" ) ;
25- } ) ;
2618 } ) ;
2719
2820 describe ( "hasHostBinding" , ( ) => {
29- it ( "returns true for object with host binding " , ( ) => {
21+ it ( "should return true for `PortWithBinding` with defined ` host` parameter " , ( ) => {
3022 expect ( hasHostBinding ( { container : 8080 , host : 49000 } ) ) . toBe ( true ) ;
3123 } ) ;
3224
33- it ( "returns false for number" , ( ) => {
25+ it ( "should return false when querying for a number" , ( ) => {
3426 expect ( hasHostBinding ( 8080 ) ) . toBe ( false ) ;
3527 } ) ;
3628
37- it ( "returns false for string" , ( ) => {
38- expect ( hasHostBinding ( "8080" ) ) . toBe ( false ) ;
29+ it ( "should return false when querying for a string with format `port/protocol`" , ( ) => {
3930 expect ( hasHostBinding ( "8080/tcp" ) ) . toBe ( false ) ;
4031 } ) ;
4132 } ) ;
4233
4334 describe ( "getProtocol" , ( ) => {
44- it ( "returns tcp for number" , ( ) => {
35+ it ( "should return the default ` tcp` for a number" , ( ) => {
4536 expect ( getProtocol ( 8080 ) ) . toBe ( "tcp" ) ;
4637 } ) ;
4738
48- it ( "returns tcp for string without protocol" , ( ) => {
49- expect ( getProtocol ( "8080" ) ) . toBe ( "tcp" ) ;
50- } ) ;
51-
52- it ( "returns protocol from string" , ( ) => {
39+ it ( "should return the protocol part of a string with format `port/protocol`" , ( ) => {
5340 expect ( getProtocol ( "8080/tcp" ) ) . toBe ( "tcp" ) ;
5441 expect ( getProtocol ( "8080/udp" ) ) . toBe ( "udp" ) ;
5542 } ) ;
5643
57- it ( "returns protocol from object " , ( ) => {
44+ it ( "should maintain backwards compatibility when defined as `PortWithBinding` without protocol " , ( ) => {
5845 expect ( getProtocol ( { container : 8080 , host : 49000 } ) ) . toBe ( "tcp" ) ;
59- expect ( getProtocol ( { container : 8080 , host : 49000 , protocol : "udp" } ) ) . toBe ( "udp" ) ;
60- } ) ;
61-
62- it ( "handles protocol case-insensitively" , ( ) => {
63- expect ( getProtocol ( { container : 8080 , host : 49000 , protocol : "TCP" } ) ) . toBe ( "tcp" ) ;
64- expect ( getProtocol ( { container : 8080 , host : 49000 , protocol : "UDP" } ) ) . toBe ( "udp" ) ;
65- expect ( getProtocol ( "8080/TCP" ) ) . toBe ( "tcp" ) ;
66- expect ( getProtocol ( "8080/UDP" ) ) . toBe ( "udp" ) ;
6746 } ) ;
6847
69- it ( "maintains backward compatibility" , ( ) => {
70- expect ( getProtocol ( 8080 ) ) . toBe ( "tcp" ) ;
71- expect ( getProtocol ( "8080" ) ) . toBe ( "tcp" ) ;
72- expect ( getProtocol ( { container : 8080 , host : 49000 } ) ) . toBe ( "tcp" ) ;
48+ it ( "should return the protocol parameter when defined as `PortWithBinding`" , ( ) => {
49+ expect ( getProtocol ( { container : 8080 , host : 49000 , protocol : "udp" } ) ) . toBe ( "udp" ) ;
7350 } ) ;
7451 } ) ;
7552} ) ;
0 commit comments