Files
demus-packaging/test/01-script-options-test.bats

164 lines
4.5 KiB
Bash

#!/usr/bin/env bats
load 'test_helper'
setup() {
load ../spec-update-artifacts.sh
common_setup
}
# bats file_tags=spec_file_argument
@test "No selection without a spec file selects sources update" {
_parse_args
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" ""
assert_equal "$UPDATE_LICENSES" ""
assert_equal "$UPDATE_SOURCES" 1
assert_equal "$IGNORE_UNLICENSED_ARG" ""
}
@test "A not .spec file returns an error" {
run _parse_args gurli.test
assert_failure 2
assert_line --index 0 "The spec file gurli.test doesn't have a .spec extension"
}
@test "A non-existent spec file returns an error" {
run _parse_args gurli.spec
assert_failure 3
assert_line --index 0 "The spec file gurli.spec is not readable"
}
# bats file_tags=options
@test "Invalid option returns an error" {
run _parse_args -q a.spec
assert_failure 9
assert_line --index 0 "Option -q is invalid"
}
@test "No selection with a spec file selects all actions" {
echo "Source: go-vendor-tools.toml" > "$TEST_TEMP_DIR/a.spec"
_parse_args "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" 1
assert_equal "$UPDATE_LICENSES" 1
assert_equal "$UPDATE_SOURCES" 1
assert_equal "$IGNORE_UNLICENSED_ARG" ""
}
@test "Only select update archive" {
touch "$TEST_TEMP_DIR/a.spec"
_parse_args -a "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" 1
assert_equal "$UPDATE_LICENSES" ""
assert_equal "$UPDATE_SOURCES" ""
assert_equal "$IGNORE_UNLICENSED_ARG" ""
}
@test "Only select update license" {
touch "$TEST_TEMP_DIR/a.spec"
_parse_args -l "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" ""
assert_equal "$UPDATE_LICENSES" 1
assert_equal "$UPDATE_SOURCES" ""
assert_equal "$IGNORE_UNLICENSED_ARG" ""
}
@test "Only select update sources" {
touch "$TEST_TEMP_DIR/a.spec"
_parse_args -s "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" ""
assert_equal "$UPDATE_LICENSES" ""
assert_equal "$UPDATE_SOURCES" 1
assert_equal "$IGNORE_UNLICENSED_ARG" ""
}
@test "Multiple selections aggregate" {
echo "Source: go-vendor-tools.toml" > "$TEST_TEMP_DIR/a.spec"
_parse_args -s -l "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" ""
assert_equal "$UPDATE_LICENSES" 1
assert_equal "$UPDATE_SOURCES" 1
assert_equal "$IGNORE_UNLICENSED_ARG" ""
}
@test "The -u option configures an --ignore-unlicensed-mods parameter for go_vendor_license" {
echo "Source: go-vendor-tools.toml" > "$TEST_TEMP_DIR/a.spec"
_parse_args -u "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$IGNORE_UNLICENSED_ARG" " --ignore-unlicensed-mods"
assert_equal "$UPDATE_ARCHIVE" 1
assert_equal "$UPDATE_LICENSES" 1
assert_equal "$UPDATE_SOURCES" 1
}
@test "The -u option implies -l" {
echo "Source: go-vendor-tools.toml" > "$TEST_TEMP_DIR/a.spec"
_parse_args -u -s "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$IGNORE_UNLICENSED_ARG" " --ignore-unlicensed-mods"
assert_equal "$UPDATE_ARCHIVE" ""
assert_equal "$UPDATE_LICENSES" 1
assert_equal "$UPDATE_SOURCES" 1
}
@test "The -u options returns an error in a not go-vendor-tools enabled project" {
touch "$TEST_TEMP_DIR/a.spec"
run _parse_args -u -s "$TEST_TEMP_DIR/a.spec"
assert_failure 4
assert_output "$TEST_TEMP_DIR/a.spec is not go-vendor-tools enabled"
}
@test "The help option successfully short-circuits everything else" {
touch "$TEST_TEMP_DIR/a.spec"
run _parse_args -h
assert_success
assert_line --index 0 --partial "Usage: "
}
@test "-t sets the sources file path and enables sources re-generation" {
touch "$TEST_TEMP_DIR/a.spec"
_parse_args -t "$TEST_TEMP_DIR/sources" "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" ""
assert_equal "$UPDATE_LICENSES" ""
assert_equal "$SOURCES_FILE" "$TEST_TEMP_DIR/sources"
assert_equal "$UPDATE_SOURCES" 1
}
@test "-t sets the sources file path and adds sources re-generation to pre-existing requests" {
echo "Source: go-vendor-tools.toml" > "$TEST_TEMP_DIR/a.spec"
_parse_args -a -t "$TEST_TEMP_DIR/sources" "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" 1
assert_equal "$UPDATE_LICENSES" ""
assert_equal "$SOURCES_FILE" "$TEST_TEMP_DIR/sources"
assert_equal "$UPDATE_SOURCES" 1
}