-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,42 @@ | ||
import pytest | ||
import os | ||
import subprocess | ||
|
||
from snuba.migrations.autogeneration import generate | ||
|
||
|
||
def test_basic() -> None: | ||
old_storage, new_storage = generate( | ||
"snuba/datasets/configuration/events/storages/errors.yaml" | ||
) | ||
assert old_storage, new_storage | ||
dir = "/tmp/kylesfakerepo987636" | ||
fname = "fakestorage.yaml" | ||
|
||
# make a tmp dir with a git repo | ||
if os.path.exists(dir): | ||
subprocess.run(["rm", "-rf", dir], check=True) | ||
os.makedirs(dir) | ||
try: | ||
subprocess.run(["git", "init"], cwd=dir, check=True) | ||
# make a fake storage | ||
with open(os.path.join(dir, fname), "w") as f: | ||
f.write("hello world\n") | ||
subprocess.run( | ||
["git", "add", "."], | ||
cwd=dir, | ||
check=True, | ||
) | ||
subprocess.run( | ||
["git", "commit", "-m", '"blop"'], | ||
cwd=dir, | ||
check=True, | ||
) | ||
except subprocess.CalledProcessError as e: | ||
if not e.stderr: | ||
raise | ||
raise ValueError(e.stderr.decode("utf-8")) from e | ||
|
||
def test_error() -> None: | ||
with pytest.raises(ValueError): | ||
generate("~/hello.txt") | ||
# update the fake storage | ||
with open(os.path.join(dir, fname), "a") as f: | ||
f.write("goodbye world") | ||
|
||
# make sure HEAD and curr version looks right | ||
old_storage, new_storage = generate(os.path.join(dir, fname)) | ||
assert old_storage == "hello world\n" | ||
assert new_storage == "hello world\ngoodbye world" |