From e0c130a9388d71f78181ef3759048c3c004ec16c Mon Sep 17 00:00:00 2001 From: dillanb-hashi Date: Thu, 24 Apr 2025 08:29:49 -0700 Subject: [PATCH] test(bats): Added bats tests for generic commands (#5677) * test(bats): Added bats tests for generic commands --- internal/tests/cli/boundary/_generics.bash | 18 ++++++++ internal/tests/cli/boundary/generic.bats | 49 ++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 internal/tests/cli/boundary/_generics.bash create mode 100644 internal/tests/cli/boundary/generic.bats diff --git a/internal/tests/cli/boundary/_generics.bash b/internal/tests/cli/boundary/_generics.bash new file mode 100644 index 000000000..aeaecdcb1 --- /dev/null +++ b/internal/tests/cli/boundary/_generics.bash @@ -0,0 +1,18 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: BUSL-1.1 + +export UPDATE_NAME='update' + +function generic_read() { + boundary read $1 -format json +} + +function generic_update_name() { + local id=$1 + local name=$2 + boundary update $id -name $name +} + +function generic_delete() { + boundary delete $1 -format json +} \ No newline at end of file diff --git a/internal/tests/cli/boundary/generic.bats b/internal/tests/cli/boundary/generic.bats new file mode 100644 index 000000000..b61665746 --- /dev/null +++ b/internal/tests/cli/boundary/generic.bats @@ -0,0 +1,49 @@ +#!/usr/bin/env bats + +load _auth +load _helpers +load _targets +load _generics + + +@test "boundary/generic: can log in as admin user" { + run login $DEFAULT_LOGIN + [ "$status" -eq 0 ] +} + +@test "boundary/generic: admin user can create target" { + run create_tcp_target $DEFAULT_P_ID 22 $TGT_NAME + echo $output + [ "$status" -eq 0 ] +} + +@test "boundary/generic: admin user can read target with generic read" { + local id=$(target_id_from_name $DEFAULT_P_ID $TGT_NAME) + run generic_read $id + echo $output + [ "$status" -eq 0 ] +} + +@test "boundary/generic: admin user can update target with generic update" { + local id=$(target_id_from_name $DEFAULT_P_ID $TGT_NAME) + run generic_update_name $id $UPDATE_NAME + echo $output + [ "$status" -eq 0 ] +} + +@test "boundary/generic: admin user can check that the update worked with generic read" { + local id=$(target_id_from_name $DEFAULT_P_ID $UPDATE_NAME) + echo $id + run generic_read $id + echo $output + [ "$status" -eq 0 ] +} + +@test "boundary/generic: admin user can delete target with generic delete" { + local id=$(target_id_from_name $DEFAULT_P_ID $UPDATE_NAME) + run generic_delete $id + echo $output + [ "$status" -eq 0 ] + run has_status_code "$output" "204" + [ "$status" -eq 0 ] +} \ No newline at end of file