Add a basic deployment test (#476)

This commit is contained in:
David Boreham 2023-07-31 15:08:34 -06:00 committed by GitHub
parent a8f4e4cee4
commit 5afe7a29ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 4 deletions

View File

@ -45,6 +45,13 @@ def init(command_context: DeployCommandContext):
return yaml.load(default_spec_file_content) return yaml.load(default_spec_file_content)
def create(command_context: DeployCommandContext):
data = "create-command-output-data"
output_file_path = command_context.deployment_dir.joinpath("create-file")
with open(output_file_path, 'w+') as output_file:
output_file.write(data)
def get_state(command_context: DeployCommandContext): def get_state(command_context: DeployCommandContext):
print("Here we get state") print("Here we get state")
return State.CONFIGURED return State.CONFIGURED

View File

@ -209,7 +209,7 @@ def create(ctx, spec_file, deployment_dir):
# stack member here. # stack member here.
deployment_command_context = ctx.obj deployment_command_context = ctx.obj
deployment_command_context.stack = stack_name deployment_command_context.stack = stack_name
deployment_context = DeploymentContext(Path(deployment_dir), ctx.obj) deployment_context = DeploymentContext(Path(deployment_dir), deployment_command_context)
call_stack_deploy_create(deployment_context) call_stack_deploy_create(deployment_context)

View File

@ -26,17 +26,18 @@ $TEST_TARGET_SO --stack test build-containers
# Test deploy command execution # Test deploy command execution
$TEST_TARGET_SO --stack test deploy setup $CERC_REPO_BASE_DIR $TEST_TARGET_SO --stack test deploy setup $CERC_REPO_BASE_DIR
# Check that we now have the expected output directory # Check that we now have the expected output directory
if [ ! -d "$CERC_REPO_BASE_DIR/container-output-dir" ]; then container_output_dir=$CERC_REPO_BASE_DIR/container-output-dir
if [ ! -d "$container_output_dir" ]; then
echo "deploy setup test: output directory not present" echo "deploy setup test: output directory not present"
echo "deploy setup test: FAILED" echo "deploy setup test: FAILED"
exit 1 exit 1
fi fi
if [ ! -f "$CERC_REPO_BASE_DIR/container-output-dir/output-file" ]; then if [ ! -f "$container_output_dir/output-file" ]; then
echo "deploy setup test: output file not present" echo "deploy setup test: output file not present"
echo "deploy setup test: FAILED" echo "deploy setup test: FAILED"
exit 1 exit 1
fi fi
output_file_content=$(<$CERC_REPO_BASE_DIR/container-output-dir/output-file) output_file_content=$(<$container_output_dir/output-file)
if [ ! "$output_file_content" == "output-data" ]; then if [ ! "$output_file_content" == "output-data" ]; then
echo "deploy setup test: output file contents not correct" echo "deploy setup test: output file contents not correct"
echo "deploy setup test: FAILED" echo "deploy setup test: FAILED"
@ -73,4 +74,41 @@ else
exit 1 exit 1
fi fi
$TEST_TARGET_SO --stack test deploy down --delete-volumes $TEST_TARGET_SO --stack test deploy down --delete-volumes
# Basic test of creating a deployment
test_deployment_dir=$CERC_REPO_BASE_DIR/test-deployment-dir
test_deployment_spec=$CERC_REPO_BASE_DIR/test-deployment-spec.yml
$TEST_TARGET_SO --stack test deploy init --output $test_deployment_spec
# Check the file now exists
if [ ! -f "$test_deployment_spec" ]; then
echo "deploy init test: spec file not present"
echo "deploy init test: FAILED"
exit 1
fi
echo "deploy init test: passed"
$TEST_TARGET_SO deploy create --spec-file $test_deployment_spec --deployment-dir $test_deployment_dir
# Check the deployment dir exists
if [ ! -d "$test_deployment_dir" ]; then
echo "deploy create test: deployment directory not present"
echo "deploy create test: FAILED"
exit 1
fi
echo "deploy create test: passed"
# Check the file writted by the create command in the stack now exists
if [ ! -f "$test_deployment_dir/create-file" ]; then
echo "deploy create test: create output file not present"
echo "deploy create test: FAILED"
exit 1
fi
# And has the right content
create_file_content=$(<$test_deployment_dir/create-file)
if [ ! "$create_file_content" == "create-command-output-data" ]; then
echo "deploy create test: create output file contents not correct"
echo "deploy create test: FAILED"
exit 1
fi
echo "deploy create output file test: passed"
# Try to start the deployment
$TEST_TARGET_SO deployment --dir $test_deployment_dir start
# Stop and clean up
$TEST_TARGET_SO deployment --dir $test_deployment_dir stop --delete-volumes
echo "Test passed" echo "Test passed"