add nimbus-fml coverage, update python tests

This commit is contained in:
Charlie 2023-05-18 20:52:09 -04:00
Родитель 023d4727b2
Коммит becc00c482
3 изменённых файлов: 87 добавлений и 1 удалений

2
automation/emit_coverage_info.sh Normal file → Executable file
Просмотреть файл

@ -41,7 +41,7 @@ export RUSTDOCFLAGS="-Cpanic=abort"
# Apparently --no-default-features doesn't work in the root, even with -p to select a specific package.
# Instead we pull the list of individual package manifest files which have default features
# out of `cargo metadata` and test using --manifest-path for each individual package.
for manifest in $(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select((.features | .default | length) > 0) | .manifest_path'); do
for manifest in $(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select((.features | .default | length) > 0 or .name == "nimbus-fml") | .manifest_path'); do
package=$(dirname "$manifest")
package=$(basename "$package")
echo "## no-default-features test for package $package (manifest @ $manifest)"

Просмотреть файл

@ -94,6 +94,66 @@ def client(app_context, experiment):
return c
@pytest.fixture(scope="class")
def cirrus_client(request):
app_context = json.dumps(
{
"app_id": "test app id",
"app_name": "test app name",
"channel": "dev",
}
)
bucket_config = {
"randomizationUnit": "user_id",
"count": 100,
"namespace": "",
"start": 1,
"total": 100,
}
branches = [
{
"slug": "control",
"ratio": 1,
"feature": {
"featureId": "imported-module-1-included-feature-1",
"value": {"enabled": False},
},
},
{
"slug": "treatment",
"ratio": 1,
"feature": {
"featureId": "imported-module-1-included-feature-1",
"value": {"enabled": True},
},
},
]
experiment = {
"schemaVersion": "1.0.0",
"slug": "experiment-slug",
"userFacingName": "",
"userFacingDescription": "",
"appId": "test app id",
"appName": "test app name",
"channel": "dev",
# Use is_already_enrolled for sticky targeting, otherwise we check lang, region, and a custom attribute
"targeting": '(is_already_enrolled) || (username in ["test", "jeddai"])',
"bucketConfig": bucket_config,
"isRollout": False,
"isEnrollmentPaused": False,
"proposedEnrollment": 10,
"branches": branches,
"featureIds": ["imported-module-1-included-feature-1"],
}
request.cls.cirrus_client = CirrusClient(app_context)
data = json.dumps({"data": [experiment]})
request.cls.cirrus_client.set_experiments(data)
@pytest.fixture(scope="class")
def fml_client(request):
def _client(_, path, channel):

Просмотреть файл

@ -0,0 +1,26 @@
import json
import pytest
import unittest
@pytest.mark.usefixtures("fml_client", "cirrus_client")
class TestCirrusClientFmlClientIntegration(unittest.TestCase):
def test_enroll_and_get_enrolled_feature_json(self):
req_1 = json.dumps(
{
"clientId": "test",
"requestContext": {"username": "test"},
}
)
res_1 = json.loads(self.cirrus_client.handle_enrollment(req_1))
feature_configs = json.dumps(
[value["feature"] for value in res_1["enrolledFeatureConfigMap"].values()]
)
print(res_1)
fml_client = self.fml_client("test-include-import.fml.yml", "developer")
merged_res_1 = fml_client.validate_feature_configs_and_merge_into_defaults(
feature_configs
)
merged_res_json_1 = json.loads(merged_res_1.json)
print(merged_res_json_1)