First batch of tests

This commit is contained in:
southerntofu 2020-09-15 22:07:49 +02:00
parent e8e217434d
commit 789bbefddf
2 changed files with 190 additions and 2 deletions

View File

@ -1,3 +1,47 @@
# git-build-i18n
# forgebuild
Translation strings for the different git-build implementations
This repository contains the specification, translation strings, and tests for forgebuild, a system to check for updates on remote repositories and trigger some tasks accordingly.
If you are looking for a program you may use as an end user, check out [forge/build.rs](https://tildegit.org/forge/build.rs) (Rust) or [forge/build.sh](https://tildegit.org/forge/build.sh) (bash) instead.
## Specification
forgebuild is based on a specification which can be found in the [spec.md](spec.md) document. This document is versioned, and all forgebuild implementations should use it as a reference.
## Translations
This repository also contains translation files for the various forgebuild implementations. The reference translations are located in the `i18n/` folder, stored as JSON files using 2-letter codes for the language name, such as `en.json`.
In the future, some scripts may be added to convert those JSON files to different formats such as [GNU gettext](https://www.gnu.org/software/gettext/).
## Tests
This project contains the tests for validating your forgebuild implementation. These tests are written with the [bats](https://github.com/bats-core/bats-core/) testing framework, which runs anywhere bash does. Currently, the forgebuild implementation you want to test needs to be `forgebuild` in the $PATH.
To run the tests:
```
# Requirements on Debian-based systems:
# sudo apt install bats git
$ git clone https://tildegit.org/forge/build
$ bats build/tests
✓ repository is cloned
✓ first run triggers task
✓ no update does not trigger task
✓ forced run triggers task
✓ update triggers task
✓ host-based settings are loaded
✓ unknown host uses default settings
✓ submodule is cloned
✓ first submodule run triggers task
✓ submodule update does not trigger task by default
10 tests, 0 failures
```
TODO:
- [x] basic function tests
- [ ] configurable forgebuild path, so we can test different implementations
- [x] task settings (global/per-host settings)
- [ ] PGP signatures

144
tests/git.bats Executable file
View File

@ -0,0 +1,144 @@
#! /usr/bin/env bats
# This is a test file for use with the bats testing framework
# https://github.com/bats-core/bats-core
# On Debian: apt install bats
function setup {
ORIGDIR="$(pwd)"
# Ensure output from previous test does not exist
# (in case something crashed)
clean
# Setup simple git repository
GITREPO="$(mktemp -d)"
cd $GITREPO
git init
echo "first commit" > README
git add README
git commit -m "first commit"
# Setup forgebuild tasks
FORGEBUILDDIR="$(mktemp -d)"
echo "$GITREPO" > $FORGEBUILDDIR/time.source
echo "date +%s%N > /tmp/forgebuild-time" > $FORGEBUILDDIR/time
chmod +x $FORGEBUILDDIR/time
echo "$GITREPO" > $FORGEBUILDDIR/host.source
echo "cat \$GITBUILDCONF/entry > /tmp/forgebuild-host" > $FORGEBUILDDIR/host
chmod +x $FORGEBUILDDIR/host
# Setup settings
mkdir $FORGEBUILDDIR/config
echo "default" > $FORGEBUILDDIR/config/entry
mkdir $FORGEBUILDDIR/$HOSTNAME
echo "host" > $FORGEBUILDDIR/$HOSTNAME/entry
}
function teardown {
cd $ORIGDIR
clean
}
function clean {
if [ -d $GITREPO ]; then rm -rf $GITREPO; fi
if [ -d $FORGEBUILDDIR ]; then rm -rf $FORGEBUILDDIR; fi
if [ -f /tmp/forgebuild-time ]; then rm /tmp/forgebuild-time; fi
if [ -f /tmp/forgebuild-host ]; then rm /tmp/forgebuild-host; fi
}
function setup_submodule {
SUBMODULE="$(mktemp -d)"
cd $SUBMODULE
git init
echo "SUB" > README
git add README
git commit -m "first commit"
cd $GITREPO
git submodule add $SUBMODULE sub
git commit -m "add submodule"
}
@test "repository is cloned" {
forgebuild -b $FORGEBUILDDIR time
[ -f $FORGEBUILDDIR/.time/README ]
}
@test "first run triggers task" {
forgebuild -b $FORGEBUILDDIR time
[ -f /tmp/forgebuild-time ]
}
@test "no update does not trigger task" {
forgebuild -b $FORGEBUILDDIR time
[ -f /tmp/forgebuild-time ]
TIME="$(cat /tmp/forgebuild-time)"
forgebuild -b $FORGEBUILDDIR time
NEWTIME="$(cat /tmp/forgebuild-time)"
[[ "$TIME" = "$NEWTIME" ]]
}
@test "forced run triggers task" {
forgebuild -b $FORGEBUILDDIR time
[ -f /tmp/forgebuild-time ]
TIME="$(cat /tmp/forgebuild-time)"
forgebuild -f -b $FORGEBUILDDIR time
NEWTIME="$(cat /tmp/forgebuild-time)"
[[ "$TIME" != "$NEWTIME" ]]
}
@test "update triggers task" {
forgebuild -b $FORGEBUILDDIR time
[ -f /tmp/forgebuild-time ]
TIME="$(cat /tmp/forgebuild-time)"
cd $GITREPO
touch NEWFILE
git add NEWFILE
git commit -m "second commit"
forgebuild -b $FORGEBUILDDIR time
NEWTIME="$(cat /tmp/forgebuild-time)"
[[ "$TIME" != "$NEWTIME" ]]
}
@test "host-based settings are loaded" {
forgebuild -b $FORGEBUILDDIR host
[[ "$(cat /tmp/forgebuild-host)" = "host" ]]
}
@test "unknown host uses default settings" {
HOST="UNKNOWN" forgebuild -b $FORGEBUILDDIR host
[[ "$(cat /tmp/forgebuild-host)" = "default" ]]
}
@test "submodule is cloned" {
setup_submodule
forgebuild -b $FORGEBUILDDIR time
[ -f $FORGEBUILDDIR/.time/sub/README ]
[[ "$(cat $FORGEBUILDDIR/.time/sub/README)" = "SUB" ]]
}
@test "first submodule run triggers task" {
setup_submodule
forgebuild -b $FORGEBUILDDIR time
[ -f /tmp/forgebuild-time ]
}
@test "submodule update does not trigger task by default" {
setup_submodule
forgebuild -b $FORGEBUILDDIR time
[ -f /tmp/forgebuild-time ]
TIME="$(cat /tmp/forgebuild-time)"
cd $SUBMODULE
echo "new stuff" > NEWFILE
git add NEWFILE
git commit -m "second commit"
forgebuild -b $FORGEBUILDDIR time
NEWTIME="$(cat /tmp/forgebuild-time)"
[[ "$TIME" = "$NEWTIME" ]]
}