Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add tests #28

Merged
merged 6 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.11]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install pipenv
run: pip install pipenv==2023.5.19

- name: Install dependencies
run: pipenv install --skip-lock -d

- name: Check isort
run: pipenv run isort . --check-only --diff --quiet

- name: Check flake8
run: pipenv run lint
18 changes: 11 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
name: Test
on: [push, pull_request]
env:
NIFCLOUD_DEFAULT_REGION: 'jp-east-1'
NIFCLOUD_ACCESS_KEY_ID: ${{ secrets.NIFCLOUD_ACCESS_KEY_ID }}
NIFCLOUD_SECRET_ACCESS_KEY: ${{ secrets.NIFCLOUD_SECRET_ACCESS_KEY }}
NIFCLOUD_STORAGE_ACCESS_KEY_ID: ${{ secrets.NIFCLOUD_STORAGE_ACCESS_KEY_ID }}
NIFCLOUD_STORAGE_SECRET_ACCESS_KEY: ${{ secrets.NIFCLOUD_STORAGE_SECRET_ACCESS_KEY }}
jobs:
lint:
test:
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
python-version: [3.11]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -21,8 +28,5 @@ jobs:
- name: Install dependencies
run: pipenv install --skip-lock -d

- name: Check isort
run: pipenv run isort . --check-only --diff --quiet

- name: Check flake8
run: pipenv run lint
- name: Run tests
run: pipenv run test
4 changes: 4 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ isort = "*"
cx-freeze = "==6.15.0"
sphinx = {version = "==5.3.0", sys_platform = "!= 'win32'"}
sphinx-rtd-theme = {version = "*", sys_platform = "!= 'win32'"}
pytest = "*"
pytest-cov = "*"

[scripts]
isort = "isort"
lint = "flake8"
test = "pytest --capture=sys"
unittest = "pytest tests/unit --capture=sys"
107 changes: 104 additions & 3 deletions Pipfile.lock

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

1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ per-file-ignores =
nifcloudcli/customizations/configure/get.py:E501
nifcloudcli/customizations/configure/set.py:E501
build/**/*.py:E501
max-line-length = 120
Empty file added tests/integration/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions tests/integration/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import json
import os
import pathlib
from subprocess import PIPE, Popen


def nifcloud(cmd, raw_output=False):
repo_root = pathlib.Path(__file__).parent.parent.parent
nifcloud_cmd = os.path.join(repo_root, "bin", "nifcloud")
if not os.path.isfile(nifcloud_cmd):
raise ValueError('Could not find "nifcloud" executable.')

full_command = f"python {nifcloud_cmd} {cmd}"
env = os.environ.copy()
process = Popen(
full_command, stdout=PIPE, stderr=PIPE, stdin=PIPE, shell=True, env=env
)

stdout, stderr = process.communicate()
if process.returncode != 0:
raise ValueError(
f"return code is not 0 ({process.returncode}). stdout: {stdout.decode()} stderr: {stderr.decode()}"
)

if raw_output:
return stdout.decode()

return json.loads(stdout.decode())
18 changes: 18 additions & 0 deletions tests/integration/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from .helper import nifcloud


class TestCLI:
def test_cli_help(self):
res = nifcloud("help", raw_output=True)
available_services = [
"computing",
"rdb",
"nas",
"dns",
"ess",
"script",
"storage",
"service-activity",
]
for service in available_services:
assert service in res
43 changes: 43 additions & 0 deletions tests/integration/test_computing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from .helper import nifcloud


class TestComputing:
def test_computing_describe_instances(self):
res = nifcloud("computing describe-instances")
assert len(res["ReservationSet"]) == 0

def test_computing_describe_regions(self):
res = nifcloud("computing describe-regions")
expected_regions = [
{
"RegionName": "east-1",
"RegionEndpoint": "jp-east-1.computing.api.nifcloud.com",
},
{
"RegionName": "east-2",
"RegionEndpoint": "jp-east-2.computing.api.nifcloud.com",
},
{
"RegionName": "east-3",
"RegionEndpoint": "jp-east-3.computing.api.nifcloud.com",
},
{
"RegionName": "jp-east-4",
"RegionEndpoint": "jp-east-4.computing.api.nifcloud.com",
},
{
"RegionName": "west-1",
"RegionEndpoint": "jp-west-1.computing.api.nifcloud.com",
},
{
"RegionName": "jp-west-2",
"RegionEndpoint": "jp-west-2.computing.api.nifcloud.com",
},
{
"RegionName": "us-east-1",
"RegionEndpoint": "us-east-1.computing.api.nifcloud.com",
},
]
for actual, expected in zip(res["RegionInfo"], expected_regions):
assert actual["RegionName"] == expected["RegionName"]
assert actual["RegionEndpoint"] == expected["RegionEndpoint"]
7 changes: 7 additions & 0 deletions tests/integration/test_dns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .helper import nifcloud


class TestDNS:
def test_dns_list_hosted_zones(self):
res = nifcloud("dns list-hosted-zones")
assert len(res["HostedZones"]) == 1
17 changes: 17 additions & 0 deletions tests/integration/test_ess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from .helper import nifcloud


class TestESS:
def test_ess_list_identities(self):
res = nifcloud("ess list-identities")
assert len(res["Identities"]) == 0

def test_ess_get_send_quota(self):
res = nifcloud("ess get-send-quota")
assert res["Max24HourSend"] == 2500000.0
assert res["MaxSendRate"] == 50.0
assert res["SentLast24Hours"] == 0.0

def test_ess_get_send_statistics(self):
res = nifcloud("ess get-send-statistics")
assert len(res["SendDataPoints"]) == 0
7 changes: 7 additions & 0 deletions tests/integration/test_nas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .helper import nifcloud


class TestNAS:
def test_nas_describe_nas_instances(self):
res = nifcloud("nas describe-nas-instances")
assert len(res["NASInstances"]) == 0
20 changes: 20 additions & 0 deletions tests/integration/test_rdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from .helper import nifcloud


class TestRDB:
def test_rdb_describe_db_instances(self):
res = nifcloud("rdb describe-db-instances")
assert len(res["DBInstances"]) == 0

def test_rdb_describe_db_engine_versions(self):
res = nifcloud(
"rdb describe-db-engine-versions --engine=mysql --engine-version=5.7.15"
)
db_engine_versions = res["DBEngineVersions"]
assert len(db_engine_versions) == 1
db_engine_version = db_engine_versions[0]
assert db_engine_version["DBEngineDescription"] == "MySQL Community Edition"
assert db_engine_version["DBEngineVersionDescription"] == "MySQL 5.7.15"
assert db_engine_version["DBParameterGroupFamily"] == "mysql5.7"
assert db_engine_version["Engine"] == "mysql"
assert db_engine_version["EngineVersion"] == "5.7.15"
7 changes: 7 additions & 0 deletions tests/integration/test_service_activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .helper import nifcloud


class TestServiceActivity:
def test_service_activity_describe_service_statuses(self):
res = nifcloud("service-activity describe-service-statuses")
assert len(res["Data"]["ServiceMenu"]) != 0
Loading
Loading