tests: add hosts CLI tests (#638)

pull/639/head
Jeff Malnick 6 years ago committed by GitHub
parent 73388d21aa
commit 0f1fbea8f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,6 +6,7 @@ export DEFAULT_P_ID='p_1234567890'
export DEFAULT_O_ID='o_1234567890'
export DEFAULT_TARGET='ttcp_1234567890'
export DEFAULT_HOST_SET='hsst_1234567890'
export DEFAULT_HOST_CATALOG='hcst_1234567890'
function strip() {
echo "$1" | tr -d '"'

@ -0,0 +1,23 @@
function create_host_catalog() {
local sid=$1
local name=$2
boundary host-catalogs create static -scope-id $sid -name $name -description 'test host catalog'
}
function read_host_catalog() {
boundary hosts read -id $1
}
function delete_host_catalog() {
boundary hosts delete -id $1
}
function list_host_catalogs() {
boundary host-catalogs list -scope-id $1 -format json
}
function host_catalog_id() {
local id=$1
local sid=$2
strip $(list_host_catalogs $sid | jq -c ".[] | select(.name | contains(\"$id\")) | .[\"id\"]")
}

@ -1,8 +1,12 @@
function create_host() {
local name=$1
local addr=$2
boundary hosts create static -name $name -address $addr
local hcid=$2
boundary hosts create static \
-name $name \
-description 'test host' \
-address '1.1.1.1' \
-host-catalog-id $hcid
}
function read_host() {
@ -14,11 +18,12 @@ function delete_host() {
}
function list_hosts() {
boundary hosts list -scope-id $1 -format json
boundary hosts list -host-catalog-id $1 -format json
}
function host_id() {
local sid=$1
local name=$2
strip $(list_hosts $sid | jq -c ".[] | select(.name | contains(\"$name\")) | .[\"id\"]")
local name=$1
local hcid=$2
strip $(list_hosts $hcid | jq -c ".[] | select(.name | contains(\"$name\")) | .[\"id\"]")
}

@ -0,0 +1,53 @@
#!/usr/bin/env bats
load _auth
load _hosts
load _helpers
export NEW_HOST='test'
@test "boundary/login: can login as default user" {
run login $DEFAULT_USER
echo "$output"
[ "$status" -eq 0 ]
}
@test "boundary/hosts: can create $NEW_HOST host in default host catalog" {
run create_host $NEW_HOST $DEFAULT_HOST_CATALOG
echo "$output"
[ "$status" -eq 0 ]
}
@test "boundary/hosts: can not add already created $NEW_HOST host in default host catalog" {
run create_host $NEW_HOST
echo "$output"
[ "$status" -eq 1 ]
}
@test "boundary/hosts: can read $NEW_HOST host" {
local hid=$(host_id $NEW_HOST $DEFAULT_HOST_CATALOG)
run read_host $hid
echo "$output"
[ "$status" -eq 0 ]
}
@test "boundary/host: can delete $NEW_HOST host" {
local hid=$(host_id $NEW_HOST $DEFAULT_HOST_CATALOG)
run delete_host $hid
echo "$output"
[ "$status" -eq 0 ]
}
@test "boundary/host: can not delete already deleted $NEW_HOST host" {
local hid=$(host_id $NEW_HOST $DEFAULT_HOST_CATALOG)
run delete_host $hid
echo "$output"
[ "$status" -eq 1 ]
}
@test "boundary/hosts: can not read deleted $NEW_HOST host" {
local hid=$(host_id $NEW_HOST $DEFAULT_HOST_CATALOG)
run read_host $hid
echo "$output"
[ "$status" -eq 1 ]
}
Loading…
Cancel
Save