-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated image_hash test to test for copy changes
- Loading branch information
Julio Martinez
committed
Dec 20, 2024
1 parent
10a8d02
commit b17d99a
Showing
1 changed file
with
36 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,59 @@ | ||
import unittest | ||
import os | ||
import shutil | ||
|
||
from indexify.functions_sdk.image import BASE_IMAGE_NAME, Image | ||
|
||
KNOWN_GOOD_HASH = "229514da1c19e40fda77e8b4a4990f69ce1ec460f025f4e1367bb2219f6abea1" | ||
KNOWN_GOOD_HASH = "3f25487a14c4c0e8c9948545e85e17404717a3eebf33c91821b6d8d06cc6d704" | ||
|
||
|
||
class TestImage(unittest.TestCase): | ||
def setUp(self): | ||
os.mkdir("copy_test_dir") | ||
with open("copy_test_dir/test_file", "w") as fp: | ||
fp.write("Test data\n") | ||
|
||
def tearDown(self): | ||
shutil.rmtree("copy_test_dir") | ||
|
||
def test_copy_hash_update(self): | ||
i = self.newTestImage() | ||
|
||
prevHash = i.hash() | ||
|
||
with open("copy_test_dir/test_file", "w+") as fp: | ||
fp.write("Some more test data\n") | ||
|
||
self.assertNotEqual(i.hash(), prevHash) | ||
|
||
def test_image_hash(self): | ||
i = ( | ||
Image() | ||
.name("test") | ||
.base_image("static_base_image") | ||
.copy("copy_test_dir", "test_dir") | ||
.run("pip install all_the_things") | ||
.tag("test") | ||
) | ||
i._sdk_version = ( | ||
"1.2.3" # This needs to be statc for the hash to be predictable | ||
"1.2.3" # This needs to be static for the hash to be predictable | ||
) | ||
|
||
self.assertEqual(i.hash(), KNOWN_GOOD_HASH) | ||
|
||
def newTestImage(self): | ||
i = ( | ||
Image() | ||
.name("test") | ||
.base_image("static_base_image") | ||
.copy("copy_test_dir", "test_dir") | ||
.run("pip install all_the_things") | ||
.tag("test") | ||
) | ||
i._sdk_version = ( | ||
"1.2.3" # This needs to be static for the hash to be predictable | ||
) | ||
return i | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |