Skip to content

Commit

Permalink
Merge pull request #1785 from buildtesters/buildtest_buildspec_valida…
Browse files Browse the repository at this point in the history
…te_name

validate test by name via 'buildtest buildspec validate --name'
  • Loading branch information
shahzebsiddiqui authored Jun 12, 2024
2 parents 207d071 + 6961da2 commit 679f5af
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
5 changes: 4 additions & 1 deletion bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ _buildtest ()
esac
;;
validate|val)
local opts="--buildspec --exclude --executor --tag -b -e -t -x "
local opts="--buildspec --exclude --executor --name --tag -b -e -n -t -x "
COMPREPLY=( $( compgen -W "${opts}" -- "${cur}" ) )

case "${prev}" in
Expand All @@ -490,6 +490,9 @@ _buildtest ()
-e|--executor)
COMPREPLY=( $( compgen -W "$(_avail_executors)" -- "${cur}" ) )
;;
-n|--name)
COMPREPLY=( $( compgen -W "$(_buildspec_test_names)" -- "${cur}" ) )
;;
esac
;;
esac
Expand Down
8 changes: 8 additions & 0 deletions buildtest/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,14 @@ def buildspec_menu(self):
"help": "Specify buildspecs by tag name to validate",
},
),
(
["-n", "--name"],
{
"type": str,
"action": "append",
"help": "Specify buildspecs by name to validate",
},
),
],
},
]
Expand Down
9 changes: 8 additions & 1 deletion buildtest/cli/buildspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,12 @@ def handle_exception(buildspec, exception):


def buildspec_validate_command(
configuration, buildspecs=None, excluded_buildspecs=None, tags=None, executors=None
configuration,
buildspecs=None,
excluded_buildspecs=None,
tags=None,
executors=None,
name=None,
):
"""Entry point for ``buildtest buildspec validate``. This method is responsible for discovering buildspec
with same options used for building buildspecs that includes ``--buildspec``, ``--exclude``, ``--tag``, and
Expand All @@ -1223,13 +1228,15 @@ def buildspec_validate_command(
excluded_buildspecs (list, optional): List of excluded buildspecs which can be a file or directory. This option is specified via ``buildtest buildspec validate --exclude``
tags (list, optional): List of tag names to search for buildspec to validate. This option is specified via ``buildtest buildspec validate --tag``
executors (list, optional): List of executor names to search for buildspecs to validate. This option is specified via ``buildtest buildspec validate --executor``
name (str, optional): Name of test to validate. This option is specified via ``buildtest buildspec validate --name``
"""

buildspecs_dict = discover_buildspecs(
buildspecs=buildspecs,
exclude_buildspecs=excluded_buildspecs,
tags=tags,
executors=executors,
name=name,
)
detected_buildspecs = buildspecs_dict["detected"]

Expand Down
1 change: 1 addition & 0 deletions buildtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def handle_buildspec_command(args, configuration, report_file, buildtest_editor)
excluded_buildspecs=args.exclude,
tags=args.tag,
executors=args.executor,
name=args.name,
configuration=configuration,
)

Expand Down
11 changes: 9 additions & 2 deletions docs/gettingstarted/buildspecs_interface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ Validate Buildspecs - ``buildtest buildspec validate``
--------------------------------------------------------

buildtest can validate buildspecs through the ``buildtest buildspec validate`` command which provides
analogous options for ``buildtest build`` for selecting buildspecs such as ``-b``, ``-e``, ``-t`` and ``-e``.
analogous options for ``buildtest build`` for selecting buildspecs such as ``-b``, ``-e``, ``-n``, ``-t`` and ``-x``.
This command can be used to validate buildspecs with the JSON Schema which can be useful if you are writing a buildspec
and want to validate the buildspec without running the test.

Expand All @@ -339,7 +339,7 @@ Shown below are the available command options.

.. command-output:: buildtest buildspec validate --help

The `-b` option can be used to specify path to buildspec file or directory to validate buildspecs. If its a directory,
The **-b** option can be used to specify path to buildspec file or directory to validate buildspecs. If its a directory,
buildtest will traverse all directories recursively and find any **.yml** file extensions and attempt to validate each buildspec.
Shown below is an example output of what it may look like

Expand All @@ -363,6 +363,13 @@ will validate all buildspecs for **python** and **pass** tags.

.. command-output:: buildtest buildspec validate -t python -t pass

You can mix and match different options for searching buildspecs to validate. For example, we can
search by buildspec, tags, and name in the following example

.. dropdown:: ``buildtest buildspec validate -t python -n hello_world -b tutorials/vars.yml``

.. command-output:: buildtest buildspec validate -t python -n hello_world -b tutorials/vars.yml

Show buildspec ``buildtest buildspec show``
--------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions tests/cli/test_buildspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_buildspec_validate():
],
tags=["pass", "python"],
executors=["generic.local.sh"],
name=["hello_world"],
configuration=configuration,
)

Expand Down

0 comments on commit 679f5af

Please sign in to comment.