Skip to content

Commit

Permalink
Stage execute fix (#1525)
Browse files Browse the repository at this point in the history
Added more tests for stage execute
  • Loading branch information
sfc-gh-astus authored Sep 4, 2024
1 parent 89551de commit 0445f43
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 41 deletions.
98 changes: 95 additions & 3 deletions tests/git/__snapshots__/test_git_commands.ambr
Original file line number Diff line number Diff line change
@@ -1,13 +1,57 @@
# serializer version: 1
# name: test_execute[@DB.SCHEMA.REPO/branches/main/s1.sql-@DB.SCHEMA.REPO/branches/main/-expected_files4]
'''
SUCCESS - @DB.SCHEMA.REPO/branches/main/s1.sql
+--------------------------------------------------------+
| File | Status | Error |
|--------------------------------------+---------+-------|
| @DB.SCHEMA.REPO/branches/main/s1.sql | SUCCESS | None |
+--------------------------------------------------------+

'''
# ---
# name: test_execute[@DB.SCHEMA.REPO/branches/main/s1.sql-@db.schema.repo/branches/main/-expected_files0]
'''
SUCCESS - @db.schema.repo/branches/main/s1.sql
+--------------------------------------------------------+
| File | Status | Error |
|--------------------------------------+---------+-------|
| @db.schema.repo/branches/main/s1.sql | SUCCESS | None |
+--------------------------------------------------------+

'''
# ---
# name: test_execute[@DB.schema.REPO/branches/main/a/S3.sql-@DB.schema.REPO/branches/main/-expected_files5]
'''
SUCCESS - @DB.schema.REPO/branches/main/a/S3.sql
+----------------------------------------------------------+
| File | Status | Error |
|----------------------------------------+---------+-------|
| @DB.schema.REPO/branches/main/a/S3.sql | SUCCESS | None |
+----------------------------------------------------------+

'''
# ---
# name: test_execute[@DB.schema.REPO/branches/main/a/S3.sql-@db.schema.repo/branches/main/-expected_files1]
'''
SUCCESS - @db.schema.repo/branches/main/a/S3.sql
+----------------------------------------------------------+
| File | Status | Error |
|----------------------------------------+---------+-------|
| @db.schema.repo/branches/main/a/S3.sql | SUCCESS | None |
+----------------------------------------------------------+

'''
# ---
# name: test_execute[@db.schema.repo/branches/main/-@db.schema.repo/branches/main/-expected_files2]
'''
SUCCESS - @db.schema.repo/branches/main/s1.sql
SUCCESS - @db.schema.repo/branches/main/a/s3.sql
SUCCESS - @db.schema.repo/branches/main/a/S3.sql
+----------------------------------------------------------+
| File | Status | Error |
|----------------------------------------+---------+-------|
| @db.schema.repo/branches/main/s1.sql | SUCCESS | None |
| @db.schema.repo/branches/main/a/s3.sql | SUCCESS | None |
| @db.schema.repo/branches/main/a/S3.sql | SUCCESS | None |
+----------------------------------------------------------+

'''
Expand All @@ -26,17 +70,54 @@
# name: test_execute[@repo/branches/main/-@repo/branches/main/-expected_files0]
'''
SUCCESS - @repo/branches/main/s1.sql
SUCCESS - @repo/branches/main/a/S3.sql
+------------------------------------------------+
| File | Status | Error |
|------------------------------+---------+-------|
| @repo/branches/main/s1.sql | SUCCESS | None |
| @repo/branches/main/a/S3.sql | SUCCESS | None |
+------------------------------------------------+

'''
# ---
# name: test_execute[@repo/branches/main/a-@repo/branches/main/-expected_files1]
'''
SUCCESS - @repo/branches/main/a/S3.sql
+------------------------------------------------+
| File | Status | Error |
|------------------------------+---------+-------|
| @repo/branches/main/a/S3.sql | SUCCESS | None |
+------------------------------------------------+

'''
# ---
# name: test_execute_new_git_repository_list_files[@repo/branches/main/-@repo/branches/main/-expected_files0]
'''
SUCCESS - @repo/branches/main/S2.sql
SUCCESS - @repo/branches/main/s1.sql
SUCCESS - @repo/branches/main/a/s3.sql
+------------------------------------------------+
| File | Status | Error |
|------------------------------+---------+-------|
| @repo/branches/main/S2.sql | SUCCESS | None |
| @repo/branches/main/s1.sql | SUCCESS | None |
| @repo/branches/main/a/s3.sql | SUCCESS | None |
+------------------------------------------------+

'''
# ---
# name: test_execute[@repo/branches/main/a-@repo/branches/main/-expected_files1]
# name: test_execute_new_git_repository_list_files[@repo/branches/main/S2.sql-@repo/branches/main/-expected_files2]
'''
SUCCESS - @repo/branches/main/S2.sql
+----------------------------------------------+
| File | Status | Error |
|----------------------------+---------+-------|
| @repo/branches/main/S2.sql | SUCCESS | None |
+----------------------------------------------+

'''
# ---
# name: test_execute_new_git_repository_list_files[@repo/branches/main/a/s3.sql-@repo/branches/main/-expected_files3]
'''
SUCCESS - @repo/branches/main/a/s3.sql
+------------------------------------------------+
Expand All @@ -47,3 +128,14 @@

'''
# ---
# name: test_execute_new_git_repository_list_files[@repo/branches/main/s1.sql-@repo/branches/main/-expected_files1]
'''
SUCCESS - @repo/branches/main/s1.sql
+----------------------------------------------+
| File | Status | Error |
|----------------------------+---------+-------|
| @repo/branches/main/s1.sql | SUCCESS | None |
+----------------------------------------------+

'''
# ---
77 changes: 73 additions & 4 deletions tests/git/test_git_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,26 +435,36 @@ def test_setup_create_secret_create_api(
(
"@repo/branches/main/",
"@repo/branches/main/",
["@repo/branches/main/s1.sql", "@repo/branches/main/a/s3.sql"],
["@repo/branches/main/s1.sql", "@repo/branches/main/a/S3.sql"],
),
(
"@repo/branches/main/a",
"@repo/branches/main/",
["@repo/branches/main/a/s3.sql"],
["@repo/branches/main/a/S3.sql"],
),
(
"@db.schema.repo/branches/main/",
"@db.schema.repo/branches/main/",
[
"@db.schema.repo/branches/main/s1.sql",
"@db.schema.repo/branches/main/a/s3.sql",
"@db.schema.repo/branches/main/a/S3.sql",
],
),
(
"@db.schema.repo/branches/main/s1.sql",
"@db.schema.repo/branches/main/",
["@db.schema.repo/branches/main/s1.sql"],
),
(
"@DB.SCHEMA.REPO/branches/main/s1.sql",
"@DB.SCHEMA.REPO/branches/main/",
["@DB.SCHEMA.REPO/branches/main/s1.sql"],
),
(
"@DB.schema.REPO/branches/main/a/S3.sql",
"@DB.schema.REPO/branches/main/",
["@DB.schema.REPO/branches/main/a/S3.sql"],
),
],
)
@mock.patch(f"{STAGE_MANAGER}._execute_query")
Expand All @@ -469,7 +479,7 @@ def test_execute(
):
mock_execute.return_value = mock_cursor(
[
{"name": "repo/branches/main/a/s3.sql"},
{"name": "repo/branches/main/a/S3.sql"},
{"name": "repo/branches/main/s1.sql"},
{"name": "repo/branches/main/s2"},
],
Expand All @@ -487,6 +497,65 @@ def test_execute(
assert result.output == os_agnostic_snapshot


@pytest.mark.parametrize(
"repository_path, expected_stage, expected_files",
[
(
"@repo/branches/main/",
"@repo/branches/main/",
[
"@repo/branches/main/S2.sql",
"@repo/branches/main/s1.sql",
"@repo/branches/main/a/s3.sql",
],
),
(
"@repo/branches/main/s1.sql",
"@repo/branches/main/",
["@repo/branches/main/s1.sql"],
),
(
"@repo/branches/main/S2.sql",
"@repo/branches/main/",
["@repo/branches/main/S2.sql"],
),
(
"@repo/branches/main/a/s3.sql",
"@repo/branches/main/",
["@repo/branches/main/a/s3.sql"],
),
],
)
@mock.patch(f"{STAGE_MANAGER}._execute_query")
def test_execute_new_git_repository_list_files(
mock_execute,
mock_cursor,
runner,
repository_path,
expected_stage,
expected_files,
os_agnostic_snapshot,
):
mock_execute.return_value = mock_cursor(
[
{"name": "/branches/main/s1.sql"},
{"name": "/branches/main/S2.sql"},
{"name": "/branches/main/a/s3.sql"},
],
[],
)

result = runner.invoke(["git", "execute", repository_path])

assert result.exit_code == 0, result.output
ls_call, *execute_calls = mock_execute.mock_calls
assert ls_call == mock.call(f"ls {expected_stage}", cursor_class=DictCursor)
assert execute_calls == [
mock.call(f"execute immediate from {p}") for p in expected_files
]
assert result.output == os_agnostic_snapshot


@mock.patch(f"{STAGE_MANAGER}._execute_query")
def test_execute_with_variables(mock_execute, mock_cursor, runner):
mock_execute.return_value = mock_cursor([{"name": "repo/branches/main/s1.sql"}], [])
Expand Down
Loading

0 comments on commit 0445f43

Please sign in to comment.