mirror of https://github.com/hashicorp/boundary
tests: add host sets CLI tests (#643)
parent
bee1412785
commit
cad8949ac8
@ -0,0 +1,49 @@
|
||||
function create_host_set() {
|
||||
local hcid=$1
|
||||
local name=$2
|
||||
boundary host-sets create static \
|
||||
-host-catalog-id $hcid \
|
||||
-name $name \
|
||||
-description 'test group'
|
||||
}
|
||||
|
||||
function read_host_set() {
|
||||
boundary host-sets read -id $1 -format json
|
||||
}
|
||||
|
||||
function delete_host_set() {
|
||||
boundary host-sets delete -id $1 -format json
|
||||
}
|
||||
|
||||
function list_host_sets() {
|
||||
boundary host-sets list -host-catalog-id $1 -format json
|
||||
}
|
||||
|
||||
function assoc_host_set_host() {
|
||||
boundary host-sets add-hosts -host $1 -id $2
|
||||
}
|
||||
|
||||
function host_set_id() {
|
||||
local name=$1
|
||||
local hcid=$2
|
||||
strip $(list_host_sets $hcid | jq -c ".[] | select(.name | contains(\"$name\")) | .[\"id\"]")
|
||||
}
|
||||
|
||||
function host_set_host_ids() {
|
||||
local id=$1
|
||||
ids=$(read_host_set $id | jq '.["host_ids"]')
|
||||
echo "ids $ids"
|
||||
}
|
||||
|
||||
function host_set_has_host_id() {
|
||||
local hid=$1
|
||||
local hsid=$2
|
||||
ids=$(host_set_host_ids $hsid)
|
||||
echo "ids $ids hid $hid hsid $hsid"
|
||||
for id in $ids; do
|
||||
if [ $(strip "$id") == "$hid" ]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load _auth
|
||||
load _host_sets
|
||||
load _helpers
|
||||
|
||||
export NEW_HOST_SET='test'
|
||||
|
||||
@test "boundary/login: can login as default user" {
|
||||
run login $DEFAULT_USER
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/host-sets: can add $NEW_HOST_SET host set to default host catalog" {
|
||||
run create_host_set $DEFAULT_HOST_CATALOG $NEW_HOST_SET
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/host-sets: can not add already created $NEW_HOST_SET host set" {
|
||||
run create_host_set $DEFAULT_HOST_CATALOG $NEW_HOST_SET
|
||||
echo "$output"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "boundary/host-sets: can read $NEW_HOST_SET host set" {
|
||||
local hsid=$(host_set_id $NEW_HOST_SET $DEFAULT_HOST_CATALOG)
|
||||
run read_host_set $hsid
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/host-set/add-host: can associate $NEW_HOST_SET host set with default host" {
|
||||
local hsid=$(host_set_id $NEW_HOST_SET $DEFAULT_HOST_CATALOG)
|
||||
run assoc_host_set_host $DEFAULT_HOST $hsid
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/host-set/add-host: $NEW_HOST_SET host set contains default host" {
|
||||
local hsid=$(host_set_id $NEW_HOST_SET $DEFAULT_HOST_CATALOG)
|
||||
run host_set_has_host_id $DEFAULT_HOST $hsid
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/host-set: can delete $NEW_HOST_SET host set" {
|
||||
local hsid=$(host_set_id $NEW_HOST_SET $DEFAULT_HOST_CATALOG)
|
||||
run delete_host_set $hsid
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/host-set: can not delete already deleted $NEW_HOST_SET host set" {
|
||||
local hsid=$(host_set_id $NEW_HOST_SET $DEFAULT_HOST_CATALOG)
|
||||
run delete_host_set $hsid
|
||||
echo "$output"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "boundary/host-sets: can not read deleted $NEW_HOST_SET host set" {
|
||||
local hsid=$(host_set_id $NEW_HOST_SET $DEFAULT_HOST_CATALOG)
|
||||
run read_host_set $hsid
|
||||
echo "$output"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
Loading…
Reference in new issue