|
| 1 | +# SPDX-FileCopyrightText: 2018-present Pavel Cisar <[email protected]> |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +""" |
| 6 | +ID: butler-fbsd-protobuf |
| 7 | +TITLE: FDSD protobuf |
| 8 | +DESCRIPTION: |
| 9 | +NOTES: |
| 10 | +""" |
| 11 | + |
| 12 | +import pytest |
| 13 | +import uuid |
| 14 | +import firebird.butler.fbsd_pb2 as fbsd |
| 15 | + |
| 16 | +_PEER_UID = uuid.uuid1().bytes |
| 17 | +_PID = 100 |
| 18 | +_HOST = 'host' |
| 19 | +_AGENT_UID = uuid.uuid1().bytes |
| 20 | +_NAME = 'Agent name' |
| 21 | +_AGENT_VERSION = 'agent version' |
| 22 | +_VENDOR_ID = uuid.uuid1().bytes |
| 23 | +_PLATFORM_ID = uuid.uuid1().bytes |
| 24 | +_PLATFORM_VERSION = 'platform version' |
| 25 | +_CLASSIFICATION = 'classification' |
| 26 | +_API_NUM = 1 |
| 27 | +_API_ID = uuid.uuid1().bytes |
| 28 | +_ERR_CODE = 100 |
| 29 | +_ERR_DESCRIPTION = "Fatal error" |
| 30 | +_ERR_CONTEXT_KEY = "Context key" |
| 31 | +_ERR_CONTEXT_VALUE = "Context value" |
| 32 | +_ERR_ANNOTATION_KEY = "Annotation key" |
| 33 | +_ERR_ANNOTATION_VALUE = "Annotation value" |
| 34 | + |
| 35 | +def test_StateEnum(): |
| 36 | + assert fbsd.StateEnum.STATE_RUNNING is fbsd.STATE_RUNNING |
| 37 | + |
| 38 | +def test_AddressDomainEnum(): |
| 39 | + assert fbsd.AddressDomainEnum.DOMAIN_LOCAL is fbsd.DOMAIN_LOCAL |
| 40 | + |
| 41 | +def test_TransportProtocolEnum(): |
| 42 | + assert fbsd.TransportProtocolEnum.PROTOCOL_INPROC is fbsd.PROTOCOL_INPROC |
| 43 | + |
| 44 | +def test_SocketTypeEnum(): |
| 45 | + assert fbsd.SocketTypeEnum.SOCKET_TYPE_ROUTER is fbsd.SOCKET_TYPE_ROUTER |
| 46 | + |
| 47 | +def test_SocketUseEnum(): |
| 48 | + assert fbsd.SocketUseEnum.SOCKET_USE_PRODUCER is fbsd.SOCKET_USE_PRODUCER |
| 49 | + |
| 50 | +def test_DependencyTypeEnum(): |
| 51 | + assert fbsd.DependencyTypeEnum.DEPTYPE_REQUIRED is fbsd.DEPTYPE_REQUIRED |
| 52 | + |
| 53 | +def test_PlatformId(): |
| 54 | + proto = fbsd.PlatformId() |
| 55 | + proto.uid = _PLATFORM_ID |
| 56 | + proto.version = _PLATFORM_VERSION |
| 57 | + msg = proto.SerializeToString() |
| 58 | + proto.Clear() |
| 59 | + proto.ParseFromString(msg) |
| 60 | + assert proto.uid == _PLATFORM_ID |
| 61 | + assert proto.version == _PLATFORM_VERSION |
| 62 | + |
| 63 | +def test_VendorId(): |
| 64 | + proto = fbsd.VendorId() |
| 65 | + proto.uid = _VENDOR_ID |
| 66 | + msg = proto.SerializeToString() |
| 67 | + proto.Clear() |
| 68 | + proto.ParseFromString(msg) |
| 69 | + assert proto.uid == _VENDOR_ID |
| 70 | + |
| 71 | +def test_AgentIdentification(): |
| 72 | + proto = fbsd.AgentIdentification() |
| 73 | + proto.uid = _AGENT_UID |
| 74 | + proto.name = _NAME |
| 75 | + proto.version = _AGENT_VERSION |
| 76 | + proto.vendor.uid = _VENDOR_ID |
| 77 | + proto.platform.uid = _PLATFORM_ID |
| 78 | + proto.platform.version = _PLATFORM_VERSION |
| 79 | + proto.classification = _CLASSIFICATION |
| 80 | + msg = proto.SerializeToString() |
| 81 | + proto.Clear() |
| 82 | + proto.ParseFromString(msg) |
| 83 | + assert proto.uid == _AGENT_UID |
| 84 | + assert proto.name == _NAME |
| 85 | + assert proto.version == _AGENT_VERSION |
| 86 | + assert proto.vendor.uid == _VENDOR_ID |
| 87 | + assert proto.platform.uid == _PLATFORM_ID |
| 88 | + assert proto.platform.version == _PLATFORM_VERSION |
| 89 | + assert proto.classification == _CLASSIFICATION |
| 90 | + |
| 91 | +def test_PeerIdentification(): |
| 92 | + proto = fbsd.PeerIdentification() |
| 93 | + proto.uid = _PEER_UID |
| 94 | + proto.host = _HOST |
| 95 | + proto.pid = _PID |
| 96 | + msg = proto.SerializeToString() |
| 97 | + proto.Clear() |
| 98 | + proto.ParseFromString(msg) |
| 99 | + assert proto.uid == _PEER_UID |
| 100 | + assert proto.host == _HOST |
| 101 | + assert proto.pid == _PID |
| 102 | + |
| 103 | +def test_InterfaceSpec(): |
| 104 | + proto = fbsd.InterfaceSpec(number=_API_NUM, uid=_API_ID) |
| 105 | + msg = proto.SerializeToString() |
| 106 | + proto.Clear() |
| 107 | + proto.ParseFromString(msg) |
| 108 | + assert proto.number == _API_NUM |
| 109 | + assert proto.uid == _API_ID |
| 110 | + |
| 111 | +def test_ErrorDescription(): |
| 112 | + proto = fbsd.ErrorDescription() |
| 113 | + proto.code = _ERR_CODE |
| 114 | + proto.description = _ERR_DESCRIPTION |
| 115 | + proto.context[_ERR_CONTEXT_KEY] = _ERR_CONTEXT_VALUE |
| 116 | + proto.annotation[_ERR_ANNOTATION_KEY] = _ERR_ANNOTATION_VALUE |
| 117 | + msg = proto.SerializeToString() |
| 118 | + proto.Clear() |
| 119 | + proto.ParseFromString(msg) |
| 120 | + assert proto.code == _ERR_CODE |
| 121 | + assert proto.description == _ERR_DESCRIPTION |
| 122 | + assert proto.context[_ERR_CONTEXT_KEY] == _ERR_CONTEXT_VALUE |
| 123 | + assert proto.annotation[_ERR_ANNOTATION_KEY] == _ERR_ANNOTATION_VALUE |
0 commit comments