#!/usr/bin/env bats # The crosscode entry script: help, and the argument checks that run before anything needs root. setup() { export CROSSCODE_NO_UPDATE=1 CC="$BATS_TEST_DIRNAME/../crosscode" } @test "help lists the commands" { run bash "$CC" help [ "$status" -eq 0 ] [[ "$output" == *"crosscode deploy "* ]] [[ "$output" == *"crosscode adopt --undo"* ]] } @test "help shows that command's options" { run bash "$CC" help deploy [ "$status" -eq 0 ] [[ "$output" == *"--every-church"* ]] run bash "$CC" adopt --help [ "$status" -eq 0 ] [[ "$output" == *"--events-dir"* ]] } @test "an unknown command fails" { run bash "$CC" frobnicate [ "$status" -eq 1 ] [[ "$output" == *'Unknown command "frobnicate"'* ]] } @test "the copy it runs from is removed afterwards" { before="$(find /tmp -maxdepth 1 -name 'crosscode.*' 2>/dev/null | wc -l)" run bash "$CC" help after="$(find /tmp -maxdepth 1 -name 'crosscode.*' 2>/dev/null | wc -l)" [ "$before" -eq "$after" ] } @test "deploy refuses bad arguments before touching anything" { run bash "$CC" deploy hopefamily events --version events@2.2 [ "$status" -eq 1 ] [[ "$output" == *"expected @"* ]] run bash "$CC" deploy hopefamily --version events@2.2.0 [ "$status" -eq 1 ] [[ "$output" == *"name events as well"* ]] run bash "$CC" deploy hopefamily events --main --version events@2.2.0 [ "$status" -eq 1 ] [[ "$output" == *"not both"* ]] run bash "$CC" deploy hopefamily calendar [ "$status" -eq 1 ] [[ "$output" == *'Unknown product "calendar"'* ]] run bash "$CC" deploy hopefamily --frobnicate [ "$status" -eq 1 ] run bash "$CC" deploy events --every-church [ "$status" -eq 1 ] [[ "$output" != *"doesn't take a church name"* ]] run bash "$CC" deploy hopefamily --every-church [ "$status" -eq 1 ] [[ "$output" == *"doesn't take a church name"* ]] } @test "install and adopt check their arguments" { run bash "$CC" install Hope --products events --domain hope.co.za --no-ssl [ "$status" -eq 1 ] [[ "$output" == *"isn't a church name"* ]] run bash "$CC" install hope --products website --domain hope.co.za --no-ssl [ "$status" -eq 1 ] [[ "$output" == *"can only install events"* ]] run bash "$CC" install hope --products events --domain hope.co.za [ "$status" -eq 1 ] [[ "$output" == *"--email is required"* ]] run bash "$CC" adopt hope [ "$status" -eq 1 ] [[ "$output" == *"--events-dir is required"* ]] run bash "$CC" adopt hope --events-dir /var/www/hope-events --version 2.2.0 [ "$status" -eq 1 ] [[ "$output" == *"expected events@x.y.z"* ]] }