示例#1
0
文件: test_base.py 项目: run-x/opta
    def test_process_ports_multi_port(
            self, processor: K8sServiceModuleProcessor) -> None:
        input = {
            "ports": [
                {
                    "name": "a",
                    "type": "http",
                    "port": 1
                },
                {
                    "name": "b",
                    "type": "tcp",
                    "port": 2
                },
            ],
            "probe_port":
            "b",
        }

        port_a = PortSpec("a", "http", 1, 80)
        port_b = PortSpec("b", "tcp", 2, 2)

        expected = {
            "ports": [port_a, port_b],
            "http_port": port_a,
            "probe_port": port_b,
            "service_annotations": {
                "nginx.opta.dev/extra-tcp-ports": '{"2": "b"}'
            },
        }

        self.process_ports_assert(processor, input, expected=expected)
示例#2
0
文件: test_base.py 项目: run-x/opta
    def test_to_json(self) -> None:
        spec = PortSpec("a", "http", 1, 80, "grpc", True)
        expected = {
            "name": "a",
            "type": "http",
            "port": 1,
            "servicePort": 80,
            "protocol": "grpc",
            "tls": True,
            "probeType": "tcp",
        }

        assert spec.__to_json__() == expected
示例#3
0
文件: test_base.py 项目: run-x/opta
    def test_validate_ports_duplicate_num(
            self, processor: K8sServiceModuleProcessor) -> None:
        ports = [
            PortSpec("a", "http", 1, 80),
            PortSpec("b", "tcp", 1, 80),
        ]

        self.validate_ports_assert(
            processor,
            ports,
            exception_type=UserErrors,
            exception_message="Duplicate port number `1`",
        )
示例#4
0
文件: test_base.py 项目: run-x/opta
    def test_validate_ports_multiple_http(
            self, processor: K8sServiceModuleProcessor) -> None:
        ports = [
            PortSpec("a", "http", 1, 80),
            PortSpec("b", "http", 2, 80),
        ]

        self.validate_ports_assert(
            processor,
            ports,
            exception_type=UserErrors,
            exception_message="Multiple `type: http` ports not supported",
        )
示例#5
0
文件: test_base.py 项目: run-x/opta
    def test_validate_ports_flag_disabled_multiple(
            self, processor: K8sServiceModuleProcessor) -> None:
        processor.FLAG_MULTIPLE_PORTS_SUPPORTED = False

        ports = [
            PortSpec("a", "http", 1, 80),
            PortSpec("b", "http", 2, 80),
        ]

        self.validate_ports_assert(
            processor,
            ports,
            exception_type=UserErrors,
            exception_message="Cannot specify multiple ports in this cloud",
        )
示例#6
0
文件: test_base.py 项目: run-x/opta
    def test_read_ports(self, processor: K8sServiceModuleProcessor) -> None:
        raw = [{"name": "a", "port": 1, "type": "http"}]

        expected = [
            PortSpec("a", "http", 1, 80),
        ]

        self.read_ports_assert(processor, raw, expected=expected)
示例#7
0
文件: test_base.py 项目: run-x/opta
    def test_valid_type_protocols(self) -> None:
        protos = PortSpec.valid_type_protocols()

        assert len(protos) > 0

        for type, protocol in protos:
            assert len(type) > 0
            if protocol:
                assert len(protocol) > 0
示例#8
0
文件: test_base.py 项目: run-x/opta
 def test_from_raw_simple(self) -> None:
     self.from_raw_assert(
         {
             "name": "a",
             "type": "http",
             "port": 1
         },
         expected=PortSpec("a", "http", 1, 80, None, False),
     )
示例#9
0
文件: test_base.py 项目: run-x/opta
    def test_probe_type(self) -> None:
        tests: Dict[Tuple[str, Optional[str]], str] = {
            ("http", None): "http",
            ("http", "grpc"): "tcp",
            ("tcp", None): "tcp",
        }

        for input, expected in tests.items():
            spec = PortSpec("a", input[0], 1, 80, input[1])
            assert spec.probe_type == expected
示例#10
0
文件: test_base.py 项目: run-x/opta
    def from_raw_assert(
        self,
        raw: Dict[str, Any],
        *,
        expected: Optional[PortSpec] = None,
        exception_type: Optional[Type[Exception]] = None,
        exception_message: Optional[str] = None,
    ) -> None:

        if exception_type:
            with pytest.raises(exception_type) as e:
                PortSpec.from_raw(raw)

            if exception_message is not None:
                assert str(e.value) == exception_message
        else:
            actual = PortSpec.from_raw(raw)

            assert actual == expected
示例#11
0
文件: test_base.py 项目: run-x/opta
 def test_from_raw_advanced(self) -> None:
     self.from_raw_assert(
         {
             "name": "a",
             "type": "http",
             "port": 1,
             "protocol": "grpc",
             "tls": True
         },
         expected=PortSpec("a", "http", 1, 80, "grpc", True),
     )
示例#12
0
文件: test_base.py 项目: run-x/opta
 def test_is_tcp(self) -> None:
     assert PortSpec("a", "http", 1, 80).is_tcp is False
     assert PortSpec("a", "tcp", 1, 80).is_tcp is True
示例#13
0
文件: test_base.py 项目: run-x/opta
    def test_legacy_port_type_mapping(self) -> None:
        mapping = PortSpec.legacy_port_type_mapping()
        valid_types = PortSpec.valid_type_protocols()

        for type_protocol in mapping.values():
            assert type_protocol in valid_types