-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added check for node age and basic unit test for the same
- Loading branch information
1 parent
7232a99
commit 4c7963f
Showing
5 changed files
with
64 additions
and
13 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 +1,2 @@ | ||
venv | ||
__pycache__/ |
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import sys, os | ||
import unittest | ||
from datetime import datetime, timedelta, timezone | ||
from kubernetes.client import V1Node, V1ObjectMeta | ||
|
||
# Add src directory to the system path | ||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../src'))) | ||
|
||
from node_utils import is_node_older_than | ||
|
||
class TestNodeUtils(unittest.TestCase): | ||
|
||
def test_is_node_older_than_true(self): | ||
# Create a node with a creation timestamp older than 7 days | ||
creation_timestamp = datetime.now(timezone.utc) - timedelta(days=8) | ||
node = V1Node(metadata=V1ObjectMeta(creation_timestamp=creation_timestamp)) | ||
result = is_node_older_than(node, 7) | ||
self.assertTrue(result, "Node older than 7 days should return True") | ||
|
||
def test_is_node_older_than_false(self): | ||
# Create a node with a creation timestamp less than 7 days | ||
creation_timestamp = datetime.now(timezone.utc) - timedelta(days=6) | ||
node = V1Node(metadata=V1ObjectMeta(creation_timestamp=creation_timestamp)) | ||
result = is_node_older_than(node, 7) | ||
self.assertFalse(result, "Node younger than 7 days should return False") | ||
|
||
def test_is_node_older_than_exact(self): | ||
# Create a node with a creation timestamp exactly 7 days old | ||
creation_timestamp = datetime.now(timezone.utc) - timedelta(days=7) | ||
node = V1Node(metadata=V1ObjectMeta(creation_timestamp=creation_timestamp)) | ||
result = is_node_older_than(node, 7) | ||
self.assertFalse(result, "Node exactly 7 days old should return False") | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |