@@ -86,39 +86,43 @@ func TestSetNamedPorts(t *testing.T) {
8686 f := NewFakeInstanceGroups (sets .NewString ([]string {"ig" }... ), defaultNamer )
8787 pool := newNodePool (f , defaultZone )
8888
89- // Note: each test case is dependent on the previous.
9089 testCases := []struct {
91- desc string
90+ activePorts [] int64
9291 expectedPorts []int64
9392 }{
9493 {
95- desc : "Set single port" ,
96- expectedPorts : []int64 {80 },
94+ // Verify setting a port works as expected.
95+ []int64 {80 },
96+ []int64 {80 },
9797 },
9898 {
99- desc : "Two new ports + existing port" ,
100- expectedPorts : []int64 {80 , 81 , 82 },
99+ // Utilizing multiple new ports
100+ []int64 {81 , 82 },
101+ []int64 {80 , 81 , 82 },
101102 },
102103 {
103- desc : "Utilize all existing ports" ,
104- expectedPorts : []int64 {80 , 81 , 82 },
104+ // Utilizing existing ports
105+ []int64 {80 , 82 },
106+ []int64 {80 , 81 , 82 },
105107 },
106108 {
107- desc : "Two new ports + remove unused port" ,
108- expectedPorts : []int64 {81 , 82 , 83 , 84 },
109+ // Utilizing a new port and an old port
110+ []int64 {80 , 83 },
111+ []int64 {80 , 81 , 82 , 83 },
109112 },
113+ // TODO: Add tests to remove named ports when we support that.
110114 }
111115 for _ , test := range testCases {
112- igs , err := pool .EnsureInstanceGroupsAndPorts ("ig" , test .expectedPorts )
116+ igs , err := pool .EnsureInstanceGroupsAndPorts ("ig" , test .activePorts )
113117 if err != nil {
114- t .Fatalf ("unexpected error in setting ports %v to instance group: %s" , test .expectedPorts , err )
118+ t .Fatalf ("unexpected error in setting ports %v to instance group: %s" , test .activePorts , err )
115119 }
116120 if len (igs ) != 1 {
117121 t .Fatalf ("expected a single instance group, got: %v" , igs )
118122 }
119123 actualPorts := igs [0 ].NamedPorts
120124 if len (actualPorts ) != len (test .expectedPorts ) {
121- t .Fatalf ("unexpected number of named ports on instance group. expected: %v, got: %v" , len ( test .expectedPorts ), len ( actualPorts ) )
125+ t .Fatalf ("unexpected named ports on instance group. expected: %v, got: %v" , test .expectedPorts , actualPorts )
122126 }
123127 for i , p := range igs [0 ].NamedPorts {
124128 if p .Port != test .expectedPorts [i ] {
0 commit comments