Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"project_name": "TODO",
"project_name": "replace-me",
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}",
"project_short_description": "TODO",
"project_short_description": "A brief description of the project",
"company_name": "Zenable Inc",
"company_domain": "zenable.io",
"github_org": "zenable-io",
Expand Down
23 changes: 17 additions & 6 deletions tests/test_cookiecutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
def get_config() -> dict:
"""Generate all the config keys"""
config_file = Path("./cookiecutter.json")
with open(config_file) as file_object:
config = json.load(file_object)
with config_file.open(encoding="utf-8") as f:
config = json.load(f)
return config


Expand Down Expand Up @@ -227,6 +227,19 @@ def test_default_project(cookies):
if repo.is_dirty(untracked_files=True):
pytest.fail("Something went wrong with the project's post-generation hook")

# Extract project_name and project_slug from cookiecutter.json
config_file = Path("./cookiecutter.json")
with config_file.open(encoding="utf-8") as f:
generated_config = json.load(f)
github_org = generated_config.get("github_org")
project_name = generated_config.get("project_name")
project_name_lower = project_name.lower()

# Keep this logic aligned with the template's README.md
# It's important that this has -s in the name to test the docker hub image name sanitization
default_image_name = f"{github_org}/{project_name_lower}"
default_image_name_and_tag = f"{default_image_name}:latest"

try:
env = os.environ.copy()
env.pop("VIRTUAL_ENV", None) # Clean VIRTUAL_ENV to avoid conflicts
Expand Down Expand Up @@ -273,11 +286,9 @@ def test_default_project(cookies):
env=env,
)

default_image = "zenable-io/todo:latest"

# Ensure that --help exits 0
subprocess.run(
["docker", "run", "--rm", default_image, "--help"],
["docker", "run", "--rm", default_image_name_and_tag, "--help"],
capture_output=True,
check=True,
cwd=project,
Expand All @@ -288,7 +299,7 @@ def test_default_project(cookies):
"docker",
"run",
"--rm",
default_image,
default_image_name_and_tag,
"--debug",
"--verbose",
]
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_name|replace(" ", "")}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ task init
task build

# Run the image
docker run {{ cookiecutter.github_org }}/{{ cookiecutter.project_slug }}:0.0.0 --help
docker run {{ cookiecutter.github_org }}/{{ cookiecutter.project_name | lower }}:0.0.0 --help
```

If you'd like to build all of the supported docker images, you can set the `PLATFORM` env var to `all` like this:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_docker_image():
Test that the Docker image builds and runs correctly.
"""
project_root = Path(__file__).parent.parent
image_name = "{{ cookiecutter.github_org }}/{{ cookiecutter.project_slug }}"
image_name = "{{ cookiecutter.github_org }}/{{ cookiecutter.project_name | lower }}"

pyproject_file = project_root / "pyproject.toml"

Expand Down
Loading