istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/config/protocol/instance_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 protocol_test
    16  
    17  import (
    18  	"testing"
    19  
    20  	"istio.io/istio/pkg/config/protocol"
    21  )
    22  
    23  func TestIsHTTP(t *testing.T) {
    24  	if protocol.UDP.IsHTTP() {
    25  		t.Errorf("UDP is not HTTP protocol")
    26  	}
    27  	if !protocol.GRPC.IsHTTP() {
    28  		t.Errorf("gRPC is HTTP protocol")
    29  	}
    30  }
    31  
    32  func TestParse(t *testing.T) {
    33  	testPairs := []struct {
    34  		name string
    35  		out  protocol.Instance
    36  	}{
    37  		{"tcp", protocol.TCP},
    38  		{"http", protocol.HTTP},
    39  		{"HTTP", protocol.HTTP},
    40  		{"Http", protocol.HTTP},
    41  		{"http_proxy", protocol.HTTP_PROXY},
    42  		{"Http_Proxy", protocol.HTTP_PROXY},
    43  		{"HTTP_PROXY", protocol.HTTP_PROXY},
    44  		{"https", protocol.HTTPS},
    45  		{"http2", protocol.HTTP2},
    46  		{"grpc", protocol.GRPC},
    47  		{"grpc-web", protocol.GRPCWeb},
    48  		{"gRPC-Web", protocol.GRPCWeb},
    49  		{"grpc-Web", protocol.GRPCWeb},
    50  		{"udp", protocol.UDP},
    51  		{"Mongo", protocol.Mongo},
    52  		{"mongo", protocol.Mongo},
    53  		{"MONGO", protocol.Mongo},
    54  		{"Redis", protocol.Redis},
    55  		{"redis", protocol.Redis},
    56  		{"REDIS", protocol.Redis},
    57  		{"Mysql", protocol.MySQL},
    58  		{"mysql", protocol.MySQL},
    59  		{"MYSQL", protocol.MySQL},
    60  		{"MySQL", protocol.MySQL},
    61  		{"", protocol.Unsupported},
    62  		{"SMTP", protocol.Unsupported},
    63  		{"HBONE", protocol.Unsupported},
    64  	}
    65  
    66  	for _, testPair := range testPairs {
    67  		testName := testPair.name
    68  		if testName == "" {
    69  			testName = "[empty]"
    70  		}
    71  		t.Run(testName, func(t *testing.T) {
    72  			out := protocol.Parse(testPair.name)
    73  			if out != testPair.out {
    74  				t.Fatalf("Parse(%q) => %q, want %q", testPair.name, out, testPair.out)
    75  			}
    76  		})
    77  	}
    78  }