Skip to content

Commit d3a8b8d

Browse files
[exec] tests: add end-to-end tests
1 parent e48000f commit d3a8b8d

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[
2+
{
3+
"resource": "Campaign A",
4+
"dimensions": {
5+
"name": "Ad Group 1",
6+
"id": 101
7+
},
8+
"metrics": {
9+
"clicks": 1500,
10+
"cost": 250.75
11+
}
12+
},
13+
{
14+
"resource": "Campaign B",
15+
"dimensions": {
16+
"name": "Ad Group 2",
17+
"id": 102
18+
},
19+
"metrics": {
20+
"clicks": 2300,
21+
"cost": 410.20
22+
}
23+
},
24+
{
25+
"resource": "Campaign C",
26+
"dimensions": {
27+
"name": "Ad Group 3",
28+
"id": 103
29+
},
30+
"metrics": {
31+
"clicks": 800,
32+
"cost": 120.50
33+
}
34+
},
35+
{
36+
"resource": "Campaign A",
37+
"dimensions": {
38+
"name": "Ad Group 4",
39+
"id": 104
40+
},
41+
"metrics": {
42+
"clicks": 3200,
43+
"cost": 600.00
44+
}
45+
}
46+
]
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# pylint: disable=C0330, g-bad-import-order, g-multiple-import, missing-class-docstring, missing-module-docstring, missing-function-docstring
16+
17+
import json
18+
import pathlib
19+
import subprocess
20+
21+
_SCRIPT_PATH = pathlib.Path(__file__).parent
22+
23+
24+
class TestApiQueryExecutor:
25+
def test_fake_source(self):
26+
fake_data = _SCRIPT_PATH / 'test.json'
27+
query = (
28+
'SELECT resource, dimensions.name AS name, metrics.clicks AS clicks '
29+
'FROM resource'
30+
)
31+
command = (
32+
f'garf "{query}" --input console --source fake '
33+
f'--source.data_location={fake_data} '
34+
'--output console --console.format=json '
35+
'--loglevel ERROR'
36+
)
37+
result = subprocess.run(
38+
command,
39+
shell=True,
40+
check=False,
41+
capture_output=True,
42+
text=True,
43+
)
44+
45+
expected_output = [
46+
{
47+
'resource': 'Campaign A',
48+
'name': 'Ad Group 1',
49+
'clicks': 1500,
50+
},
51+
{
52+
'resource': 'Campaign B',
53+
'name': 'Ad Group 2',
54+
'clicks': 2300,
55+
},
56+
{
57+
'resource': 'Campaign C',
58+
'name': 'Ad Group 3',
59+
'clicks': 800,
60+
},
61+
{
62+
'resource': 'Campaign A',
63+
'name': 'Ad Group 4',
64+
'clicks': 3200,
65+
},
66+
]
67+
68+
assert result.returncode == 0
69+
assert json.loads(result.stdout) == expected_output

0 commit comments

Comments
 (0)