]> git.scottworley.com Git - pinch/commitdiff
More tests: pin-twice, reject-nonancestor
authorScott Worley <scottworley@scottworley.com>
Fri, 22 May 2020 23:57:54 +0000 (16:57 -0700)
committerScott Worley <scottworley@scottworley.com>
Fri, 22 May 2020 23:57:54 +0000 (16:57 -0700)
tests/pin-twice.sh [new file with mode: 0755]
tests/reject-nonancestor.sh [new file with mode: 0755]

diff --git a/tests/pin-twice.sh b/tests/pin-twice.sh
new file mode 100755 (executable)
index 0000000..b17af2c
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+set -e
+
+repo_dir="`mktemp -d`"
+repo="$repo_dir/repo"
+git init "$repo"
+(
+  cd "$repo"
+  echo Contents > test-file
+  git add test-file
+  git commit -m 'Commit message'
+)
+
+conf="`mktemp`"
+cat > "$conf" <<EOF
+[foo]
+git_repo = file://$repo
+git_ref = master
+EOF
+
+python3 ./pinch.py pin "$conf"
+
+(
+  cd "$repo"
+  echo Other contents > other-file
+  git add other-file
+  git commit -m 'Second commit message'
+)
+
+python3 ./pinch.py pin "$conf"
+
+actual_env_command=`python3 ./pinch.py update --dry-run "$conf"`
+
+rm -rf "$repo_dir" "$conf"
+
+expected_env_command_RE='^nix-env --profile /nix/var/nix/profiles/per-user/[^/]+/channels --show-trace --file '\''<nix/unpack-channel.nix>'\'' --install --from-expression '\''f: f \{ name = "(repo-[0-9]{10}-[0-9a-f]{11})"; channelName = "foo"; src = builtins.storePath "/nix/store/.{32}-\1.tar.xz"; \}'\''$'
+
+if echo "$actual_env_command" | egrep "$expected_env_command_RE" > /dev/null;then
+  echo PASS
+else
+  echo "Output:   $actual_env_command"
+  echo "does not match RE: $expected_env_command_RE"
+  exit 1
+fi
diff --git a/tests/reject-nonancestor.sh b/tests/reject-nonancestor.sh
new file mode 100755 (executable)
index 0000000..b8e944a
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+set -e
+
+repo_dir="`mktemp -d`"
+repo="$repo_dir/repo"
+git init "$repo"
+(
+  cd "$repo"
+  echo Contents > test-file
+  git add test-file
+  git commit -m 'Commit message'
+)
+
+conf="`mktemp`"
+cat > "$conf" <<EOF
+[foo]
+git_repo = file://$repo
+git_ref = master
+EOF
+
+python3 ./pinch.py pin "$conf"
+
+(
+  cd "$repo"
+  echo Other contents > other-file
+  git add other-file
+  git commit --amend -m 'Amended commit message'
+)
+
+if python3 ./pinch.py pin "$conf";then
+  echo "FAIL: non-ancestor commit should be rejected"
+  exit 1
+else
+  echo PASS
+fi
+
+rm -rf "$repo_dir" "$conf"