diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index d28273a..ee3c2c9 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -19,3 +19,41 @@ jobs: - name: Lint with shellcheck run: make lint + + test: + name: Test + runs-on: ubuntu-latest + defaults: + run: + shell: bash -i {0} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Mock cURL and wget + run: | + echo "REAL_CURL=$(which curl)" >> $GITHUB_ENV + echo "REAL_WGET=$(which wget)" >> $GITHUB_ENV + echo "$(pwd)/mocks/" >> $GITHUB_PATH + + - name: Install g using g-install with default options + run: curl -sSL https://git.io/g-install | sh -s -- -y bash + + - name: Verify environment variables + run: test ! -z "${GOROOT?}" && test ! -z "${GOPATH?}" + + - name: Verify g installation + run: g --version + + - name: Verify go installation + run: go version + + - name: Make sure it is the go binary installed by g + run: test "$(which go)" = "$GOPATH/bin/go" + + - name: Make sure g can switch versions + run: g install 1.14.15 && go version | grep -1 "go1.14.15" + + - name: Make sure g can self-upgrade + run: SHELL="$(which bash)" g self-upgrade diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d109f4..e4204ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Upgrade shfmt from v3.0.0 to v3.2.4, no format changes introduced - Introduce a Github Actions workflow file with lint only for now - Fix g breaking on missing $TERM var in non-interactive systems +- Add basic tests to the Github Actions workflow ## 0.8.0 - 2019-12-24 diff --git a/Makefile b/Makefile index 65e4c16..bbc8d24 100644 --- a/Makefile +++ b/Makefile @@ -16,12 +16,12 @@ prepare: .tmp/shellcheck .tmp/shfmt .PHONY: lint lint: prepare - @./.tmp/shellcheck bin/* - @./.tmp/shfmt -d bin/* + @./.tmp/shellcheck bin/* mocks/* + @./.tmp/shfmt -d bin/* mocks/* .PHONY: format format: prepare - @./.tmp/shfmt -w bin/* + @./.tmp/shfmt -w bin/* mocks/* .tmp/shellcheck: @echo "Downloading shellcheck" diff --git a/mocks/curl b/mocks/curl new file mode 100755 index 0000000..280832f --- /dev/null +++ b/mocks/curl @@ -0,0 +1,26 @@ +#!/bin/sh + +# POSIX shell doesn't support errtrace nor pipefail. + +# Exit on error. Append "|| true" if you expect an error. +set -o errexit +# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR. +set -o nounset + +BASE_DIR="$(dirname -- "$0")" +G_URL="https://git.io/g-bin" +G_LOCATION="$BASE_DIR/../bin/g" +INSTALL_URL="https://git.io/g-install" +INSTALL_LOCATION="$BASE_DIR/../bin/install" + +for item in "$@"; do + if [ "$item" = "$G_URL" ]; then + cat "$G_LOCATION" + return + elif [ "$item" = "$INSTALL_URL" ]; then + cat "$INSTALL_LOCATION" + return + fi +done + +command "${REAL_CURL:?}" "$@" diff --git a/mocks/wget b/mocks/wget new file mode 100755 index 0000000..33124ca --- /dev/null +++ b/mocks/wget @@ -0,0 +1,26 @@ +#!/bin/sh + +# POSIX shell doesn't support errtrace nor pipefail. + +# Exit on error. Append "|| true" if you expect an error. +set -o errexit +# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR. +set -o nounset + +BASE_DIR="$(dirname -- "$0")" +G_URL="https://git.io/g-bin" +G_LOCATION="$BASE_DIR/../bin/g" +INSTALL_URL="https://git.io/g-install" +INSTALL_LOCATION="$BASE_DIR/../bin/install" + +for item in "$@"; do + if [ "$item" = "$G_URL" ]; then + cat "$G_LOCATION" + return + elif [ "$item" = "$INSTALL_URL" ]; then + cat "$INSTALL_LOCATION" + return + fi +done + +command "${REAL_WGET:?}" "$@"