-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(container): add create container
- Loading branch information
Showing
5 changed files
with
318 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
dist/test/lib/vedv/components/container/container-command.bats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# shellcheck disable=SC2016 | ||
load test_helper | ||
|
||
setup_file() { | ||
vedv::container_command::constructor 'vedv' | ||
export __VED_CONTAINER_COMMAND_SCRIPT_NAME | ||
} | ||
|
||
vedv::container_service::create() { echo "container created, arguments: $*"; } | ||
|
||
@test "vedv::container_command::__create(), with arg '-h|--help|help' should show help" { | ||
local -r help_output='vedv container create [OPTIONS] IMAGE' | ||
|
||
run vedv::container_command::__create -h | ||
|
||
assert_success | ||
assert_output --partial "$help_output" | ||
|
||
run vedv::container_command::__create --help | ||
|
||
assert_success | ||
assert_output --partial "$help_output" | ||
|
||
run vedv::container_command::__create help | ||
|
||
assert_success | ||
assert_output --partial "$help_output" | ||
|
||
} | ||
|
||
@test 'vedv::container_command::__create(), should create a container' { | ||
local image_file="$TEST_OVA_FILE" | ||
|
||
run vedv::container_command::__create "$image_file" | ||
|
||
assert_success | ||
assert_output 'container created, arguments: /tmp/vedv/test/files/alpine-x86_64.ova ' | ||
} | ||
|
||
@test 'vedv::container_command::__create(), with --name should create a container' { | ||
local container_name='super-llama-testunit-container-command' | ||
local image_file="$TEST_OVA_FILE" | ||
|
||
run vedv::container_command::__create --name "$container_name" "$image_file" | ||
|
||
assert_success | ||
assert_output 'container created, arguments: /tmp/vedv/test/files/alpine-x86_64.ova super-llama-testunit-container-command' | ||
} | ||
|
||
@test "vedv::container_command::__create(), with invalid arg throw an error" { | ||
|
||
run vedv::container_command::__create 'image_file' 'invalid_arg' | ||
|
||
assert_failure 69 | ||
assert_output --partial 'Invalid parameter: invalid_arg' | ||
} |
73 changes: 73 additions & 0 deletions
73
dist/test/lib/vedv/components/container/container-service.bats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# shellcheck disable=SC2016 | ||
load test_helper | ||
|
||
setup_file() { | ||
vedv::container_service::constructor 'virtualbox' | ||
vedv::image_service::constructor 'virtualbox' | ||
|
||
export __VEDV_CONTAINER_SERVICE_HYPERVISOR | ||
export __VEDV_IMAGE_SERVICE_HYPERVISOR | ||
} | ||
|
||
teardown() { | ||
delete_vms_by_partial_vm_name 'testunit-container-service' | ||
delete_vms_by_partial_vm_name 'image:alpine-x86_64|crc:87493131' | ||
} | ||
|
||
@test "vedv::container_service::__gen_container_vm_name_from_image_vm_name(), with 'image_vm_name' unset should throw an error" { | ||
run vedv::container_service::__gen_container_vm_name_from_image_vm_name | ||
|
||
assert_failure 1 | ||
assert_output --partial '$1: unbound variable' | ||
} | ||
|
||
@test "vedv::container_service::__gen_container_vm_name_from_image_vm_name(), should generate the name" { | ||
local image_vm_name='image:base-image|crc:261268494' | ||
run vedv::container_service::__gen_container_vm_name_from_image_vm_name "$image_vm_name" | ||
|
||
assert_success | ||
assert_output 'container:base-image|crc:261268494' | ||
} | ||
|
||
@test "vedv::container_service::__gen_container_vm_name, should generate the name" { | ||
petname() { echo 'tintin-pet'; } | ||
run vedv::container_service::__gen_container_vm_name | ||
|
||
assert_success | ||
assert_output 'container:tintin-pet|crc:1823374605' | ||
} | ||
|
||
@test "vedv::container_service::__gen_container_vm_name, with name, should generate the name" { | ||
local -r container_name='rinti-love' | ||
run vedv::container_service::__gen_container_vm_name "$container_name" | ||
|
||
assert_success | ||
assert_output 'container:rinti-love|crc:1085124909' | ||
} | ||
|
||
@test "vedv::container_service::create, with name unset, should throw an error" { | ||
run vedv::container_service::create | ||
|
||
assert_failure 1 | ||
assert_output --partial '$1: unbound variable' | ||
} | ||
|
||
@test "vedv::container_service::create, should create a container vm" { | ||
local -r image="$TEST_OVA_FILE" | ||
local -r container_name='happy-dyli-testunit-container-service' | ||
run vedv::container_service::create "$image" "$container_name" | ||
|
||
assert_success | ||
assert_output 'container:happy-dyli-testunit-container-service|crc:2520159523' | ||
} | ||
|
||
@test "vedv::container_service::create, should throw error if there is another container with the same name" { | ||
local -r image="$TEST_OVA_FILE" | ||
local -r container_name='happy-dyli-testunit-container-service' | ||
|
||
vedv::container_service::create "$image" "$container_name" | ||
run vedv::container_service::create "$image" "$container_name" | ||
|
||
assert_failure 80 | ||
assert_output "container with name: 'happy-dyli-testunit-container-service' already exist" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
. "${DIST_PATH}/test/test_helper_base.bash" | ||
. "${DIST_PATH}/lib/vedv/hypervisors/virtualbox.bash" | ||
. "${DIST_PATH}/lib/vedv/components/image/image-service.bash" | ||
. "${DIST_PATH}/lib/vedv/components/container/container-service.bash" | ||
. "${DIST_PATH}/lib/vedv/components/container/container-command.bash" |