def test_sysdig_embedded_token(self): """Test Sysdig with an embedded token""" with requests_mock.mock(real_http=True) as req_mock: sde = MetricResource(**sysdig_embedded) url = sde.spec.urlTemplate response_json = { "data": [{ "t": 1582756200, "d": [6.481] }], "start": 1582755600, "end": 1582756200 } req_mock.register_uri('POST', url, json = response_json, status_code = 200, \ request_headers={'Authorization': 'Bearer 87654321-1234-1234-1234-123456789012'}) expr = ExperimentResource(**er_example) version = expr.spec.versionInfo.baseline version.variables = [ NamedValue(name="userfilter", value='usergroup!~"wakanda"'), NamedValue(name="revision", value='sample-app-v1') ] start_time = expr.status.startTime # verify body body, err = get_body(sde, version, start_time) logger.info(body) assert err is None groups = re.search("'sample-app-v1'", body["filter"]) assert groups is not None # verify jq expression value, err = get_metric_value(sde, version, start_time) assert err is None assert value == 6.481
def test_body(self): """body must interpolate elapsedTime and version name""" expr = ExperimentResource(**er_example) metric_info = MetricInfo(**cpu_utilization) version = expr.spec.versionInfo.baseline start_time = expr.status.startTime body, err = get_body(metric_info.metricObj, version, start_time) assert err is None assert body["last"] > 32931645 assert body[ "filter"] == "kubernetes.node.name = 'n1' and service = 'default'"
def test_elastic_secret(self, mock_secret): """Test Sysdig with a secret token""" with requests_mock.mock(real_http=True) as req_mock: ela = MetricResource(**elastic_secret) url = ela.spec.urlTemplate response_json = { "aggregations": { "items_to_sell": { "doc_count": 3, "avg_sales": { "value": 128.33333333333334 } } } } req_mock.register_uri('POST', url, json = response_json, status_code = 200, \ request_headers={'Authorization': 'Basic cHJvZHVzZXI6dDBwLXNlY3JldA=='}) mock_secret.return_value = ({ "username": "******", "password": "******" }, None) expr = ExperimentResource(**er_example) version = expr.spec.versionInfo.baseline version.variables = [ NamedValue(name="userfilter", value='usergroup!~"wakanda"'), NamedValue(name="revision", value='sample-app-v1') ] start_time = expr.status.startTime # verify body body, err = get_body(ela, version, start_time) logger.info(body) assert err is None groups = re.search( "sample-app-v1", body["aggs"]["items_to_sell"]["filter"]["term"]["version"]) assert groups is not None # verify jq expression value, err = get_metric_value(ela, version, start_time) assert err is None assert value == 128.33333333333334