From 2c71e1a81eb7668bf45fe2dfaf7dd41efa9e10e1 Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Mon, 13 Apr 2026 11:08:38 -0500 Subject: [PATCH] improve spec tests, parameterization, missing tests, more coverage Signed-off-by: Jacob Salmela --- Makefile | 2 +- spec/functional/add_cable_spec.sh | 47 ++++ spec/functional/add_device_spec.sh | 47 ++++ spec/functional/add_module_spec.sh | 47 ++++ spec/functional/add_rack_spec.sh | 47 ++++ spec/functional/add_spec.sh | 180 +++++++------- spec/functional/alpha_spec.sh | 41 +--- spec/functional/cani_spec.sh | 50 ++-- spec/functional/classify_spec.sh | 48 ++++ spec/functional/export_spec.sh | 2 +- spec/functional/import_spec.sh | 21 +- spec/functional/remove_cable_spec.sh | 47 ++++ spec/functional/remove_device_spec.sh | 47 ++++ spec/functional/remove_location_spec.sh | 47 ++++ spec/functional/remove_module_spec.sh | 47 ++++ spec/functional/remove_rack_spec.sh | 47 ++++ spec/functional/remove_spec.sh | 61 +---- spec/functional/show_spec.sh | 156 +++---------- spec/functional/update_cable_spec.sh | 47 ++++ spec/functional/update_device_spec.sh | 47 ++++ spec/functional/update_location_spec.sh | 47 ++++ spec/functional/update_module_spec.sh | 47 ++++ spec/functional/update_rack_spec.sh | 47 ++++ spec/functional/update_spec.sh | 219 +++++------------- spec/spec_helper.sh | 11 + .../fixtures/cani/configs/test_config.yml | 63 +++++ testdata/fixtures/cani/crud_inventory.json | 183 +++++++++++++++ 27 files changed, 1181 insertions(+), 514 deletions(-) create mode 100644 spec/functional/add_cable_spec.sh create mode 100644 spec/functional/add_device_spec.sh create mode 100644 spec/functional/add_module_spec.sh create mode 100644 spec/functional/add_rack_spec.sh create mode 100644 spec/functional/classify_spec.sh create mode 100644 spec/functional/remove_cable_spec.sh create mode 100644 spec/functional/remove_device_spec.sh create mode 100644 spec/functional/remove_location_spec.sh create mode 100644 spec/functional/remove_module_spec.sh create mode 100644 spec/functional/remove_rack_spec.sh create mode 100644 spec/functional/update_cable_spec.sh create mode 100644 spec/functional/update_device_spec.sh create mode 100644 spec/functional/update_location_spec.sh create mode 100644 spec/functional/update_module_spec.sh create mode 100644 spec/functional/update_rack_spec.sh create mode 100644 testdata/fixtures/cani/configs/test_config.yml create mode 100644 testdata/fixtures/cani/crud_inventory.json diff --git a/Makefile b/Makefile index cbf6406b..992c70e5 100644 --- a/Makefile +++ b/Makefile @@ -200,7 +200,7 @@ utest: bin ## Run unit tests .PHONY: ftest ftest: bin ## Run functional tests $(INFO) "running functional tests" - ./spec/support/bin/cani_integrate.sh functional + shellspec ./spec/functional -f tap $(OK) "functional tests passed" .PHONY: itest diff --git a/spec/functional/add_cable_spec.sh b/spec/functional/add_cable_spec.sh new file mode 100644 index 00000000..f2964702 --- /dev/null +++ b/spec/functional/add_cable_spec.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +# +# MIT License +# +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# ── add cable ─────────────────────────────────────────────────────── + +Describe 'cani alpha add cable' + + Describe 'valid slug' + It 'adds a cable with a known slug' + When call bin/cani alpha add cable hpe-cat5-rj45-4-3m-cable --config "$CANI_CONF" + The status should equal 0 + The stderr should include 'Added cable' + The stderr should include '1 cable(s) added' + End + End + + Describe 'invalid slug' + It 'rejects an unknown slug' + When call bin/cani alpha add cable nonexistent-slug + The status should equal 1 + The stderr should include 'unknown cable slug or part number' + End + End + +End diff --git a/spec/functional/add_device_spec.sh b/spec/functional/add_device_spec.sh new file mode 100644 index 00000000..066f5967 --- /dev/null +++ b/spec/functional/add_device_spec.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +# +# MIT License +# +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# ── add device ────────────────────────────────────────────────────── + +Describe 'cani alpha add device' + + Describe 'valid slug' + It 'adds a device with a known slug' + When call bin/cani alpha add device cray-xd225v --config "$CANI_CONF" + The status should equal 0 + The stderr should include 'Added device' + The stderr should include 'device(s) added' + End + End + + Describe 'invalid slug' + It 'rejects an unknown slug' + When call bin/cani alpha add device nonexistent-slug + The status should equal 1 + The stderr should include 'unknown device slug or part number: nonexistent-slug' + End + End + +End diff --git a/spec/functional/add_module_spec.sh b/spec/functional/add_module_spec.sh new file mode 100644 index 00000000..e43457d5 --- /dev/null +++ b/spec/functional/add_module_spec.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +# +# MIT License +# +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# ── add module ────────────────────────────────────────────────────── + +Describe 'cani alpha add module' + + Describe 'valid slug' + It 'adds a module with a known slug' + When call bin/cani alpha add module hpe-1600w-flex-slot-platinum-hot-plug-psu --config "$CANI_CONF" + The status should equal 0 + The stderr should include 'Added module' + The stderr should include '1 module(s) added' + End + End + + Describe 'invalid slug' + It 'rejects an unknown slug' + When call bin/cani alpha add module nonexistent-slug + The status should equal 1 + The stderr should include 'unknown module slug or part number' + End + End + +End diff --git a/spec/functional/add_rack_spec.sh b/spec/functional/add_rack_spec.sh new file mode 100644 index 00000000..3e14a8e3 --- /dev/null +++ b/spec/functional/add_rack_spec.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +# +# MIT License +# +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# ── add rack ──────────────────────────────────────────────────────── + +Describe 'cani alpha add rack' + + Describe 'valid slug' + It 'adds a rack with a known slug' + When call bin/cani alpha add rack hpe-48u-800mmx1200mm-g2-enterprise-shock-rack --config "$CANI_CONF" + The status should equal 0 + The stderr should include 'Added rack' + The stderr should include '1 rack(s) added' + End + End + + Describe 'invalid slug' + It 'rejects an unknown slug' + When call bin/cani alpha add rack nonexistent-slug + The status should equal 1 + The stderr should include 'unknown rack slug or part number' + End + End + +End diff --git a/spec/functional/add_spec.sh b/spec/functional/add_spec.sh index 4810645c..83c94dcc 100644 --- a/spec/functional/add_spec.sh +++ b/spec/functional/add_spec.sh @@ -2,7 +2,7 @@ # # MIT License # -# (C) Copyright 2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2023, 2026 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -36,56 +36,20 @@ Describe 'cani alpha add' The stdout should include 'Add items to the inventory' End - # subcommands - It 'lists the location subcommand' - When call bin/cani alpha add --help - The stdout should include 'location' + Describe 'subcommands' + Parameters:value location rack device module cable metadata + It "lists the $1 subcommand" + When call bin/cani alpha add --help + The stdout should include "$1" + End End - It 'lists the rack subcommand' - When call bin/cani alpha add --help - The stdout should include 'rack' - End - - It 'lists the device subcommand' - When call bin/cani alpha add --help - The stdout should include 'device' - End - - It 'lists the module subcommand' - When call bin/cani alpha add --help - The stdout should include 'module' - End - - It 'lists the cable subcommand' - When call bin/cani alpha add --help - The stdout should include 'cable' - End - - # persistent flags - It 'has --auto / -a flag' - When call bin/cani alpha add --help - The stdout should include '--auto' - End - - It 'has --accept / -y flag' - When call bin/cani alpha add --help - The stdout should include '--accept' - End - - It 'has --list-supported-types / -L flag' - When call bin/cani alpha add --help - The stdout should include '--list-supported-types' - End - - It 'has --qty / -q flag' - When call bin/cani alpha add --help - The stdout should include '--qty' - End - - It 'has --parent / -p flag' - When call bin/cani alpha add --help - The stdout should include '--parent' + Describe 'persistent flags' + Parameters:value --auto --accept --list-supported-types --qty --parent --prefix --start --pad-width --tag --metadata --status --serial + It "has $1 flag" + When call bin/cani alpha add --help + The stdout should include "$1" + End End End @@ -98,14 +62,12 @@ Describe 'cani alpha add' The stdout should include 'Add a location' End - It 'has --type flag' - When call bin/cani alpha add location --help - The stdout should include '--type' - End - - It 'has --parent flag' - When call bin/cani alpha add location --help - The stdout should include '--parent' + Describe 'flags' + Parameters:value --type --parent --description --content-types + It "has $1 flag" + When call bin/cani alpha add location --help + The stdout should include "$1" + End End End @@ -133,19 +95,12 @@ Describe 'cani alpha add' The stdout should include 'Add one or more devices' End - It 'has --rack flag' - When call bin/cani alpha add device --help - The stdout should include '--rack' - End - - It 'has --position flag' - When call bin/cani alpha add device --help - The stdout should include '--position' - End - - It 'has --face flag' - When call bin/cani alpha add device --help - The stdout should include '--face' + Describe 'flags' + Parameters:value --rack --position --face --zone --dry-run --location + It "has $1 flag" + When call bin/cani alpha add device --help + The stdout should include "$1" + End End End @@ -158,14 +113,12 @@ Describe 'cani alpha add' The stdout should include 'Add one or more modules' End - It 'has --device flag' - When call bin/cani alpha add module --help - The stdout should include '--device' - End - - It 'has --bay flag' - When call bin/cani alpha add module --help - The stdout should include '--bay' + Describe 'flags' + Parameters:value --device --bay --bay-filter --dry-run --location + It "has $1 flag" + When call bin/cani alpha add module --help + The stdout should include "$1" + End End End @@ -178,34 +131,49 @@ Describe 'cani alpha add' The stdout should include 'Add one or more cables' End - It 'has --a-device flag' - When call bin/cani alpha add cable --help - The stdout should include '--a-device' + Describe 'flags' + Parameters:value --a-device --a-port --b-device --b-port --label --color + It "has $1 flag" + When call bin/cani alpha add cable --help + The stdout should include "$1" + End End + End - It 'has --a-port flag' - When call bin/cani alpha add cable --help - The stdout should include '--a-port' - End + # ── add metadata help & flags ──────────────────────────────────── - It 'has --b-device flag' - When call bin/cani alpha add cable --help - The stdout should include '--b-device' + Describe 'metadata --help' + It 'exits 0 and describes creating metadata definitions' + When call bin/cani alpha add metadata --help + The status should equal 0 + The stdout should include 'metadata definitions' End - It 'has --b-port flag' - When call bin/cani alpha add cable --help - The stdout should include '--b-port' + Describe 'subcommands' + Parameters:value role status tag + It "lists the $1 subcommand" + When call bin/cani alpha add metadata --help + The stdout should include "$1" + End End - It 'has --label flag' - When call bin/cani alpha add cable --help - The stdout should include '--label' + Describe 'flags' + Parameters:value --content-types --color --description + It "has $1 flag" + When call bin/cani alpha add metadata --help + The stdout should include "$1" + End End + End - It 'has --color flag' - When call bin/cani alpha add cable --help - The stdout should include '--color' + # ── add metadata noun help ────────────────────────────────────── + + Describe 'metadata noun help' + Parameters:value role status tag + It "metadata $1 --help exits 0" + When call bin/cani alpha add metadata "$1" --help + The status should equal 0 + The stdout should include "$1" End End @@ -254,6 +222,24 @@ Describe 'cani alpha add' The status should equal 1 The stderr should include 'unknown location type slug' End + + It 'add metadata role with no arg fails' + When call bin/cani alpha add metadata role + The status should equal 1 + The stderr should include 'accepts 1 arg(s), received 0' + End + + It 'add metadata status with no arg fails' + When call bin/cani alpha add metadata status + The status should equal 1 + The stderr should include 'accepts 1 arg(s), received 0' + End + + It 'add metadata tag with no arg fails' + When call bin/cani alpha add metadata tag + The status should equal 1 + The stderr should include 'accepts 1 arg(s), received 0' + End End # ── CRUD: add location ────────────────────────────────────────── diff --git a/spec/functional/alpha_spec.sh b/spec/functional/alpha_spec.sh index 8bd2c861..c8eb5d05 100644 --- a/spec/functional/alpha_spec.sh +++ b/spec/functional/alpha_spec.sh @@ -2,7 +2,7 @@ # # MIT License # -# (C) Copyright 2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2023, 2026 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -34,39 +34,12 @@ Describe 'cani alpha' The stdout should include 'unstable' End - It 'lists the add subcommand' - When call bin/cani alpha --help - The stdout should include 'add' - End - - It 'lists the remove subcommand' - When call bin/cani alpha --help - The stdout should include 'remove' - End - - It 'lists the update subcommand' - When call bin/cani alpha --help - The stdout should include 'update' - End - - It 'lists the show subcommand' - When call bin/cani alpha --help - The stdout should include 'show' - End - - It 'lists the import subcommand' - When call bin/cani alpha --help - The stdout should include 'import' - End - - It 'lists the export subcommand' - When call bin/cani alpha --help - The stdout should include 'export' - End - - It 'lists the serve subcommand' - When call bin/cani alpha --help - The stdout should include 'serve' + Describe 'subcommands' + Parameters:value add remove update show import export serve classify + It "lists the $1 subcommand" + When call bin/cani alpha --help + The stdout should include "$1" + End End End diff --git a/spec/functional/cani_spec.sh b/spec/functional/cani_spec.sh index 19841025..06e66ac4 100755 --- a/spec/functional/cani_spec.sh +++ b/spec/functional/cani_spec.sh @@ -2,7 +2,7 @@ # # MIT License # -# (C) Copyright 2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2023, 2026 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -34,44 +34,20 @@ Describe 'cani' The stdout should include 'Continious And Never-ending Inventory' End - It 'lists the alpha subcommand' - When call bin/cani --help - The stdout should include 'alpha' - End - - It 'lists the init subcommand' - When call bin/cani --help - The stdout should include 'init' - End - - It 'lists the --config flag' - When call bin/cani --help - The stdout should include '--config' - End - - It 'lists the --debug flag' - When call bin/cani --help - The stdout should include '--debug' + Describe 'subcommands' + Parameters:value alpha init + It "lists the $1 subcommand" + When call bin/cani --help + The stdout should include "$1" + End End - It 'lists the --datastore flag' - When call bin/cani --help - The stdout should include '--datastore' - End - - It 'lists the --types-dirs flag' - When call bin/cani --help - The stdout should include '--types-dirs' - End - - It 'lists the --types-repos flag' - When call bin/cani --help - The stdout should include '--types-repos' - End - - It 'lists the --version / -v flag' - When call bin/cani --help - The stdout should include '--version' + Describe 'flags' + Parameters:value --config --debug --datastore --types-dirs --types-repos --types-repo-clone --types-repo-pull --strict --version + It "has $1 flag" + When call bin/cani --help + The stdout should include "$1" + End End End diff --git a/spec/functional/classify_spec.sh b/spec/functional/classify_spec.sh new file mode 100644 index 00000000..5f4978af --- /dev/null +++ b/spec/functional/classify_spec.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env sh +# +# MIT License +# +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# ── classify command ──────────────────────────────────────────────── + +Describe 'cani alpha classify' + + # ── help & flags ──────────────────────────────────────────────── + + Describe '--help' + It 'exits 0 and shows the description' + When call bin/cani alpha classify --help + The status should equal 0 + The stdout should include 'classify' + End + + Describe 'flags' + Parameters:value --auto --auto-score --filter + It "has $1 flag" + When call bin/cani alpha classify --help + The stdout should include "$1" + End + End + End + +End diff --git a/spec/functional/export_spec.sh b/spec/functional/export_spec.sh index b60d2fe9..82765966 100644 --- a/spec/functional/export_spec.sh +++ b/spec/functional/export_spec.sh @@ -2,7 +2,7 @@ # # MIT License # -# (C) Copyright 2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), diff --git a/spec/functional/import_spec.sh b/spec/functional/import_spec.sh index d6fc7d95..53f9c5b1 100644 --- a/spec/functional/import_spec.sh +++ b/spec/functional/import_spec.sh @@ -2,7 +2,7 @@ # # MIT License # -# (C) Copyright 2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -34,19 +34,12 @@ Describe 'cani alpha import' The stdout should include 'Import assets into the inventory' End - It 'has --phase flag' - When call bin/cani alpha import --help - The stdout should include '--phase' - End - - It 'has --no-color flag' - When call bin/cani alpha import --help - The stdout should include '--no-color' - End - - It 'has --step flag' - When call bin/cani alpha import --help - The stdout should include '--step' + Describe 'flags' + Parameters:value --phase --no-color --step + It "has $1 flag" + When call bin/cani alpha import --help + The stdout should include "$1" + End End It 'lists provider subcommands' diff --git a/spec/functional/remove_cable_spec.sh b/spec/functional/remove_cable_spec.sh new file mode 100644 index 00000000..51a62a27 --- /dev/null +++ b/spec/functional/remove_cable_spec.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +# +# MIT License +# +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# ── remove cable ──────────────────────────────────────────────────── + +Describe 'cani alpha remove cable' + Before 'setup_crud_env' + + Describe 'valid label' + It 'removes a cable by label' + When call bin/cani alpha remove cable test-cable --force --config "$CANI_CONF" + The status should equal 0 + The stderr should include 'Removed cable' + End + End + + Describe 'invalid name' + It 'rejects an unknown name' + When call bin/cani alpha remove cable nonexistent-name --force --config "$CANI_CONF" + The status should equal 1 + The stderr should include 'no item found matching' + End + End + +End diff --git a/spec/functional/remove_device_spec.sh b/spec/functional/remove_device_spec.sh new file mode 100644 index 00000000..3f7f684c --- /dev/null +++ b/spec/functional/remove_device_spec.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +# +# MIT License +# +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# ── remove device ─────────────────────────────────────────────────── + +Describe 'cani alpha remove device' + Before 'setup_crud_env' + + Describe 'valid name' + It 'removes a device by name' + When call bin/cani alpha remove device test-device --force --config "$CANI_CONF" + The status should equal 0 + The stderr should include 'Removed device' + End + End + + Describe 'invalid name' + It 'rejects an unknown name' + When call bin/cani alpha remove device nonexistent-name --force --config "$CANI_CONF" + The status should equal 1 + The stderr should include 'no item found matching' + End + End + +End diff --git a/spec/functional/remove_location_spec.sh b/spec/functional/remove_location_spec.sh new file mode 100644 index 00000000..62b00e93 --- /dev/null +++ b/spec/functional/remove_location_spec.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +# +# MIT License +# +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# ── remove location ──────────────────────────────────────────────── + +Describe 'cani alpha remove location' + Before 'setup_crud_env' + + Describe 'valid name' + It 'removes a location by name' + When call bin/cani alpha remove location removable-location --force --config "$CANI_CONF" + The status should equal 0 + The stderr should include 'Removed location' + End + End + + Describe 'invalid name' + It 'rejects an unknown name' + When call bin/cani alpha remove location nonexistent-name --force --config "$CANI_CONF" + The status should equal 1 + The stderr should include 'no item found matching' + End + End + +End diff --git a/spec/functional/remove_module_spec.sh b/spec/functional/remove_module_spec.sh new file mode 100644 index 00000000..b2a90a61 --- /dev/null +++ b/spec/functional/remove_module_spec.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +# +# MIT License +# +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# ── remove module ─────────────────────────────────────────────────── + +Describe 'cani alpha remove module' + Before 'setup_crud_env' + + Describe 'valid name' + It 'removes a module by name' + When call bin/cani alpha remove module test-module --force --config "$CANI_CONF" + The status should equal 0 + The stderr should include 'Removed module' + End + End + + Describe 'invalid name' + It 'rejects an unknown name' + When call bin/cani alpha remove module nonexistent-name --force --config "$CANI_CONF" + The status should equal 1 + The stderr should include 'no item found matching' + End + End + +End diff --git a/spec/functional/remove_rack_spec.sh b/spec/functional/remove_rack_spec.sh new file mode 100644 index 00000000..feb6547a --- /dev/null +++ b/spec/functional/remove_rack_spec.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +# +# MIT License +# +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# ── remove rack ───────────────────────────────────────────────────── + +Describe 'cani alpha remove rack' + Before 'setup_crud_env' + + Describe 'valid name' + It 'removes a rack by name' + When call bin/cani alpha remove rack test-rack --force --config "$CANI_CONF" + The status should equal 0 + The stderr should include 'Removed rack' + End + End + + Describe 'invalid name' + It 'rejects an unknown name' + When call bin/cani alpha remove rack nonexistent-name --force --config "$CANI_CONF" + The status should equal 1 + The stderr should include 'no item found matching' + End + End + +End diff --git a/spec/functional/remove_spec.sh b/spec/functional/remove_spec.sh index 4c02bb30..52fa6e58 100644 --- a/spec/functional/remove_spec.sh +++ b/spec/functional/remove_spec.sh @@ -2,7 +2,7 @@ # # MIT License # -# (C) Copyright 2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2023, 2026 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -36,30 +36,12 @@ Describe 'cani alpha remove' The stdout should include 'Remove items from the inventory' End - # subcommands - It 'lists the location subcommand' - When call bin/cani alpha remove --help - The stdout should include 'location' - End - - It 'lists the rack subcommand' - When call bin/cani alpha remove --help - The stdout should include 'rack' - End - - It 'lists the device subcommand' - When call bin/cani alpha remove --help - The stdout should include 'device' - End - - It 'lists the module subcommand' - When call bin/cani alpha remove --help - The stdout should include 'module' - End - - It 'lists the cable subcommand' - When call bin/cani alpha remove --help - The stdout should include 'cable' + Describe 'subcommands' + Parameters:value location rack device module cable + It "lists the $1 subcommand" + When call bin/cani alpha remove --help + The stdout should include "$1" + End End # persistent flags @@ -132,32 +114,9 @@ Describe 'cani alpha remove' # ── argument validation ───────────────────────────────────────── Describe 'argument validation' - It 'remove location with no arg fails' - When call bin/cani alpha remove location - The status should equal 1 - The stderr should include 'accepts 1 arg(s), received 0' - End - - It 'remove rack with no arg fails' - When call bin/cani alpha remove rack - The status should equal 1 - The stderr should include 'accepts 1 arg(s), received 0' - End - - It 'remove device with no arg fails' - When call bin/cani alpha remove device - The status should equal 1 - The stderr should include 'accepts 1 arg(s), received 0' - End - - It 'remove module with no arg fails' - When call bin/cani alpha remove module - The status should equal 1 - The stderr should include 'accepts 1 arg(s), received 0' - End - - It 'remove cable with no arg fails' - When call bin/cani alpha remove cable + Parameters:value location rack device module cable + It "remove $1 with no arg fails" + When call bin/cani alpha remove "$1" The status should equal 1 The stderr should include 'accepts 1 arg(s), received 0' End diff --git a/spec/functional/show_spec.sh b/spec/functional/show_spec.sh index 8d9cc19b..ded0a72a 100644 --- a/spec/functional/show_spec.sh +++ b/spec/functional/show_spec.sh @@ -2,7 +2,7 @@ # # MIT License # -# (C) Copyright 2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2023, 2026 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -36,101 +36,20 @@ Describe 'cani alpha show' The stdout should include 'Show items from the inventory' End - # subcommands - It 'lists the location subcommand' - When call bin/cani alpha show --help - The stdout should include 'location' - End - - It 'lists the rack subcommand' - When call bin/cani alpha show --help - The stdout should include 'rack' - End - - It 'lists the device subcommand' - When call bin/cani alpha show --help - The stdout should include 'device' - End - - It 'lists the module subcommand' - When call bin/cani alpha show --help - The stdout should include 'module' - End - - It 'lists the cable subcommand' - When call bin/cani alpha show --help - The stdout should include 'cable' - End - - It 'lists the cables subcommand' - When call bin/cani alpha show --help - The stdout should include 'cables' - End - - It 'lists the interfaces subcommand' - When call bin/cani alpha show --help - The stdout should include 'interfaces' - End - - # persistent flags - It 'has --sort / -s flag' - When call bin/cani alpha show --help - The stdout should include '--sort' - End - - It 'has --format / -o flag' - When call bin/cani alpha show --help - The stdout should include '--format' - End - - It 'has --visual / -v flag' - When call bin/cani alpha show --help - The stdout should include '--visual' - End - - It 'has --rack flag' - When call bin/cani alpha show --help - The stdout should include '--rack' - End - - It 'has --no-color flag' - When call bin/cani alpha show --help - The stdout should include '--no-color' - End - - It 'has --file / -f flag' - When call bin/cani alpha show --help - The stdout should include '--file' + Describe 'subcommands' + Parameters:value location rack device module cable cables interfaces fru metadata + It "lists the $1 subcommand" + When call bin/cani alpha show --help + The stdout should include "$1" + End End - It 'has --show-cables flag' - When call bin/cani alpha show --help - The stdout should include '--show-cables' - End - - It 'has --rack-view flag' - When call bin/cani alpha show --help - The stdout should include '--rack-view' - End - - It 'has --columns flag' - When call bin/cani alpha show --help - The stdout should include '--columns' - End - - It 'has --verbose / -V flag' - When call bin/cani alpha show --help - The stdout should include '--verbose' - End - - It 'has --show-routing flag' - When call bin/cani alpha show --help - The stdout should include '--show-routing' - End - - It 'has --cable-type flag' - When call bin/cani alpha show --help - The stdout should include '--cable-type' + Describe 'persistent flags' + Parameters:value --sort --format --visual --rack --no-color --file --show-cables --rack-view --columns --verbose --show-routing --cable-type --detail + It "has $1 flag" + When call bin/cani alpha show --help + The stdout should include "$1" + End End End @@ -169,6 +88,26 @@ Describe 'cani alpha show' End End + # ── show fru help ─────────────────────────────────────────────── + + Describe 'fru --help' + It 'exits 0 and describes listing FRUs' + When call bin/cani alpha show fru --help + The status should equal 0 + The stdout should include 'FRU' + End + End + + # ── show metadata help ────────────────────────────────────────── + + Describe 'metadata --help' + It 'exits 0 and describes showing metadata definitions' + When call bin/cani alpha show metadata --help + The status should equal 0 + The stdout should include 'metadata' + End + End + # ── validation ────────────────────────────────────────────────── Describe 'validation' @@ -182,32 +121,9 @@ Describe 'cani alpha show' # ── show noun subcommands ───────────────────────────────────── Describe 'noun subcommands' - It 'show location exits 0' - When call bin/cani alpha show location --config "$CANI_CONF" - The status should equal 0 - The stdout should include 'Total:' - End - - It 'show rack exits 0' - When call bin/cani alpha show rack --config "$CANI_CONF" - The status should equal 0 - The stdout should include 'Total:' - End - - It 'show device exits 0' - When call bin/cani alpha show device --config "$CANI_CONF" - The status should equal 0 - The stdout should include 'Total:' - End - - It 'show module exits 0' - When call bin/cani alpha show module --config "$CANI_CONF" - The status should equal 0 - The stdout should include 'Total:' - End - - It 'show cable exits 0' - When call bin/cani alpha show cable --config "$CANI_CONF" + Parameters:value location rack device module cable + It "show $1 exits 0" + When call bin/cani alpha show "$1" --config "$CANI_CONF" The status should equal 0 The stdout should include 'Total:' End diff --git a/spec/functional/update_cable_spec.sh b/spec/functional/update_cable_spec.sh new file mode 100644 index 00000000..8ec83c90 --- /dev/null +++ b/spec/functional/update_cable_spec.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +# +# MIT License +# +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# ── update cable ──────────────────────────────────────────────────── + +Describe 'cani alpha update cable' + Before 'setup_crud_env' + + Describe 'valid label' + It 'updates a cable by label' + When call bin/cani alpha update cable test-cable --description "updated description" --config "$CANI_CONF" + The status should equal 0 + The stderr should include 'Updated cable' + End + End + + Describe 'invalid name' + It 'rejects an unknown name' + When call bin/cani alpha update cable nonexistent-name --description "x" --config "$CANI_CONF" + The status should equal 1 + The stderr should include 'no item found matching' + End + End + +End diff --git a/spec/functional/update_device_spec.sh b/spec/functional/update_device_spec.sh new file mode 100644 index 00000000..f56d5add --- /dev/null +++ b/spec/functional/update_device_spec.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +# +# MIT License +# +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# ── update device ─────────────────────────────────────────────────── + +Describe 'cani alpha update device' + Before 'setup_crud_env' + + Describe 'valid name' + It 'updates a device by name' + When call bin/cani alpha update device test-device --description "updated description" --config "$CANI_CONF" + The status should equal 0 + The stderr should include 'Updated device' + End + End + + Describe 'invalid name' + It 'rejects an unknown name' + When call bin/cani alpha update device nonexistent-name --description "x" --config "$CANI_CONF" + The status should equal 1 + The stderr should include 'no item found matching' + End + End + +End diff --git a/spec/functional/update_location_spec.sh b/spec/functional/update_location_spec.sh new file mode 100644 index 00000000..177b8461 --- /dev/null +++ b/spec/functional/update_location_spec.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +# +# MIT License +# +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# ── update location ──────────────────────────────────────────────── + +Describe 'cani alpha update location' + Before 'setup_crud_env' + + Describe 'valid name' + It 'updates a location by name' + When call bin/cani alpha update location test-site --description "updated description" --config "$CANI_CONF" + The status should equal 0 + The stderr should include 'Updated location' + End + End + + Describe 'invalid name' + It 'rejects an unknown name' + When call bin/cani alpha update location nonexistent-name --description "x" --config "$CANI_CONF" + The status should equal 1 + The stderr should include 'no item found matching' + End + End + +End diff --git a/spec/functional/update_module_spec.sh b/spec/functional/update_module_spec.sh new file mode 100644 index 00000000..91d3fe72 --- /dev/null +++ b/spec/functional/update_module_spec.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +# +# MIT License +# +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# ── update module ─────────────────────────────────────────────────── + +Describe 'cani alpha update module' + Before 'setup_crud_env' + + Describe 'valid name' + It 'updates a module by name' + When call bin/cani alpha update module test-module --description "updated description" --config "$CANI_CONF" + The status should equal 0 + The stderr should include 'Updated module' + End + End + + Describe 'invalid name' + It 'rejects an unknown name' + When call bin/cani alpha update module nonexistent-name --description "x" --config "$CANI_CONF" + The status should equal 1 + The stderr should include 'no item found matching' + End + End + +End diff --git a/spec/functional/update_rack_spec.sh b/spec/functional/update_rack_spec.sh new file mode 100644 index 00000000..7b9f47f1 --- /dev/null +++ b/spec/functional/update_rack_spec.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +# +# MIT License +# +# (C) Copyright 2026 Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +# ── update rack ───────────────────────────────────────────────────── + +Describe 'cani alpha update rack' + Before 'setup_crud_env' + + Describe 'valid name' + It 'updates a rack by name' + When call bin/cani alpha update rack test-rack --description "updated description" --config "$CANI_CONF" + The status should equal 0 + The stderr should include 'Updated rack' + End + End + + Describe 'invalid name' + It 'rejects an unknown name' + When call bin/cani alpha update rack nonexistent-name --description "x" --config "$CANI_CONF" + The status should equal 1 + The stderr should include 'no item found matching' + End + End + +End diff --git a/spec/functional/update_spec.sh b/spec/functional/update_spec.sh index 66fde032..b6ac05af 100644 --- a/spec/functional/update_spec.sh +++ b/spec/functional/update_spec.sh @@ -2,7 +2,7 @@ # # MIT License # -# (C) Copyright 2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2023, 2026 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -36,36 +36,20 @@ Describe 'cani alpha update' The stdout should include 'Update items in the inventory' End - # subcommands - It 'lists the location subcommand' - When call bin/cani alpha update --help - The stdout should include 'location' - End - - It 'lists the rack subcommand' - When call bin/cani alpha update --help - The stdout should include 'rack' - End - - It 'lists the device subcommand' - When call bin/cani alpha update --help - The stdout should include 'device' - End - - It 'lists the module subcommand' - When call bin/cani alpha update --help - The stdout should include 'module' + Describe 'subcommands' + Parameters:value location rack device module cable orphans + It "lists the $1 subcommand" + When call bin/cani alpha update --help + The stdout should include "$1" + End End - It 'lists the cable subcommand' - When call bin/cani alpha update --help - The stdout should include 'cable' - End - - # persistent flags - It 'has --set flag' - When call bin/cani alpha update --help - The stdout should include '--set' + Describe 'persistent flags' + Parameters:value --set --tag --metadata + It "has $1 flag" + When call bin/cani alpha update --help + The stdout should include "$1" + End End End @@ -83,24 +67,12 @@ Describe 'cani alpha update' The stdout should include '' End - It 'has --name flag' - When call bin/cani alpha update location --help - The stdout should include '--name' - End - - It 'has --content-types flag' - When call bin/cani alpha update location --help - The stdout should include '--content-types' - End - - It 'has --parent flag' - When call bin/cani alpha update location --help - The stdout should include '--parent' - End - - It 'has --description flag' - When call bin/cani alpha update location --help - The stdout should include '--description' + Describe 'flags' + Parameters:value --name --content-types --parent --description + It "has $1 flag" + When call bin/cani alpha update location --help + The stdout should include "$1" + End End End @@ -113,29 +85,12 @@ Describe 'cani alpha update' The stdout should include 'Update a rack' End - It 'has --name flag' - When call bin/cani alpha update rack --help - The stdout should include '--name' - End - - It 'has --status flag' - When call bin/cani alpha update rack --help - The stdout should include '--status' - End - - It 'has --role flag' - When call bin/cani alpha update rack --help - The stdout should include '--role' - End - - It 'has --description flag' - When call bin/cani alpha update rack --help - The stdout should include '--description' - End - - It 'has --u-height flag' - When call bin/cani alpha update rack --help - The stdout should include '--u-height' + Describe 'flags' + Parameters:value --name --status --role --description --u-height --location + It "has $1 flag" + When call bin/cani alpha update rack --help + The stdout should include "$1" + End End End @@ -148,34 +103,12 @@ Describe 'cani alpha update' The stdout should include 'Update a device' End - It 'has --name flag' - When call bin/cani alpha update device --help - The stdout should include '--name' - End - - It 'has --status flag' - When call bin/cani alpha update device --help - The stdout should include '--status' - End - - It 'has --role flag' - When call bin/cani alpha update device --help - The stdout should include '--role' - End - - It 'has --description flag' - When call bin/cani alpha update device --help - The stdout should include '--description' - End - - It 'has --position flag' - When call bin/cani alpha update device --help - The stdout should include '--position' - End - - It 'has --face flag' - When call bin/cani alpha update device --help - The stdout should include '--face' + Describe 'flags' + Parameters:value --name --status --role --description --position --face --swap --parent --nid --alias + It "has $1 flag" + When call bin/cani alpha update device --help + The stdout should include "$1" + End End End @@ -188,29 +121,12 @@ Describe 'cani alpha update' The stdout should include 'Update a module' End - It 'has --name flag' - When call bin/cani alpha update module --help - The stdout should include '--name' - End - - It 'has --status flag' - When call bin/cani alpha update module --help - The stdout should include '--status' - End - - It 'has --role flag' - When call bin/cani alpha update module --help - The stdout should include '--role' - End - - It 'has --description flag' - When call bin/cani alpha update module --help - The stdout should include '--description' - End - - It 'has --bay flag' - When call bin/cani alpha update module --help - The stdout should include '--bay' + Describe 'flags' + Parameters:value --name --status --role --description --bay + It "has $1 flag" + When call bin/cani alpha update module --help + The stdout should include "$1" + End End End @@ -223,56 +139,41 @@ Describe 'cani alpha update' The stdout should include 'Update a cable' End - It 'has --label flag' - When call bin/cani alpha update cable --help - The stdout should include '--label' + Describe 'flags' + Parameters:value --label --status --color --description + It "has $1 flag" + When call bin/cani alpha update cable --help + The stdout should include "$1" + End End + End - It 'has --status flag' - When call bin/cani alpha update cable --help - The stdout should include '--status' + # ── update orphans help & flags ───────────────────────────────── + + Describe 'orphans --help' + It 'exits 0 and describes assigning orphans' + When call bin/cani alpha update orphans --help + The status should equal 0 + The stdout should include 'orphan' End - It 'has --color flag' - When call bin/cani alpha update cable --help - The stdout should include '--color' + It 'has --dry-run flag' + When call bin/cani alpha update orphans --help + The stdout should include '--dry-run' End - It 'has --description flag' - When call bin/cani alpha update cable --help - The stdout should include '--description' + It 'has --apply-plan flag' + When call bin/cani alpha update orphans --help + The stdout should include '--apply-plan' End End # ── argument validation ───────────────────────────────────────── Describe 'argument validation' - It 'update location with no arg fails' - When call bin/cani alpha update location - The status should equal 1 - The stderr should include 'accepts 1 arg(s), received 0' - End - - It 'update rack with no arg fails' - When call bin/cani alpha update rack - The status should equal 1 - The stderr should include 'accepts 1 arg(s), received 0' - End - - It 'update device with no arg fails' - When call bin/cani alpha update device - The status should equal 1 - The stderr should include 'accepts 1 arg(s), received 0' - End - - It 'update module with no arg fails' - When call bin/cani alpha update module - The status should equal 1 - The stderr should include 'accepts 1 arg(s), received 0' - End - - It 'update cable with no arg fails' - When call bin/cani alpha update cable + Parameters:value location rack device module cable + It "update $1 with no arg fails" + When call bin/cani alpha update "$1" The status should equal 1 The stderr should include 'accepts 1 arg(s), received 0' End diff --git a/spec/spec_helper.sh b/spec/spec_helper.sh index aaf34dbd..8cf2045c 100644 --- a/spec/spec_helper.sh +++ b/spec/spec_helper.sh @@ -106,6 +106,17 @@ setup_populated_env() { cp "$FIXTURES/test-rack-inventory.json" "$CANI_DS" } +# Create a test environment pre-loaded with the CRUD inventory fixture. +# Contains: test-site (location), removable-location, test-rack, test-device, +# test-module, test-cable, and an interface. +#shellcheck disable=SC2317 +setup_crud_env() { + rm -rf "$CANI_DIR" + mkdir -p "$CANI_DIR" + cp "$FIXTURES/cani/configs/test_config.yml" "$CANI_CONF" + cp "$FIXTURES/cani/crud_inventory.json" "$CANI_DS" +} + # Remove the entire test directory. #shellcheck disable=SC2317 teardown_test_env() { diff --git a/testdata/fixtures/cani/configs/test_config.yml b/testdata/fixtures/cani/configs/test_config.yml new file mode 100644 index 00000000..f5f45599 --- /dev/null +++ b/testdata/fixtures/cani/configs/test_config.yml @@ -0,0 +1,63 @@ +# A map of settings for each provider +providers: + example: + import: {} + export: {} + ochami: + import: {} + export: {} + redfish: + import: + root: "" + export: {} + csm: + # Path to PEM-encoded CA certificate + ca_cert: "" + # Disable TLS certificate verification + insecure: false + # CIDR used by Kubernetes for pods + k8s_pods_cidr: 10.32.0.0/12 + # CIDR used by Kubernetes for services + k8s_services_cidr: 10.16.0.0/12 + # FQDN or host:port of the API gateway + provider_host: "" + # Kubernetes secret name for auth credentials + secret_name: admin-client-auth + # Use simulation mode (localhost:8443, no auth) + use_simulation: false + import: + sls_file: "" + smd_file: "" + export: {} + hpcm: + import: + # Path to HPCM cm.config file + cm_config_file: "" + # Path to HPCM node JSON file + node_json_file: "" + export: {} + nautobot: + default_location: "" # Default location for devices + default_role: "" # Default role for devices + default_status: "" # Default status for devices + token: "" # API token for authentication (use --token to override) + url: http://localhost:8081/api # Base URL of the Nautobot instance + import: {} # Import command options + export: + create_device_types: true # Create missing device types in Nautobot + create_location_types: true # Create missing location types in Nautobot + create_locations: true # Create missing locations in Nautobot + create_module_types: true # Create missing module types in Nautobot + create_roles: true # Create missing roles in Nautobot + create_statuses: true # Create missing statuses in Nautobot + dry_run: false # Log planned actions without making API calls + merge: false # Merge with existing devices instead of skipping conflicts +datastore: .cani/canidb.json # Path to the datastore file +debug: false # Enable debug logging +# Local directories with extra hardware types +types_dirs: [] +# Remote git repos with extra hardware types +types_repos: + - https://github.com/netbox-community/devicetype-library.git +types_repo_clone: false # Clone types repos that are not yet cached locally +types_repo_pull: false # Pull latest from types repos on startup diff --git a/testdata/fixtures/cani/crud_inventory.json b/testdata/fixtures/cani/crud_inventory.json new file mode 100644 index 00000000..f3df2902 --- /dev/null +++ b/testdata/fixtures/cani/crud_inventory.json @@ -0,0 +1,183 @@ +{ + "schemaVersion": "v1alpha2", + "locations": { + "0249b742-abc6-4326-b521-de2e758d3216": { + "id": "0249b742-abc6-4326-b521-de2e758d3216", + "name": "removable-location", + "slug": "dc", + "locationType": "dc", + "parent": "00000000-0000-0000-0000-000000000000", + "status": "Active", + "nestable": true, + "source": "builtin", + "description": "A top-level location type representing a data center facility. This is the highest level of the location hierarchy and can contain other location types such as levels and sections." + }, + "f9e5d985-376f-4bb1-8249-a7e82647b7f9": { + "id": "f9e5d985-376f-4bb1-8249-a7e82647b7f9", + "name": "test-site", + "locationType": "site", + "parent": "00000000-0000-0000-0000-000000000000", + "racks": [ + "58f00e62-0b30-4435-9c78-98f5aa3649f1" + ], + "status": "Active" + } + }, + "racks": { + "58f00e62-0b30-4435-9c78-98f5aa3649f1": { + "id": "58f00e62-0b30-4435-9c78-98f5aa3649f1", + "name": "test-rack", + "slug": "hpe-eia-cabinet", + "manufacturer": "HPE", + "model": "EX2000", + "type": "cabinet", + "uHeight": 0, + "deviceBays": [ + { + "name": "Chassis 0", + "allowed": { + "slug": [ + "hpe-eia-chassis" + ] + }, + "default": { + "slug": "hpe-eia-chassis" + }, + "extra": { + "ordinal": 0 + } + } + ], + "status": "Staged", + "providerMetadata": { + "csm": { + "class": "River", + "hmnVlan": 1513, + "xname": "x3000" + } + }, + "location": "f9e5d985-376f-4bb1-8249-a7e82647b7f9", + "providerDefaults": { + "csm": { + "Class": "River", + "EndingHmnVlan": 1769, + "Ordinal": 3000, + "StartingHmnVlan": 1513 + } + } + } + }, + "devices": { + "16e4c62b-237e-4977-8426-aaec65db017b": { + "id": "16e4c62b-237e-4977-8426-aaec65db017b", + "name": "test-device", + "slug": "cray-xd225v", + "partNumber": "P52183-B21", + "manufacturer": "HPE", + "model": "Cray XD225v Node", + "type": "node", + "subdeviceRole": "child", + "uHeight": 1, + "isFullDepth": true, + "interfaces": [ + { + "id": "00000000-0000-0000-0000-000000000000", + "name": "Management", + "type": "100base-tx", + "mgmt_only": true + }, + { + "id": "00000000-0000-0000-0000-000000000000", + "name": "GigabitEthernet0/0/1", + "type": "1000base-t" + } + ], + "consolePorts": [ + { + "name": "console", + "type": "rj-45-console" + }, + { + "name": "console usb3", + "type": "usb-a" + }, + { + "name": "VGA", + "type": "other" + } + ], + "powerPorts": [ + { + "name": "PSU1", + "type": "iec-60320-c14", + "maximum_draw": 105, + "allocated_draw": 67 + } + ], + "moduleBays": [ + { + "name": "PCIe1", + "position": "PCIe1" + }, + { + "name": "PCIe2", + "position": "PCIe2" + } + ], + "status": "Staged", + "parent": "00000000-0000-0000-0000-000000000000", + "rack": "00000000-0000-0000-0000-000000000000", + "location": "00000000-0000-0000-0000-000000000000", + "parentDevice": "00000000-0000-0000-0000-000000000000" + } + }, + "modules": { + "aa13b10a-b217-4642-86c1-5359733d1009": { + "id": "aa13b10a-b217-4642-86c1-5359733d1009", + "name": "test-module", + "slug": "hpe-1600w-flex-slot-platinum-hot-plug-psu", + "partNumber": "P38997-B21", + "manufacturer": "HPE", + "model": "HPE 1600W Flex Slot Platinum Hot Plug Power Supply", + "description": "HPE 1600W Flex Slot Platinum Hot Plug Low Halogen Power Supply Kit for ProLiant Gen10 Plus and Gen11 servers.", + "type": "power-supply", + "weight": 1.8, + "weightUnit": "kg", + "parentDevice": "00000000-0000-0000-0000-000000000000", + "status": "Active", + "location": "00000000-0000-0000-0000-000000000000" + } + }, + "cables": { + "6b2d3c9e-79c4-4cef-9a63-04e6c387266f": { + "id": "6b2d3c9e-79c4-4cef-9a63-04e6c387266f", + "slug": "hpe-cat5-rj45-4-3m-cable", + "label": "test-cable", + "partNumber": "C7536A", + "manufacturer": "HPE", + "model": "HPE 4.3m/14ft CAT5 RJ45 M/M Ethernet Cable", + "description": "HPE 4.3m/14ft CAT5 RJ45 M/M Ethernet Cable. Source: https://buy.hpe.com/us/en/options/cables-cable-kits/cat5-cables/hpe-cat5e-networking-and-telecom-connectivity-cable/p/C7536A", + "type": "cable", + "cableCategory": "cat5", + "connectorType": "rj45-rj45", + "length": 4.3, + "lengthUnit": "m", + "status": "Connected", + "terminationA": "00000000-0000-0000-0000-000000000000", + "terminationB": "00000000-0000-0000-0000-000000000000", + "terminationADevice": "00000000-0000-0000-0000-000000000000", + "terminationBDevice": "00000000-0000-0000-0000-000000000000" + } + }, + "frus": {}, + "interfaces": { + "00000000-0000-0000-0000-000000000000": { + "id": "00000000-0000-0000-0000-000000000000", + "name": "GigabitEthernet0/0/1", + "interfaceType": "1000base-t", + "deviceId": "16e4c62b-237e-4977-8426-aaec65db017b", + "status": "Active" + } + }, + "metadata": {} +} \ No newline at end of file