mirror of https://github.com/gitwatch/gitwatch
Merge branch 'workingdir-28'
commit
72fa2a3181
@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
# This is a testscript using the bats testing framework:
|
||||
# https://github.com/sstephenson/bats
|
||||
# To run it, at a command prompt:
|
||||
# bats testscript.bats
|
||||
|
||||
load startup-shutdown
|
||||
|
||||
@test "commit log messages working" {
|
||||
# Start up gitwatch with logging, see if works
|
||||
${BATS_TEST_DIRNAME}/../gitwatch.sh -l 10 "$testdir/local/remote" 3>&- &
|
||||
GITWATCH_PID=$!
|
||||
|
||||
# Keeps kill message from printing to screen
|
||||
disown
|
||||
|
||||
# Create a file, verify that it hasn't been added yet, then commit
|
||||
cd remote
|
||||
|
||||
# According to inotify documentation, a race condition results if you write
|
||||
# to directory too soon after it has been created; hence, a short wait.
|
||||
sleep 1
|
||||
echo "line1" >> file1.txt
|
||||
|
||||
# Wait a bit for inotify to figure out the file has changed, and do its add,
|
||||
# and commit
|
||||
sleep $WAITTIME
|
||||
|
||||
# Make a new change
|
||||
echo "line2" >> file1.txt
|
||||
sleep $WAITTIME
|
||||
|
||||
# Check commit log that the diff is in there
|
||||
run git log -1 --oneline
|
||||
[[ $output == *"file1.txt"* ]]
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
# This is a testscript using the bats testing framework:
|
||||
# https://github.com/sstephenson/bats
|
||||
# To run it, at a command prompt:
|
||||
# bats testscript.bats
|
||||
|
||||
load startup-shutdown
|
||||
|
||||
@test "remote git dirs working, with commit logging" {
|
||||
# Move .git somewhere else
|
||||
dotgittestdir=$(mktemp -d)
|
||||
mv "$testdir/local/remote/.git" "$dotgittestdir"
|
||||
|
||||
# Start up gitwatch, intentionally in wrong directory, with remote dir specified
|
||||
${BATS_TEST_DIRNAME}/../gitwatch.sh -l 10 -g "$dotgittestdir/.git" "$testdir/local/remote" 3>&- &
|
||||
GITWATCH_PID=$!
|
||||
|
||||
# Keeps kill message from printing to screen
|
||||
disown
|
||||
|
||||
# Create a file, verify that it hasn't been added yet, then commit
|
||||
cd remote
|
||||
|
||||
# According to inotify documentation, a race condition results if you write
|
||||
# to directory too soon after it has been created; hence, a short wait.
|
||||
sleep 1
|
||||
echo "line1" >> file1.txt
|
||||
|
||||
# Wait a bit for inotify to figure out the file has changed, and do its add,
|
||||
# and commit
|
||||
sleep $WAITTIME
|
||||
|
||||
# Store commit for later comparison
|
||||
lastcommit=$(git --git-dir $dotgittestdir/.git rev-parse master)
|
||||
|
||||
# Make a new change
|
||||
echo "line2" >> file1.txt
|
||||
sleep $WAITTIME
|
||||
|
||||
# Verify that new commit has happened
|
||||
currentcommit=$(git --git-dir $dotgittestdir/.git rev-parse master)
|
||||
[ "$lastcommit" != "$currentcommit" ]
|
||||
|
||||
# Check commit log that the diff is in there
|
||||
run git --git-dir $dotgittestdir/.git log -1 --oneline
|
||||
[[ $output == *"file1.txt"* ]]
|
||||
|
||||
rm -rf $dotgittestdir
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
setup() {
|
||||
# Time to wait for gitwatch to respond
|
||||
WAITTIME=4
|
||||
# Set up directory structure and initialize remote
|
||||
testdir=$(mktemp -d)
|
||||
cd $testdir
|
||||
mkdir remote
|
||||
cd remote
|
||||
git init -q --bare
|
||||
cd ..
|
||||
mkdir local
|
||||
cd local
|
||||
git clone -q ../remote
|
||||
}
|
||||
|
||||
|
||||
teardown() {
|
||||
# Remove testing directories
|
||||
cd /tmp
|
||||
|
||||
# rm -rf $testdir
|
||||
|
||||
# Make sure gitwatch script gets killed if script stopped background
|
||||
# Must kill the entire tree of processes generated
|
||||
pkill -15 -P $GITWATCH_PID
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
# This is a testscript using the bats testing framework:
|
||||
# https://github.com/sstephenson/bats
|
||||
# To run it, at a command prompt:
|
||||
# bats testscript.bats
|
||||
|
||||
load startup-shutdown
|
||||
|
||||
@test "commit only when git status change" {
|
||||
|
||||
# Start up gitwatch and capture its output
|
||||
${BATS_TEST_DIRNAME}/../gitwatch.sh "$testdir/local/remote" > "$testdir/output.txt" 3>&- &
|
||||
GITWATCH_PID=$!
|
||||
|
||||
# Keeps kill message from printing to screen
|
||||
disown
|
||||
|
||||
# Create a file, verify that it hasn't been added yet, then commit
|
||||
cd remote
|
||||
|
||||
# According to inotify documentation, a race condition results if you write
|
||||
# to directory too soon after it has been created; hence, a short wait.
|
||||
sleep 1
|
||||
echo "line1" >> file1.txt
|
||||
|
||||
# Wait a bit for inotify to figure out the file has changed, and do its add,
|
||||
# and commit
|
||||
sleep $WAITTIME
|
||||
|
||||
# Touch the file, but no change
|
||||
touch file1.txt
|
||||
sleep $WAITTIME
|
||||
|
||||
run bash -c "grep \"nothing to commit\" \"$testdir/output.txt\" | wc -l"
|
||||
[[ $output == "0" ]]
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
# This is a testscript using the bats testing framework:
|
||||
# https://github.com/sstephenson/bats
|
||||
# To run it, at a command prompt:
|
||||
# bats testscript.bats
|
||||
|
||||
load startup-shutdown
|
||||
|
||||
@test "syncing correctly" {
|
||||
# Start up gitwatch and see if commit and push happen automatically
|
||||
# after waiting two seconds
|
||||
${BATS_TEST_DIRNAME}/../gitwatch.sh -r origin "$testdir/local/remote" 3>- &
|
||||
GITWATCH_PID=$!
|
||||
|
||||
# Keeps kill message from printing to screen
|
||||
disown
|
||||
|
||||
# Create a file, verify that it hasn't been added yet,
|
||||
# then commit and push
|
||||
cd remote
|
||||
|
||||
# According to inotify documentation, a race condition results if you write
|
||||
# to directory too soon after it has been created; hence, a short wait.
|
||||
sleep 1
|
||||
echo "line1" >> file1.txt
|
||||
|
||||
# Wait a bit for inotify to figure out the file has changed, and do its add,
|
||||
# commit, and push.
|
||||
sleep $WAITTIME
|
||||
|
||||
# Verify that push happened
|
||||
currentcommit=$(git rev-parse master)
|
||||
remotecommit=$(git rev-parse origin/master)
|
||||
[ "$currentcommit" = "$remotecommit" ]
|
||||
|
||||
# Try making subdirectory with file
|
||||
lastcommit=$(git rev-parse master)
|
||||
mkdir subdir
|
||||
cd subdir
|
||||
echo "line2" >> file2.txt
|
||||
|
||||
sleep $WAITTIME
|
||||
|
||||
# Verify that new commit has happened
|
||||
currentcommit=$(git rev-parse master)
|
||||
[ "$lastcommit" != "$currentcommit" ]
|
||||
|
||||
# Verify that push happened
|
||||
currentcommit=$(git rev-parse master)
|
||||
remotecommit=$(git rev-parse origin/master)
|
||||
[ "$currentcommit" = "$remotecommit" ]
|
||||
|
||||
|
||||
# Try removing file to see if can work
|
||||
rm file2.txt
|
||||
sleep $WAITTIME
|
||||
|
||||
# Verify that new commit has happened
|
||||
currentcommit=$(git rev-parse master)
|
||||
[ "$lastcommit" != "$currentcommit" ]
|
||||
|
||||
# Verify that push happened
|
||||
currentcommit=$(git rev-parse master)
|
||||
remotecommit=$(git rev-parse origin/master)
|
||||
[ "$currentcommit" = "$remotecommit" ]
|
||||
|
||||
# Remove testing directories
|
||||
cd /tmp
|
||||
rm -rf $testdir
|
||||
}
|
||||
|
@ -1,154 +0,0 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
# This is a testscript using the bats testing framework:
|
||||
# https://github.com/sstephenson/bats
|
||||
# To run it, at a command prompt:
|
||||
# bats testscript.bats
|
||||
|
||||
setup() {
|
||||
# Set up directory structure and initialize remote
|
||||
testdir=$(mktemp -d)
|
||||
cd $testdir
|
||||
mkdir remote
|
||||
cd remote
|
||||
git init -q --bare
|
||||
cd ..
|
||||
mkdir local
|
||||
cd local
|
||||
git clone -q ../remote
|
||||
}
|
||||
|
||||
@test "syncing correctly" {
|
||||
# Start up gitwatch and see if commit and push happen automatically
|
||||
# after waiting two seconds
|
||||
${BATS_TEST_DIRNAME}/gitwatch.sh -r origin "$testdir/local/remote" 3>- &
|
||||
GITWATCH_PID=$!
|
||||
|
||||
# Keeps kill message from printing to screen
|
||||
disown
|
||||
|
||||
# Create a file, verify that it hasn't been added yet,
|
||||
# then commit and push
|
||||
cd remote
|
||||
|
||||
# According to inotify documentation, a race condition results if you write
|
||||
# to directory too soon after it has been created; hence, a short wait.
|
||||
sleep 1
|
||||
echo "line1" >> file1.txt
|
||||
|
||||
# Wait a bit for inotify to figure out the file has changed, and do its add,
|
||||
# commit, and push.
|
||||
sleep 5
|
||||
|
||||
# Verify that push happened
|
||||
currentcommit=$(git rev-parse master)
|
||||
remotecommit=$(git rev-parse origin/master)
|
||||
[ "$currentcommit" = "$remotecommit" ]
|
||||
|
||||
# Try making subdirectory with file
|
||||
lastcommit=$(git rev-parse master)
|
||||
mkdir subdir
|
||||
cd subdir
|
||||
echo "line2" >> file2.txt
|
||||
|
||||
sleep 5
|
||||
|
||||
# Verify that new commit has happened
|
||||
currentcommit=$(git rev-parse master)
|
||||
[ "$lastcommit" != "$currentcommit" ]
|
||||
|
||||
# Verify that push happened
|
||||
currentcommit=$(git rev-parse master)
|
||||
remotecommit=$(git rev-parse origin/master)
|
||||
[ "$currentcommit" = "$remotecommit" ]
|
||||
|
||||
|
||||
# Try removing file to see if can work
|
||||
rm file2.txt
|
||||
sleep 5
|
||||
|
||||
# Verify that new commit has happened
|
||||
currentcommit=$(git rev-parse master)
|
||||
[ "$lastcommit" != "$currentcommit" ]
|
||||
|
||||
# Verify that push happened
|
||||
currentcommit=$(git rev-parse master)
|
||||
remotecommit=$(git rev-parse origin/master)
|
||||
[ "$currentcommit" = "$remotecommit" ]
|
||||
|
||||
# Remove testing directories
|
||||
cd /tmp
|
||||
rm -rf $testdir
|
||||
}
|
||||
|
||||
|
||||
@test "commit log messages working" {
|
||||
# Start up gitwatch with logging, see if works
|
||||
${BATS_TEST_DIRNAME}/gitwatch.sh -l 10 "$testdir/local/remote" 3>&- &
|
||||
GITWATCH_PID=$!
|
||||
|
||||
# Keeps kill message from printing to screen
|
||||
disown
|
||||
|
||||
# Create a file, verify that it hasn't been added yet, then commit
|
||||
cd remote
|
||||
|
||||
# According to inotify documentation, a race condition results if you write
|
||||
# to directory too soon after it has been created; hence, a short wait.
|
||||
sleep 1
|
||||
echo "line1" >> file1.txt
|
||||
|
||||
# Wait a bit for inotify to figure out the file has changed, and do its add,
|
||||
# and commit
|
||||
sleep 5
|
||||
|
||||
# Make a new change
|
||||
echo "line2" >> file1.txt
|
||||
sleep 5
|
||||
|
||||
# Check commit log that the diff is in there
|
||||
run git log -1 --oneline
|
||||
[[ $output == *"file1.txt"* ]]
|
||||
}
|
||||
|
||||
@test "commit only when git status change" {
|
||||
|
||||
# Start up gitwatch and capture its output
|
||||
${BATS_TEST_DIRNAME}/gitwatch.sh "$testdir/local/remote" > "$testdir/output.txt" 3>&- &
|
||||
GITWATCH_PID=$!
|
||||
|
||||
# Keeps kill message from printing to screen
|
||||
disown
|
||||
|
||||
# Create a file, verify that it hasn't been added yet, then commit
|
||||
cd remote
|
||||
|
||||
# According to inotify documentation, a race condition results if you write
|
||||
# to directory too soon after it has been created; hence, a short wait.
|
||||
sleep 1
|
||||
echo "line1" >> file1.txt
|
||||
|
||||
# Wait a bit for inotify to figure out the file has changed, and do its add,
|
||||
# and commit
|
||||
sleep 5
|
||||
|
||||
# Touch the file, but no change
|
||||
touch file1.txt
|
||||
sleep 5
|
||||
|
||||
run bash -c "grep \"nothing to commit\" \"$testdir/output.txt\" | wc -l"
|
||||
[[ $output == "0" ]]
|
||||
|
||||
}
|
||||
|
||||
|
||||
teardown() {
|
||||
# Remove testing directories
|
||||
cd /tmp
|
||||
|
||||
rm -rf $testdir
|
||||
|
||||
# Make sure gitwatch script gets killed if script stopped background
|
||||
# Must kill the entire tree of processes generated
|
||||
pkill -15 -P $GITWATCH_PID
|
||||
}
|
Loading…
Reference in New Issue