Skip to content

Commit

Permalink
Merge pull request #11 from canonical/validate_int_tests
Browse files Browse the repository at this point in the history
test: update failing int tests
  • Loading branch information
marcoppenheimer authored Jul 25, 2022
2 parents 17ed94d + 8640271 commit 99bfb0c
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 54 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Testing

on:
pull_request:


jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: python3 -m pip install tox
- name: Run linters
run: tox -e lint

unit-test:
name: Unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: python -m pip install tox
- name: Run tests
run: tox -e unit

integration-test-lxd:
name: Integration tests for (lxd)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: lxd
- name: Run integration tests
run: tox -e integration
38 changes: 0 additions & 38 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,10 @@ jobs:
credentials: "${{ secrets.CHARMHUB_TOKEN }}" # FIXME: current token will expire in 2023-07-04
github-token: "${{ secrets.GITHUB_TOKEN }}"

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: python3 -m pip install tox
- name: Run linters
run: tox -e lint

unit-test:
name: Unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: python -m pip install tox
- name: Run tests
run: tox -e unit

integration-test-lxd:
name: Integration tests for (lxd)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: lxd
- name: Run integration tests
run: tox -e integration

release-to-charmhub:
name: Release to CharmHub
needs:
- lib-check
- lint
- unit-test
- integration-test-lxd
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import subprocess

from charms.kafka.v0.kafka_snap import KafkaSnap
from kafka_provides import KafkaProvider
from ops.charm import CharmBase, RelationEvent, RelationJoinedEvent
from ops.framework import EventBase
from ops.main import main
Expand All @@ -24,6 +23,7 @@

from connection_check import broker_active, zookeeper_connected
from kafka_config import KafkaConfig
from kafka_provider import KafkaProvider

logger = logging.getLogger(__name__)

Expand Down
6 changes: 1 addition & 5 deletions tests/integration/app-charm/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ def _on_start(self, _) -> None:
self.unit.status = ActiveStatus()

def _set_data(self, _) -> None:
if not self.unit.is_leader():
return

# reasonable confidence there won't be conflicting chroots
self.relation.data[self.app].update({"password": "thisisatestpassword"})
return

def _log(self, event: RelationEvent):
return
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_zookeeper_connection(unit_name: str, model_full_name: str) -> Tuple[List
for info in relations_info:
if info["endpoint"] == "cluster":
for key in info["application-data"].keys():
if re.match(r"(relation\-[/d]+)", key):
if re.match(r"(relation\-[\d]+)", key):
usernames.append(key)
if info["endpoint"] == "zookeeper":
zookeeper_uri = info["application-data"]["uris"]
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ async def test_build_and_deploy(ops_test: OpsTest):
kafka_charm = await ops_test.build_charm(".")
await asyncio.gather(
ops_test.model.deploy(
"zookeeper", channel="edge", application_name="zookeeper", num_units=3
"zookeeper", channel="edge", application_name="zookeeper", num_units=1
),
ops_test.model.deploy(kafka_charm, application_name="kafka", num_units=3),
ops_test.model.deploy(kafka_charm, application_name="kafka", num_units=1),
)
await ops_test.model.wait_for_idle(apps=["kafka", "zookeeper"])
assert ops_test.model.applications["kafka"].status == "waiting"
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/test_kafka_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@pytest.fixture(scope="module")
def usernames():
return {}
return set()


@pytest.mark.abort_on_fail
Expand All @@ -30,9 +30,9 @@ async def test_deploy_charms_relate_active(ops_test: OpsTest, usernames):

await asyncio.gather(
ops_test.model.deploy(
"zookeeper", channel="edge", application_name="zookeeper", num_units=3
"zookeeper", channel="edge", application_name="zookeeper", num_units=1
),
ops_test.model.deploy(zk_charm, application_name=APP_NAME, num_units=3),
ops_test.model.deploy(zk_charm, application_name=APP_NAME, num_units=1),
ops_test.model.deploy(app_charm, application_name=DUMMY_NAME_1, num_units=1),
)
await ops_test.model.wait_for_idle(apps=[APP_NAME, DUMMY_NAME_1, ZK])
Expand All @@ -47,7 +47,7 @@ async def test_deploy_charms_relate_active(ops_test: OpsTest, usernames):
returned_usernames, zookeeper_uri = get_zookeeper_connection(
unit_name="kafka/0", model_full_name=ops_test.model_full_name
)
usernames.add(returned_usernames)
usernames.update(returned_usernames)

for username in usernames:
check_user(
Expand All @@ -71,7 +71,7 @@ async def test_deploy_multiple_charms_relate_active(ops_test: OpsTest, usernames
returned_usernames, zookeeper_uri = get_zookeeper_connection(
unit_name="kafka/0", model_full_name=ops_test.model_full_name
)
usernames.add(returned_usernames)
usernames.update(returned_usernames)

for username in usernames:
check_user(
Expand All @@ -87,7 +87,7 @@ async def test_remove_application_removes_user(ops_test: OpsTest, usernames):
await ops_test.model.wait_for_idle(apps=[APP_NAME])
assert ops_test.model.applications[APP_NAME].status == "active"

usernames, zookeeper_uri = get_zookeeper_connection(
_, zookeeper_uri = get_zookeeper_connection(
unit_name="kafka/0", model_full_name=ops_test.model_full_name
)

Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ description = Short refresh script for charm-dev
commands =
/bin/bash -ec "juju destroy-model {[vars]application} --force --destroy-storage --no-wait"
/bin/bash -ec "juju add-model {[vars]application}"
/bin/bash -ec "juju deploy zookeeper --channel latest/edge -n 3 --revision 66"
/bin/bash -ec "juju deploy zookeeper --channel edge -n 3"
/bin/bash -ec "charmcraft pack"
/bin/bash -ec "juju deploy ./*.charm -n 3"
/bin/bash -ec "juju relate kafka zookeeper"

[testenv:fmt]
description = Apply coding style standards to code
Expand Down

0 comments on commit 99bfb0c

Please sign in to comment.