Skip to content

Commit

Permalink
Update tests to the newer testflows version
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-zaitsev committed Feb 12, 2021
1 parent c35bfe7 commit 8298522
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 55 deletions.
2 changes: 1 addition & 1 deletion tests/kubectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import manifest
import util

from testflows.core import TestScenario, Name, When, Then, Given, And, main, run, Module
from testflows.core import TestScenario, Name, When, Then, Given, And, main, Module
from testflows.asserts import error
from testflows.connect import Shell

Expand Down
3 changes: 1 addition & 2 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
testflows>=1.3.44,<1.4
testflows.core>=1.3,<1.4
testflows==1.6.72
PyYAML
8 changes: 4 additions & 4 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import test_clickhouse
import util

from testflows.core import TestScenario, Name, When, Then, Given, And, main, run, Module, TE, args, Fail, Error
from testflows.core import TestScenario, Name, When, Then, Given, And, main, Scenario, Module, TE, args, Fail, Error
from testflows.asserts import error

if main():
Expand Down Expand Up @@ -77,9 +77,9 @@

for t in run_tests:
if callable(t):
run(test=t)
Scenario(test=t)()
else:
run(test=t[0], args=t[1])
Scenario(test=t[0], args=t[1])()

# python3 tests/test.py --only clickhouse*
with Module("clickhouse"):
Expand All @@ -94,4 +94,4 @@
# run_test = [test_ch_002]

for t in run_test:
run(test=t)
Scenario(test=t)()
6 changes: 3 additions & 3 deletions tests/test_clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import settings
from test_operator import require_zookeeper

from testflows.core import TestScenario, Name, When, Then, Given, And, main, run, Module, TE
from testflows.core import TestScenario, Name, When, Then, Given, And, main, Scenario, Module, TE
from testflows.asserts import error


@TestScenario
@Name("test_ch_001. Insert quorum")
def test_ch_001():
def test_ch_001(self):
require_zookeeper()

create_and_check(
Expand Down Expand Up @@ -114,7 +114,7 @@ def test_ch_001():

@TestScenario
@Name("test_ch_002. Row-level security")
def test_ch_002():
def test_ch_002(self):
create_and_check(
"configs/test-ch-002-row-level.yaml",
{
Expand Down
25 changes: 11 additions & 14 deletions tests/test_metrics_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
import json

from testflows.core import TestScenario, Name, When, Then, Given, And, main, run, Module, TE
from testflows.core import TestScenario, Name, When, Then, Given, And, main, Scenario, Module, TE
from testflows.asserts import error

import kubectl
Expand All @@ -17,18 +17,18 @@ def set_metrics_exporter_version(version, ns=settings.operator_namespace):

@TestScenario
@Name("Check metrics server setup and version")
def test_metrics_exporter_setup():
def test_metrics_exporter_setup(self):
with Given("clickhouse-operator is installed"):
assert kubectl.get_count("pod", ns='--all-namespaces', label="-l app=clickhouse-operator") > 0, error()
with And(f"Set metrics-exporter version {settings.operator_version}"):
with Then(f"Set metrics-exporter version {settings.operator_version}"):
set_metrics_exporter_version(settings.operator_version)


@TestScenario
@Name("Check metrics server state after reboot")
def test_metrics_exporter_reboot():
def test_metrics_exporter_reboot(self):
def check_monitoring_chi(operator_namespace, operator_pod, expect_result, max_retries=10):
with And(f"metrics-exporter /chi enpoint result should return {expect_result}"):
with Then(f"metrics-exporter /chi enpoint result should return {expect_result}"):
for i in range(1, max_retries):
# check /metrics for try to refresh monitored instances
kubectl.launch(
Expand Down Expand Up @@ -89,9 +89,9 @@ def check_monitoring_chi(operator_namespace, operator_pod, expect_result, max_re

@TestScenario
@Name("Check metrics server help with different clickhouse version")
def test_metrics_exporter_with_multiple_clickhouse_version():
def test_metrics_exporter_with_multiple_clickhouse_version(self):
def check_monitoring_metrics(operator_namespace, operator_pod, expect_result, max_retries=10):
with And(f"metrics-exporter /metrics enpoint result should match with {expect_result}"):
with Then(f"metrics-exporter /metrics enpoint result should match with {expect_result}"):
for i in range(1, max_retries):
out = kubectl.launch(
f"exec {operator_pod} -c metrics-exporter -- wget -O- -q http://127.0.0.1:8888/metrics",
Expand Down Expand Up @@ -127,9 +127,9 @@ def check_monitoring_metrics(operator_namespace, operator_pod, expect_result, ma
config=config,
check={
"object_counts": {
"statefulset": 4,
"pod": 4,
"service": 5,
"statefulset": 2,
"pod": 2,
"service": 3,
},
"do_not_delete": True,
})
Expand All @@ -139,9 +139,6 @@ def check_monitoring_metrics(operator_namespace, operator_pod, expect_result, ma
'# TYPE chi_clickhouse_metric_VersionInteger gauge': True,
'chi_clickhouse_metric_VersionInteger{chi="test-017-multi-version",hostname="chi-test-017-multi-version-default-0-0': True,
'chi_clickhouse_metric_VersionInteger{chi="test-017-multi-version",hostname="chi-test-017-multi-version-default-1-0': True,
'chi_clickhouse_metric_VersionInteger{chi="test-017-multi-version",hostname="chi-test-017-multi-version-default-2-0': True,
'chi_clickhouse_metric_VersionInteger{chi="test-017-multi-version",hostname="chi-test-017-multi-version-default-3-0': True,

})

with Then("check empty /metrics after delete namespace"):
Expand All @@ -159,4 +156,4 @@ def check_monitoring_metrics(operator_namespace, operator_pod, expect_result, ma
test_metrics_exporter_with_multiple_clickhouse_version,
]
for t in test_cases:
run(test=t, flags=TE)
Scenario(test=t, flags=TE)()
Loading

0 comments on commit 8298522

Please sign in to comment.