Skip to content

Commit

Permalink
Add inital integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Jul 23, 2020
1 parent 7005680 commit 2f62c63
Show file tree
Hide file tree
Showing 11 changed files with 340 additions and 20 deletions.
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,18 @@ PROTOS ?= gnmi_ext/gnmi_ext gnmi/gnmi collector/collect
target/target

include Makefile.in

### tests/integration/deps
##### ensure integration test dependencies are available
.PHONY: tests/integration/deps
tests/integration/deps:
$(call command_check,go)
@{ type gnmi_target > /dev/null 2>&1 \
|| go install -v github.com/google/gnxi/gnmi_target; \
}

### tests
##### execute tests
.PHONY: tests
tests: | tests/integration/deps
@pytest tests/
71 changes: 52 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ betterproto = { version = "^2.0.0b1", allow-prereleases = true }
[tool.poetry.dev-dependencies]
grpcio-tools = "^1.30.0"
black = "^19.10b0"
pytest-grpc = "^0.8.0"
pytest = "^5.4.3"
pytest-asyncio = "^0.12.0"
betterproto = { version = "^2.0.0b1", allow-prereleases = true, extras = ["compiler"] }

[tool.black]
Expand All @@ -40,3 +40,18 @@ exclude = '''
| _pb2(_grpc)?\.py
)
'''

[tool.tox]
legacy_tox_ini = """
[tox]
minversion = 3.3.0
isolated_build = True
envlist = py36, py37, py38
[testenv]
whitelist_externals = poetry
skip_install = true
commands =
poetry install
poetry run pytest {posargs} tests/
"""
4 changes: 4 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from pathlib import Path

TESTS_DIR = Path(__file__).parent
FIXTURES_DIR = TESTS_DIR / "fixtures"
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def pytest_addoption(parser):
parser.addoption(
"--skip-integration",
action="store_true",
dest="skip_integration",
default=False,
help="skip integration tests",
)


def pytest_configure(config):
config.addinivalue_line("markers", "integration: mark integration tests")

if config.option.skip_integration:
setattr(config.option, "markexpr", "not integration")
Empty file added tests/fixtures/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions tests/integration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from pathlib import Path

INTEGRATION_FIXTURES_DIR = Path(__file__).parent / "fixtures"
37 changes: 37 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import gnmi.proto
import grpclib.client
import pytest

from tests.integration.target import Target, TargetConfig


@pytest.fixture
def target_config() -> TargetConfig:
return TargetConfig()


@pytest.fixture
async def target(target_config) -> Target:
async with Target(config=target_config) as t:
yield t


@pytest.fixture
def channel(target) -> grpclib.client.Channel:
return grpclib.client.Channel(host="127.0.0.1", port=target.config.port, ssl=None)


@pytest.fixture
def service(target, channel) -> gnmi.proto.gNMIStub:
return gnmi.proto.gNMIStub(
channel,
metadata={
"username": target.config.username,
"password": target.config.password,
},
)


@pytest.fixture
def service_unauthenticated(channel) -> gnmi.proto.gNMIStub:
return gnmi.proto.gNMIStub(channel)
83 changes: 83 additions & 0 deletions tests/integration/fixtures/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"openconfig-interfaces:interfaces": {
"interface": [
{
"name": "admin",
"config": {
"name": "admin"
}
}
]
},
"openconfig-system:system": {
"aaa": {
"authentication": {
"admin-user": {
"config": {
"admin-password": "password"
}
},
"config": {
"authentication-method": [
"openconfig-aaa-types:LOCAL"
]
}
}
},
"clock": {
"config": {
"timezone-name": "Europe/Stockholm"
}
},
"config": {
"hostname": "zz-tri-dev01",
"domain-name": "foo.bar.com",
"login-banner": "This device is for authorized use only",
"motd-banner": "Welcome to Open vSwitch"
},
"openconfig-openflow:openflow": {
"agent": {
"config": {
"backoff-interval": 5,
"datapath-id": "00:16:3e:00:00:00:00:00",
"failure-mode": "SECURE",
"inactivity-probe": 10,
"max-backoff": 10
}
},
"controllers": {
"controller": [
{
"config": {
"name": "main"
},
"connections": {
"connection": [
{
"aux-id": 0,
"config": {
"address": "192.0.2.10",
"aux-id": 0,
"port": 6633,
"priority": 1,
"source-interface": "admin",
"transport": "TLS"
},
"state": {
"address": "192.0.2.10",
"aux-id": 0,
"port": 6633,
"priority": 1,
"source-interface": "admin",
"transport": "TLS"
}
}
]
},
"name": "main"
}
]
}
}
}
}
Loading

0 comments on commit 2f62c63

Please sign in to comment.