istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/networking/networking_test.go (about) 1 // Copyright Istio Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package networking 16 17 import ( 18 "testing" 19 20 core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" 21 22 "istio.io/istio/pkg/config/protocol" 23 ) 24 25 func TestModelProtocolToListenerProtocol(t *testing.T) { 26 tests := []struct { 27 name string 28 protocol protocol.Instance 29 direction core.TrafficDirection 30 want ListenerProtocol 31 }{ 32 { 33 "TCP to TCP", 34 protocol.TCP, 35 core.TrafficDirection_INBOUND, 36 ListenerProtocolTCP, 37 }, 38 { 39 "HTTP to HTTP", 40 protocol.HTTP, 41 core.TrafficDirection_INBOUND, 42 ListenerProtocolHTTP, 43 }, 44 { 45 "HTTP to HTTP", 46 protocol.HTTP_PROXY, 47 core.TrafficDirection_OUTBOUND, 48 ListenerProtocolHTTP, 49 }, 50 { 51 "MySQL to TCP", 52 protocol.MySQL, 53 core.TrafficDirection_INBOUND, 54 ListenerProtocolTCP, 55 }, 56 { 57 "Inbound unknown to Auto", 58 protocol.Unsupported, 59 core.TrafficDirection_INBOUND, 60 ListenerProtocolAuto, 61 }, 62 { 63 "Outbound unknown to Auto", 64 protocol.Unsupported, 65 core.TrafficDirection_OUTBOUND, 66 ListenerProtocolAuto, 67 }, 68 { 69 "UDP to UDP", 70 protocol.UDP, 71 core.TrafficDirection_INBOUND, 72 ListenerProtocolUnknown, 73 }, 74 } 75 76 for _, tt := range tests { 77 t.Run(tt.name, func(t *testing.T) { 78 if got := ModelProtocolToListenerProtocol(tt.protocol); got != tt.want { 79 t.Errorf("ModelProtocolToListenerProtocol() = %v, want %v", got, tt.want) 80 } 81 }) 82 } 83 } 84 85 func TestString(t *testing.T) { 86 tests := []struct { 87 name string 88 value uint 89 want string 90 }{ 91 { 92 "test String method for tcp transport protocol", 93 TransportProtocolTCP, 94 "tcp", 95 }, 96 { 97 "test String method for quic transport protocol", 98 TransportProtocolQUIC, 99 "quic", 100 }, 101 { 102 "test String method for invalid transport protocol", 103 3, 104 "unknown", 105 }, 106 } 107 108 for _, tt := range tests { 109 t.Run(tt.name, func(t *testing.T) { 110 if got := TransportProtocol(tt.value).String(); got != tt.want { 111 t.Errorf("Failed to get TransportProtocol.String :: got = %v, want %v", got, tt.want) 112 } 113 }) 114 } 115 }