#!/usr/bin/env python3
#
# In unit tests, calls to run 'kubectl' come here.
# A test case puts the Kubernetes responses it wants in a temporary folder, and this just prints them.

import os
from pathlib import Path
import re
import sys

args = " ".join(sys.argv[1:])
if m := re.match("get (pods|jobs|things) (-n default|--all-namespaces) -o json", args):
    kind = m.group(1)
elif re.match("get pods (-n default|--all-namespaces)", args):
    kind = "pod_statuses"
elif m := re.match("get (nodes|things) -o json", args):
    kind = m.group(1)
else:
    sys.exit(f"Unhandled command line: {args}")

mockdir = Path(os.environ["KUGL_MOCKDIR"])
content = mockdir.joinpath(kind).read_text()
print(content)