@@ -131,3 +131,37 @@ func TestNetworkServicesController_lookupServiceByFWMark(t *testing.T) {
131
131
assert .Zero (t , foundPort , "port should be zero on error" )
132
132
})
133
133
}
134
+
135
+ func TestNetworkServicesController_getLabelFromMap (t * testing.T ) {
136
+ labels := map [string ]string {
137
+ "service.kubernetes.io" : "foo" ,
138
+ "kube-router.io" : "bar" ,
139
+ }
140
+ copyLabels := func (srcLbls map [string ]string ) map [string ]string {
141
+ dstLbls := map [string ]string {}
142
+ for k , v := range srcLbls {
143
+ dstLbls [k ] = v
144
+ }
145
+ return dstLbls
146
+ }
147
+ t .Run ("return blank when passed labels don't contain service-proxy-name label" , func (t * testing.T ) {
148
+ lbl , err := getLabelFromMap (svcProxyNameLabel , labels )
149
+ assert .Empty (t , lbl , "should return blank for a list of labels that don't contain a service-proxy-name label" )
150
+ assert .Error (t , err , "should return an error when the label doesn't exist" )
151
+ })
152
+
153
+ t .Run ("return blank when empty label map is passed" , func (t * testing.T ) {
154
+ lbls := map [string ]string {}
155
+ lbl , err := getLabelFromMap (svcProxyNameLabel , lbls )
156
+ assert .Empty (t , lbl , "should return blank for a map with no elements" )
157
+ assert .Error (t , err , "should return an error when the map doesn't contain any elements" )
158
+ })
159
+
160
+ t .Run ("return value when an labels contains service-proxy-name label" , func (t * testing.T ) {
161
+ lbls := copyLabels (labels )
162
+ lbls [svcProxyNameLabel ] = "foo"
163
+ lbl , err := getLabelFromMap (svcProxyNameLabel , lbls )
164
+ assert .Equal (t , "foo" , lbl , "should return value when service-proxy-name passed" )
165
+ assert .Nil (t , err , "error should be nil when the label exists" )
166
+ })
167
+ }
0 commit comments