@@ -1172,52 +1172,165 @@ func Test_buildTargetGroupProtocolVersion(t *testing.T) {
11721172 testCases := []struct {
11731173 name string
11741174 loadBalancerType elbv2model.LoadBalancerType
1175+ tgConfigurator routeutils.TargetGroupConfigurator
1176+ listenerProtocol elbv2model.Protocol
11751177 route routeutils.RouteDescriptor
11761178 targetGroupProps * elbv2gw.TargetGroupProps
11771179 expected * elbv2model.ProtocolVersion
11781180 }{
11791181 {
11801182 name : "nlb - no props" ,
11811183 loadBalancerType : elbv2model .LoadBalancerTypeNetwork ,
1182- route : & routeutils.MockRoute {Kind : routeutils .TCPRouteKind },
1184+ listenerProtocol : elbv2model .ProtocolTCP ,
1185+ tgConfigurator : routeutils .NewServiceBackendConfig (nil , nil , & corev1.ServicePort {
1186+ Protocol : corev1 .ProtocolTCP ,
1187+ Port : 80 ,
1188+ TargetPort : intstr.IntOrString {
1189+ IntVal : 80 ,
1190+ Type : intstr .Int ,
1191+ },
1192+ }),
1193+ route : & routeutils.MockRoute {Kind : routeutils .TCPRouteKind },
11831194 },
11841195 {
11851196 name : "nlb - with props" ,
11861197 loadBalancerType : elbv2model .LoadBalancerTypeNetwork ,
1187- route : & routeutils.MockRoute {Kind : routeutils .TCPRouteKind },
1198+ listenerProtocol : elbv2model .ProtocolTCP ,
1199+ tgConfigurator : routeutils .NewServiceBackendConfig (nil , nil , & corev1.ServicePort {
1200+ Protocol : corev1 .ProtocolTCP ,
1201+ Port : 80 ,
1202+ TargetPort : intstr.IntOrString {
1203+ IntVal : 80 ,
1204+ Type : intstr .Int ,
1205+ },
1206+ }),
1207+ route : & routeutils.MockRoute {Kind : routeutils .TCPRouteKind },
11881208 targetGroupProps : & elbv2gw.TargetGroupProps {
11891209 ProtocolVersion : & http2Gw ,
11901210 },
11911211 },
11921212 {
11931213 name : "alb - no props" ,
1214+ listenerProtocol : elbv2model .ProtocolHTTPS ,
1215+ tgConfigurator : routeutils .NewServiceBackendConfig (nil , nil , & corev1.ServicePort {
1216+ Protocol : corev1 .ProtocolTCP ,
1217+ Port : 80 ,
1218+ TargetPort : intstr.IntOrString {
1219+ IntVal : 80 ,
1220+ Type : intstr .Int ,
1221+ },
1222+ }),
11941223 route : & routeutils.MockRoute {Kind : routeutils .HTTPRouteKind },
11951224 loadBalancerType : elbv2model .LoadBalancerTypeApplication ,
11961225 expected : & http1Elb ,
11971226 },
11981227 {
11991228 name : "alb - no props - grpc" ,
1229+ listenerProtocol : elbv2model .ProtocolHTTPS ,
1230+ tgConfigurator : routeutils .NewServiceBackendConfig (nil , nil , & corev1.ServicePort {
1231+ Protocol : corev1 .ProtocolTCP ,
1232+ Port : 80 ,
1233+ TargetPort : intstr.IntOrString {
1234+ IntVal : 80 ,
1235+ Type : intstr .Int ,
1236+ },
1237+ }),
12001238 route : & routeutils.MockRoute {Kind : routeutils .GRPCRouteKind },
12011239 loadBalancerType : elbv2model .LoadBalancerTypeApplication ,
12021240 expected : & grpcElb ,
12031241 },
12041242 {
12051243 name : "alb - with props" ,
1244+ listenerProtocol : elbv2model .ProtocolHTTPS ,
1245+ tgConfigurator : routeutils .NewServiceBackendConfig (nil , nil , & corev1.ServicePort {
1246+ Protocol : corev1 .ProtocolTCP ,
1247+ Port : 80 ,
1248+ TargetPort : intstr.IntOrString {
1249+ IntVal : 80 ,
1250+ Type : intstr .Int ,
1251+ },
1252+ }),
12061253 route : & routeutils.MockRoute {Kind : routeutils .HTTPRouteKind },
12071254 loadBalancerType : elbv2model .LoadBalancerTypeApplication ,
12081255 targetGroupProps : & elbv2gw.TargetGroupProps {
12091256 ProtocolVersion : & http2Gw ,
12101257 },
12111258 expected : & http2Elb ,
12121259 },
1260+ {
1261+ name : "alb - with props - http protocol" ,
1262+ listenerProtocol : elbv2model .ProtocolHTTP ,
1263+ tgConfigurator : routeutils .NewServiceBackendConfig (nil , nil , & corev1.ServicePort {
1264+ Protocol : corev1 .ProtocolTCP ,
1265+ Port : 80 ,
1266+ TargetPort : intstr.IntOrString {
1267+ IntVal : 80 ,
1268+ Type : intstr .Int ,
1269+ },
1270+ }),
1271+ route : & routeutils.MockRoute {Kind : routeutils .HTTPRouteKind },
1272+ loadBalancerType : elbv2model .LoadBalancerTypeApplication ,
1273+ targetGroupProps : & elbv2gw.TargetGroupProps {
1274+ ProtocolVersion : & http2Gw ,
1275+ },
1276+ expected : & http1Elb ,
1277+ },
1278+ {
1279+ name : "alb - pv found on svc port - http listener" ,
1280+ listenerProtocol : elbv2model .ProtocolHTTP ,
1281+ tgConfigurator : routeutils .NewServiceBackendConfig (nil , nil , & corev1.ServicePort {
1282+ Protocol : corev1 .ProtocolTCP ,
1283+ Port : 80 ,
1284+ AppProtocol : awssdk .String ("kubernetes.io/h2c" ),
1285+ TargetPort : intstr.IntOrString {
1286+ IntVal : 80 ,
1287+ Type : intstr .Int ,
1288+ },
1289+ }),
1290+ route : & routeutils.MockRoute {Kind : routeutils .HTTPRouteKind },
1291+ loadBalancerType : elbv2model .LoadBalancerTypeApplication ,
1292+ expected : & http1Elb ,
1293+ },
1294+ {
1295+ name : "alb - pv found on svc port - https listener" ,
1296+ listenerProtocol : elbv2model .ProtocolHTTPS ,
1297+ tgConfigurator : routeutils .NewServiceBackendConfig (nil , nil , & corev1.ServicePort {
1298+ Protocol : corev1 .ProtocolTCP ,
1299+ Port : 80 ,
1300+ AppProtocol : awssdk .String ("kubernetes.io/h2c" ),
1301+ TargetPort : intstr.IntOrString {
1302+ IntVal : 80 ,
1303+ Type : intstr .Int ,
1304+ },
1305+ }),
1306+ route : & routeutils.MockRoute {Kind : routeutils .HTTPRouteKind },
1307+ loadBalancerType : elbv2model .LoadBalancerTypeApplication ,
1308+ expected : & http2Elb ,
1309+ },
1310+ {
1311+ name : "alb - unknown pv found on svc port - https listener" ,
1312+ listenerProtocol : elbv2model .ProtocolHTTPS ,
1313+ tgConfigurator : routeutils .NewServiceBackendConfig (nil , nil , & corev1.ServicePort {
1314+ Protocol : corev1 .ProtocolTCP ,
1315+ Port : 80 ,
1316+ AppProtocol : awssdk .String ("foo" ),
1317+ TargetPort : intstr.IntOrString {
1318+ IntVal : 80 ,
1319+ Type : intstr .Int ,
1320+ },
1321+ }),
1322+ route : & routeutils.MockRoute {Kind : routeutils .HTTPRouteKind },
1323+ loadBalancerType : elbv2model .LoadBalancerTypeApplication ,
1324+ expected : & http1Elb ,
1325+ },
12131326 }
12141327
12151328 for _ , tc := range testCases {
12161329 t .Run (tc .name , func (t * testing.T ) {
12171330 builder := targetGroupBuilderImpl {
12181331 loadBalancerType : tc .loadBalancerType ,
12191332 }
1220- res := builder .buildTargetGroupProtocolVersion (tc .targetGroupProps , tc .route )
1333+ res := builder .buildTargetGroupProtocolVersion (tc .targetGroupProps , tc .tgConfigurator , tc . listenerProtocol , tc . route )
12211334 assert .Equal (t , tc .expected , res )
12221335 })
12231336 }
0 commit comments