Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 295 monorepo directory structure design proposal #389

Merged
merged 137 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
01fea64
initial directory structure organization
hbraswelrh Nov 12, 2024
ec67718
feat: initial work on config and common options
gvauter Nov 13, 2024
a1984a5
chore: add openssf scorecard workflow (#359)
jpower432 Nov 14, 2024
cc569d5
build(deps): bump compliance-trestle from 3.4.0 to 3.5.0 (#380)
dependabot[bot] Nov 14, 2024
c5b9418
feat: adds logic to load yaml config into click context to set defaut…
gvauter Nov 15, 2024
c6a2569
feat: adds debug logging statements
gvauter Nov 15, 2024
78fd113
feat: add markdown directory creation and call to compliance trestle …
gvauter Nov 15, 2024
6be37e8
feat: simplify directory creation and better error handling for inval…
gvauter Nov 20, 2024
45fc4b8
feat: initial work on autosync
qduanmu Nov 20, 2024
a239482
Initial create command for click cli
hbraswelrh Nov 20, 2024
5931b5c
Initial create command for click cli
hbraswelrh Nov 20, 2024
1ba1010
adding unit test for config module
gvauter Nov 20, 2024
7645fbe
adding unit test for config module
gvauter Nov 20, 2024
268c558
Update autosync command
qduanmu Nov 21, 2024
823e5bc
Update autosync command
qduanmu Nov 21, 2024
000e26e
feat: add ssp index option
gvauter Nov 21, 2024
5aeb27d
feat: add ssp index option
gvauter Nov 21, 2024
362faf1
add unit tests for init command
gvauter Nov 21, 2024
75fd0c1
add unit tests for init command
gvauter Nov 21, 2024
59da2c8
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter Nov 21, 2024
7f266f0
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter Nov 21, 2024
1382cdc
feat: root call create and logging replacement
hbraswelrh Nov 21, 2024
3292aa5
feat: root call create and logging replacement
hbraswelrh Nov 21, 2024
0a12ef9
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 21, 2024
89de0ce
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 21, 2024
d41e017
feat: add upstream commands, fix common options decorators, expand co…
gvauter Nov 24, 2024
b172bcf
feat: add upstream commands, fix common options decorators, expand co…
gvauter Nov 24, 2024
0a1c0cd
Update autosync options and add tests
qduanmu Nov 25, 2024
c4a90a8
Update autosync options and add tests
qduanmu Nov 25, 2024
05cb60a
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 25, 2024
d3b7215
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 25, 2024
3725e7e
docs: adr-001 cli implementation (#347)
gvauter Nov 26, 2024
ed11e85
feat: add logic to make_config for nested upstream model and update r…
gvauter Nov 26, 2024
8f34874
feat: add logic to make_config for nested upstream model and update r…
gvauter Nov 26, 2024
2a3845d
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter Nov 26, 2024
f50c39d
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter Nov 26, 2024
b3ba8de
feat: create command logic for compdef and ssp
hbraswelrh Nov 26, 2024
ffae2e8
feat: create command logic for compdef and ssp
hbraswelrh Nov 26, 2024
3b63750
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 26, 2024
b97d7fa
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 26, 2024
9284ad8
feat: create command updates to prompts and logger messages
hbraswelrh Nov 26, 2024
92092a7
feat: create command updates to prompts and logger messages
hbraswelrh Nov 26, 2024
3c13ad6
feat: add default git info to init prompts and config
gvauter Nov 27, 2024
3a9a7c3
feat: add default git info to init prompts and config
gvauter Nov 27, 2024
a4dbaa6
fix hidden keep file creation
gvauter Nov 27, 2024
7d3b9e3
fix hidden keep file creation
gvauter Nov 27, 2024
1206a16
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter Nov 27, 2024
1b5566e
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter Nov 27, 2024
8fe0747
Add rule-transform command and unit test
qduanmu Nov 27, 2024
4484a56
Add rule-transform command and unit test
qduanmu Nov 27, 2024
74dd43d
feat: create command logic and adding unit tests
hbraswelrh Nov 27, 2024
17d524a
feat: create command logic and adding unit tests
hbraswelrh Nov 27, 2024
c628013
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 27, 2024
cf044da
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 27, 2024
d21f5f6
Fix AttributeError, some misc updates
qduanmu Nov 29, 2024
df0e5d2
Fix AttributeError, some misc updates
qduanmu Nov 29, 2024
aef085f
feat: unit tests added for create command
hbraswelrh Dec 2, 2024
dbf9fa2
feat: unit tests added for create command
hbraswelrh Dec 2, 2024
7bca6cd
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter Dec 3, 2024
40d6009
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter Dec 3, 2024
486ad1e
Fix AttributeError, some misc updates
qduanmu Nov 29, 2024
fb36a11
Fix AttributeError, some misc updates
qduanmu Nov 29, 2024
742cef9
feat: unit tests added for create command
hbraswelrh Dec 2, 2024
026657c
feat: unit tests added for create command
hbraswelrh Dec 2, 2024
f9a2bca
fix: docstrings added for create command unit tests
hbraswelrh Dec 3, 2024
ee0feec
fix: docstrings added for create command unit tests
hbraswelrh Dec 3, 2024
8f68749
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter Dec 3, 2024
39ebbab
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter Dec 3, 2024
ec2d3f6
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter Dec 3, 2024
f439a6e
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter Dec 3, 2024
9164f41
fix: docstrings added for create unit tests
hbraswelrh Dec 3, 2024
fc49a30
fix: docstrings added for create unit tests
hbraswelrh Dec 3, 2024
ef31702
add file pattern filter
gvauter Dec 3, 2024
39ded49
add file pattern filter
gvauter Dec 3, 2024
f352487
fix: updated headers with license and copyright
hbraswelrh Dec 3, 2024
3c094d2
fix: updated headers with license and copyright
hbraswelrh Dec 3, 2024
9fd8c3b
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Dec 3, 2024
d31e2c0
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Dec 3, 2024
170cfbc
fix: updated logger statements
hbraswelrh Dec 3, 2024
afa3f8e
fix: updated logger statements
hbraswelrh Dec 3, 2024
fa13754
fix: logger statements shortened
hbraswelrh Dec 3, 2024
a11615f
fix: logger statements shortened
hbraswelrh Dec 3, 2024
0ca9439
fix: yaml default deletion
hbraswelrh Dec 3, 2024
799b0ec
fix: yaml default deletion
hbraswelrh Dec 3, 2024
99915e4
docs: updates to reference the CLI commands in the README.md
hbraswelrh Dec 3, 2024
a44aa80
docs: updates to reference the CLI commands in the README.md
hbraswelrh Dec 3, 2024
f9feb88
feat: update for required ssp name
hbraswelrh Dec 3, 2024
8dbe4e3
feat: update for required ssp name
hbraswelrh Dec 3, 2024
91d115c
Update trestlebot/cli/commands/init.py
gvauter Dec 3, 2024
d6356c0
Update trestlebot/cli/commands/init.py
gvauter Dec 3, 2024
c6b5560
Update trestlebot/cli/commands/init.py
gvauter Dec 3, 2024
cba3776
Update trestlebot/cli/commands/init.py
gvauter Dec 3, 2024
5f456a8
fix typo in error msg
gvauter Dec 3, 2024
f72483d
fix typo in error msg
gvauter Dec 3, 2024
7bac602
fix help text for sync upstreams
gvauter Dec 3, 2024
f8c12b7
fix help text for sync upstreams
gvauter Dec 3, 2024
fa1466c
fix: update for help text and testing location errors
hbraswelrh Dec 3, 2024
8133f73
fix: update for help text and testing location errors
hbraswelrh Dec 3, 2024
d1cbc0b
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Dec 3, 2024
2df503b
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Dec 3, 2024
be89e66
fix: update for clarity on profile name for trestle workspace
hbraswelrh Dec 4, 2024
4c5a7e2
fix: update for clarity on profile name for trestle workspace
hbraswelrh Dec 4, 2024
f6fcf2d
Fix AssertionError, add missing register
qduanmu Dec 4, 2024
1669ea8
Fix AssertionError, add missing register
qduanmu Dec 4, 2024
e09b455
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Dec 4, 2024
562da56
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Dec 4, 2024
80cd9cc
fix: profile name prompting update
hbraswelrh Dec 4, 2024
4226a86
fix: profile name prompting update
hbraswelrh Dec 4, 2024
877ac9a
feat: updating compdef list to required
hbraswelrh Dec 4, 2024
66f55c7
feat: updating compdef list to required
hbraswelrh Dec 4, 2024
db34e53
docs: change of verbiage for readability
hbraswelrh Dec 4, 2024
dfc0aba
docs: change of verbiage for readability
hbraswelrh Dec 4, 2024
5c5a17a
docs: change to indicate trestle-bot as a cli tool
hbraswelrh Dec 4, 2024
230568d
docs: change to indicate trestle-bot as a cli tool
hbraswelrh Dec 4, 2024
0e31aa8
feat: change to help description of create command
hbraswelrh Dec 4, 2024
143b92a
feat: change to help description of create command
hbraswelrh Dec 4, 2024
88da512
docs: added high level folder structure for cli
hbraswelrh Dec 6, 2024
553ad1d
docs: added high level folder structure for cli
hbraswelrh Dec 6, 2024
7711aec
fix: default value returned if no key in dictionary
hbraswelrh Dec 11, 2024
b3b8ebd
fix: default value returned if no key in dictionary
hbraswelrh Dec 11, 2024
826a8f5
feat: align skip-item option to skip-items
qduanmu Dec 13, 2024
5144e10
feat: align skip-item option to skip-items
qduanmu Dec 13, 2024
84c38ba
fix: add missing git options in create command
qduanmu Dec 16, 2024
06e574b
fix: add missing git options in create command
qduanmu Dec 16, 2024
ddff735
fix: refactor testt and remove prompts
gvauter Dec 17, 2024
6e28c41
fix: refactor testt and remove prompts
gvauter Dec 17, 2024
e47dca5
fix: formatting issues and typos
gvauter Dec 17, 2024
f125d5f
fix: formatting issues and typos
gvauter Dec 17, 2024
fd2f738
chore: merge latest from main and fix conflicts
gvauter Dec 17, 2024
3b95d76
chore: merge latest from main and fix conflicts
gvauter Dec 17, 2024
954d38a
chore: update poetry lock with latest dependencies
gvauter Dec 17, 2024
586bfca
chore: update poetry lock with latest dependencies
gvauter Dec 17, 2024
1f6f6c6
fix: do not overwrite config path if set
gvauter Dec 17, 2024
ceb084c
fix: do not overwrite config path if set
gvauter Dec 17, 2024
769d0df
fix: do not overwrite config path if set
gvauter Dec 17, 2024
18eaf09
fix: do not overwrite config path if set
gvauter Dec 17, 2024
32a4132
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter Dec 18, 2024
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
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ The `autosync` command will sync trestle-generated Markdown files to OSCAL JSON

The `rules-transform` command can be used when managing [OSCAL Component Definitions](https://pages.nist.gov/OSCAL-Reference/models/v1.1.1/component-definition/json-outline/) in a trestle workspace. The action will transform rules defined in the rules YAML view to an OSCAL Component Definition JSON file.

The `create-cd` command can be used to create a new [OSCAL Component Definition](https://pages.nist.gov/OSCAL-Reference/models/v1.1.1/component-definition/json-outline/) in a trestle workspace. The action will create a new Component Definition JSON file and corresponding directories that contain rules YAML files and trestle-generated Markdown files. This action prepares the workspace for use with the `rules-transform` and `autosync` actions.
The `create compdef` command can be used to create a new [OSCAL Component Definition](https://pages.nist.gov/OSCAL-Reference/models/v1.1.1/component-definition/json-outline/) in a trestle workspace. The action will create a new Component Definition JSON file and corresponding directories that contain rules YAML files and trestle-generated Markdown files. This action prepares the workspace for use with the `rules-transform` and `autosync` actions.

The `sync-upstreams` command can be used to sync and validate upstream OSCAL content stored in a git repository to a local trestle workspace. Which content is synced is determined by the `include_model_names` and `exclude_model_names` inputs.
The `sync-upstreams` command can be used to sync and validate upstream OSCAL content stored in a git repository to a local trestle workspace. The inputs `include_models` and `exclude_models` determine which content is synced to the trestle workspace.

The `create-ssp` command can be used to create a new [OSCAL System Security Plans](https://pages.nist.gov/OSCAL-Reference/models/v1.1.1/system-security-plan/json-outline/) (SSP) in a trestle workspace. The action will create a new SSP JSON file and corresponding directories that contain trestle-generated Markdown files. This action prepares the workspace for use with the `autosync` action by creating or updating the `ssp-index.json` file. The `ssp-index.json` file is used to track the relationships between the SSP and the other OSCAL content in the workspace for the `autosync` action.
The `create ssp` command can be used to create a new [OSCAL System Security Plans](https://pages.nist.gov/OSCAL-Reference/models/v1.1.1/system-security-plan/json-outline/) (SSP) in a trestle workspace. The action will create a new SSP JSON file and corresponding directories that contain trestle-generated Markdown files. This action prepares the workspace for use with the `autosync` action by creating or updating the `ssp-index.json` file. The `ssp-index.json` file is used to track the relationships between the SSP and the other OSCAL content in the workspace for the `autosync` action.

Below is a table of the available commands and their current availability as a GitHub Action:

| Command | Available as a GitHub Action |
|--------------------|------------------------------|
| `autosync` | ✓ |
| `rules-transform` | ✓ |
| `create-cd` | ✓ |
| `sync-upstreams` | ✓ |
| `create-ssp` | |
| Command | Available as a GitHub Action |
|-------------------|------------------------------|
| `autosync` | ✓ |
| `rules-transform` | ✓ |
| `create compdef` | ✓ |
| `sync-upstreams` | ✓ |
| `create ssp` | |

For detailed documentation on how to use each action, see the README.md in each folder under [actions](./actions/).

Expand All @@ -47,7 +47,7 @@ provider information is supported for GitHub Actions (GitHub) and GitLab CI (Git

### Run as a Container

> Note: When running the commands in a container, all are prefixed with `trestlebot` (e.g. `trestlebot-autosync`). The default entrypoint for the container is the autosync command.
> Note: When running the commands in a container, all are prefixed with `trestlebot` (e.g. `trestlebot autosync`). The default entrypoint for the container is the autosync command.

Build and run the container locally:

Expand All @@ -72,4 +72,4 @@ This project is licensed under the Apache 2.0 License - see the [LICENSE.md](LIC

## Troubleshooting

See [TROUBLESHOOTING.md](./TROUBLESHOOTING.md) for troubleshooting tips.
See [TROUBLESHOOTING.md](./TROUBLESHOOTING.md) for troubleshooting tips.
15 changes: 13 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ flake8-print = "^5.0.0"
pre-commit = "^3.4.0"
mkdocs-material = "^9.5.43"
markdown-include = "^0.8.1"
types-pyyaml = "^6.0.12.20240917"

[tool.poetry.group.tests]
optional = true
Expand Down
90 changes: 90 additions & 0 deletions tests/trestlebot/cli/test_autosync_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Red Hat, Inc.


"""Testing module for trestlebot autosync command"""
import pathlib
from typing import Tuple

from click.testing import CliRunner
from git import Repo

from trestlebot.cli.commands.autosync import autosync_cmd
from trestlebot.cli.config import TrestleBotConfig, write_to_file


def test_invalid_oscal_model(tmp_repo: Tuple[str, Repo]) -> None:
"""Test invalid OSCAl model option."""

repo_path, _ = tmp_repo
runner = CliRunner()
result = runner.invoke(
autosync_cmd,
[
"--oscal-model",
"invalid",
"--repo-path",
repo_path,
"--markdown-dir",
"markdown",
"--branch",
"main",
"--committer-name",
"Test User",
"--committer-email",
"[email protected]",
],
)
assert "Invalid value for '--oscal-model'" in result.output
assert result.exit_code == 2


def test_missing_ssp_index_file_option(tmp_repo: Tuple[str, Repo]) -> None:
"""Test missing ssp_index_file option for autosync ssp."""
repo_path, _ = tmp_repo
runner = CliRunner()
cmd_options = [
"--oscal-model",
"ssp",
"--repo-path",
repo_path,
"--markdown-dir",
"markdown",
"--branch",
"main",
"--committer-name",
"Test User",
"--committer-email",
"[email protected]",
]
result = runner.invoke(autosync_cmd, cmd_options)
assert result.exit_code == 1
assert "Missing option '--ssp-index-file'" in result.output


def test_missing_markdown_dir_option(tmp_repo: Tuple[str, Repo]) -> None:
repo_path, _ = tmp_repo
runner = CliRunner()
cmd_options = [
"--oscal-model",
"compdef",
"--repo-path",
repo_path,
"--branch",
"main",
"--committer-name",
"Test User",
"--committer-email",
"[email protected]",
]
result = runner.invoke(autosync_cmd, cmd_options)
assert result.exit_code == 2
assert "Error: Missing option '--markdown-dir'" in result.output

# With 'markdown_dir' setting in config.yml
config_obj = TrestleBotConfig(markdown_dir="markdown")
filepath = pathlib.Path(repo_path).joinpath("config.yml")
write_to_file(config_obj, filepath)
cmd_options += ["--config", str(filepath)]
result = runner.invoke(autosync_cmd, cmd_options)
assert result.exit_code == 0
80 changes: 80 additions & 0 deletions tests/trestlebot/cli/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Red Hat, Inc.


"""Unit tests for CLI config module"""
import pathlib

import pytest
import yaml

from trestlebot.cli.config import (
TrestleBotConfig,
TrestleBotConfigError,
UpstreamsConfig,
load_from_file,
make_config,
write_to_file,
)


@pytest.fixture
def config_obj() -> TrestleBotConfig:
return TrestleBotConfig(
repo_path="/tmp",
markdown_dir="markdown",
upstreams=UpstreamsConfig(sources=["repo@main"]),
)


def test_invalid_config_raises_errors() -> None:
"""Test create config with invalid directory to raise error."""

with pytest.raises(TrestleBotConfigError) as ex:
_ = make_config(dict(repo_path="0"))

assert (
str(ex.value)
== "Invalid config value for repo_path. Path does not point to a directory."
)


def test_make_config_raises_no_errors(tmp_init_dir: str) -> None:
"""Test create a valid config object."""
values = {
"repo_path": tmp_init_dir,
"markdown_dir": "markdown",
"committer_name": "committer-name",
"committer_email": "committer-email",
"upstreams": {"sources": ["https://test@main"], "skip_validation": True},
}
config = make_config(values)
assert isinstance(config, TrestleBotConfig)
assert config.upstreams is not None
assert config.upstreams.sources == ["https://test@main"]
assert config.upstreams.skip_validation is True
assert config.repo_path == pathlib.Path(tmp_init_dir)
assert config.markdown_dir == values["markdown_dir"]
assert config.committer_name == values["committer_name"]
assert config.committer_email == values["committer_email"]


def test_config_write_to_file(config_obj: TrestleBotConfig, tmp_init_dir: str) -> None:
"""Test config is written to yaml file."""
filepath = pathlib.Path(tmp_init_dir).joinpath("config.yml")
write_to_file(config_obj, filepath)
with open(filepath, "r") as f:
yaml_data = yaml.safe_load(f)

assert yaml_data == config_obj.to_yaml_dict()


def test_config_load_from_file(config_obj: TrestleBotConfig, tmp_init_dir: str) -> None:
"""Test config is read from yaml file into config object."""
filepath = pathlib.Path(tmp_init_dir).joinpath("config.yml")
with filepath.open("w") as config_file:
yaml.dump(config_obj.to_yaml_dict(), config_file)

config = load_from_file(filepath)
assert isinstance(config, TrestleBotConfig)
assert config == config_obj
134 changes: 134 additions & 0 deletions tests/trestlebot/cli/test_create_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Red Hat, Inc.

""" Unit test for create commands ssp and cd"""

from click.testing import CliRunner

from trestlebot.cli.commands.create import create_cmd


def test_invalid_create_cmd() -> None:
"""Tests that create command fails if given invalid oscal model subcommand."""
runner = CliRunner()
result = runner.invoke(create_cmd, ["invalid"])

assert "Error: No such command 'invalid'" in result.output
assert result.exit_code == 2


def test_create_ssp_cmd(tmp_init_dir: str) -> None:
"""Tests successful create ssp command."""
SSP_INDEX_FILE = "tester-ssp-index.json"

runner = CliRunner()
result = runner.invoke(
create_cmd,
[
"ssp",
"--profile-name",
"oscal-profile-name",
"--markdown-dir",
"markdown",
"--ssp-name",
"test-name",
"--repo-path",
tmp_init_dir,
"--ssp-index-file",
SSP_INDEX_FILE,
],
)
assert result.exit_code == 0


def test_create_compdef_cmd(tmp_init_dir: str) -> None:
"""Tests successful create compdef command."""

runner = CliRunner()
result = runner.invoke(
create_cmd,
[
"compdef",
"--profile-name",
"oscal-profile-name",
"--compdef-name",
"test-name",
"--component-title",
"title-test",
"--component-description",
"description-test",
"--component-definition-type",
"type-test",
"repo-path",
tmp_init_dir,
],
)
assert result.exit_code == 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expected exit_code is 2? Is there any context I missed?

Copy link

@huiwangredhat huiwangredhat Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the arguments, '--committer-email', '--committer-name' and '--branch'could be added; repo-path could be updated to --repo-path; theassert result.exit_code == 2could beresult.exit_code == 0 `.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@huiwangredhat yes, you are correct, this should have a successful exit code since test expects it work correctly.



def test_default_ssp_index_file_cmd(tmp_init_dir: str) -> None:
"""Tests successful default ssp_index.json file creation."""

runner = CliRunner()
result = runner.invoke(
create_cmd,
[
"ssp",
"--profile-name",
"oscal-profile-name",
"--markdown-dir",
"markdown",
"--ssp-name",
"test-name",
"--repo-path",
tmp_init_dir,
],
)
assert result.exit_code == 0


def test_markdown_files_not_created(tmp_init_dir: str) -> None:
"""Tests failure of markdown file creation when not supplied with directory name."""
SSP_INDEX_TESTER = "ssp-tester.index.json"

runner = CliRunner()
result = runner.invoke(
create_cmd,
[
"ssp",
"--profile-name",
"oscal-profile-name",
"--ssp-name",
"test-name",
"repo-path",
tmp_init_dir,
"--ssp-index-file",
SSP_INDEX_TESTER,
],
)
assert result.exit_code == 2


def test_markdown_files_created(tmp_init_dir: str) -> None:
"""Tests successful creation of markdown files."""
SSP_INDEX_TESTER = "ssp-tester.index.json"
markdown_file_tester = "/markdown/system-security-plan.md"
hbraswelrh marked this conversation as resolved.
Show resolved Hide resolved

runner = CliRunner()
result = runner.invoke(
create_cmd,
[
"ssp",
"--profile-name",
"oscal-profile-name",
"--markdown-dir",
markdown_file_tester,
"--ssp-name",
"test-name",
"--repo-path",
tmp_init_dir,
"--ssp-index-file",
SSP_INDEX_TESTER,
],
)
assert result.exit_code == 0
Loading
Loading