Skip to content
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
46 changes: 46 additions & 0 deletions libs/garf_executors/tests/end-to-end/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"resource": "Campaign A",
"dimensions": {
"name": "Ad Group 1",
"id": 101
},
"metrics": {
"clicks": 1500,
"cost": 250.75
}
},
{
"resource": "Campaign B",
"dimensions": {
"name": "Ad Group 2",
"id": 102
},
"metrics": {
"clicks": 2300,
"cost": 410.20
}
},
{
"resource": "Campaign C",
"dimensions": {
"name": "Ad Group 3",
"id": 103
},
"metrics": {
"clicks": 800,
"cost": 120.50
}
},
{
"resource": "Campaign A",
"dimensions": {
"name": "Ad Group 4",
"id": 104
},
"metrics": {
"clicks": 3200,
"cost": 600.00
}
}
]
69 changes: 69 additions & 0 deletions libs/garf_executors/tests/end-to-end/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# pylint: disable=C0330, g-bad-import-order, g-multiple-import, missing-class-docstring, missing-module-docstring, missing-function-docstring

import json
import pathlib
import subprocess

_SCRIPT_PATH = pathlib.Path(__file__).parent


class TestApiQueryExecutor:
def test_fake_source(self):
fake_data = _SCRIPT_PATH / 'test.json'
query = (
'SELECT resource, dimensions.name AS name, metrics.clicks AS clicks '
'FROM resource'
)
command = (
f'garf "{query}" --input console --source fake '
f'--source.data_location={fake_data} '
'--output console --console.format=json '
'--loglevel ERROR'
)
result = subprocess.run(
command,
shell=True,
check=False,
capture_output=True,
text=True,
)

expected_output = [
{
'resource': 'Campaign A',
'name': 'Ad Group 1',
'clicks': 1500,
},
{
'resource': 'Campaign B',
'name': 'Ad Group 2',
'clicks': 2300,
},
{
'resource': 'Campaign C',
'name': 'Ad Group 3',
'clicks': 800,
},
{
'resource': 'Campaign A',
'name': 'Ad Group 4',
'clicks': 3200,
},
]

assert result.returncode == 0
assert json.loads(result.stdout) == expected_output
Loading