Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hashtagchris committed Sep 21, 2020
1 parent 8862a56 commit b5e5d34
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions script/test-build
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ DEST_API_PID=-1
trap "after_suite" EXIT
trap "after_suite" SIGINT

function test_version() {
version "version shouldn't require any flags"

echo "all version tests passed"
}

function test_pull() {
# Pull new repo
setup_src "org/repo:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142"
Expand Down Expand Up @@ -86,6 +92,16 @@ function test_push() {
assert_dest_sha "org1/repo2" "tags/v1" "e9009d51dd6da2c363d1d14779c53dd27fcb0c52" "updating org1/repo2:tags/v1 to new commit"
assert_dest_sha "org2/repo1" "heads/main" "e9009d51dd6da2c363d1d14779c53dd27fcb0c52" "updating org2/repo1:tags/v1 to new commit"

# Honor --repo-name flag, ignore other cache entries
setup_cache "org/repo1:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52" \
"org/repo2:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52"
setup_dest "org/repo1:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142" \
"org/repo2:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142"

push2args --repo-name "org/repo1" "pushing only one of the repos in the cache"
assert_dest_sha "org/repo1" "heads/main" "e9009d51dd6da2c363d1d14779c53dd27fcb0c52" "updating org/repo1 passed in repo flag"
assert_dest_sha "org/repo2" "heads/main" "a5984bb887dd2fcdc2892cd906d6f004844d1142" "org/repo2 not updated despite cache"

echo "all push tests passed successfully"
}

Expand Down Expand Up @@ -142,6 +158,16 @@ function test_sync() {
sync --repo-name "org/repo:org2/repo2" "syncing org/repo aliased to org2/repo2"
assert_dest_sha "org2/repo2" "heads/main" "e9009d51dd6da2c363d1d14779c53dd27fcb0c52" "syncing org/repo aliased to org2/repo2"

# Honor --repo-name flag, ignore other cache entries
setup_cache "org/repo1:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52" \
"org/repo2:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52"
setup_dest "org/repo1:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142" \
"org/repo2:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142"

sync --repo-name "org/repo1" "syncing only one of the repos in the cache"
assert_dest_sha "org/repo1" "heads/main" "e9009d51dd6da2c363d1d14779c53dd27fcb0c52" "updating org/repo1 passed in repo flag"
assert_dest_sha "org/repo2" "heads/main" "a5984bb887dd2fcdc2892cd906d6f004844d1142" "org/repo2 not updated despite cache"

echo "all sync tests passed successfully"
}

Expand Down Expand Up @@ -230,6 +256,12 @@ function setup_dest() {
done
}

function version() {
bin/actions-sync version \
&> $OUTPUT ||
fail $1
}

function pull() {
bin/actions-sync pull \
--cache-dir "test/tmp/cache" \
Expand All @@ -249,6 +281,17 @@ function push() {
fail "$1"
}

function push2args() {
bin/actions-sync push \
--cache-dir "test/tmp/cache" \
--disable-push-git-auth \
--destination-token "token" \
--destination-url "http://localhost:$DEST_API_PORT" \
"$1" "$2" \
&> $OUTPUT ||
fail $3
}

function sync() {
bin/actions-sync sync \
--cache-dir "test/tmp/cache" \
Expand Down Expand Up @@ -298,6 +341,7 @@ function fail() {
exit 1
}

test_version
before_suite
test_pull
test_push
Expand Down

0 comments on commit b5e5d34

Please sign in to comment.