Skip to content

Commit 5914d7d

Browse files
committed
implement the full push/clone workflow test
1 parent 856779f commit 5914d7d

File tree

4 files changed

+207
-27
lines changed

4 files changed

+207
-27
lines changed

test/cmd/git-credential-lfstest.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
"regexp"
8+
"strings"
9+
)
10+
11+
var (
12+
commands = map[string]func(){
13+
"get": fill,
14+
"store": noop,
15+
"erase": noop,
16+
}
17+
18+
delim = '\n'
19+
20+
hostRE = regexp.MustCompile(`\A127.0.0.1:\d+\z`)
21+
)
22+
23+
func main() {
24+
if argsize := len(os.Args); argsize != 2 {
25+
fmt.Fprintf(os.Stderr, "wrong number of args: %d\n", argsize)
26+
os.Exit(1)
27+
}
28+
29+
arg := os.Args[1]
30+
cmd := commands[arg]
31+
32+
if cmd == nil {
33+
fmt.Fprintf(os.Stderr, "bad cmd: %s\n", arg)
34+
os.Exit(1)
35+
}
36+
37+
cmd()
38+
}
39+
40+
func fill() {
41+
scanner := bufio.NewScanner(os.Stdin)
42+
creds := map[string]string{}
43+
for scanner.Scan() {
44+
line := scanner.Text()
45+
parts := strings.SplitN(line, "=", 2)
46+
if len(parts) != 2 {
47+
fmt.Fprintf(os.Stderr, "bad line: %s\n", line)
48+
os.Exit(1)
49+
}
50+
51+
creds[parts[0]] = strings.TrimSpace(parts[1])
52+
}
53+
54+
if err := scanner.Err(); err != nil {
55+
fmt.Fprintf(os.Stderr, "reading standard input: %v", err)
56+
os.Exit(1)
57+
}
58+
59+
if _, ok := creds["username"]; !ok {
60+
creds["username"] = "user"
61+
}
62+
63+
if _, ok := creds["password"]; !ok {
64+
creds["password"] = "pass"
65+
}
66+
67+
if host := creds["host"]; !hostRE.MatchString(host) {
68+
fmt.Fprintf(os.Stderr, "invalid host: %s, should be '127.0.0.1:\\d+'\n", host)
69+
os.Exit(1)
70+
}
71+
72+
for key, value := range creds {
73+
fmt.Fprintf(os.Stdout, "%s=%s\n", key, value)
74+
}
75+
}
76+
77+
func noop() {}

test/test-happy-path.sh

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,49 @@ begin_test "happy path"
88
set -e
99

1010
reponame="$(basename "$0")"
11-
setup_remote_repo $reponame
11+
setup_remote_repo "$reponame"
1212

13-
echo "set up 'local' test directory with git clone"
14-
git clone $GITSERVER/$reponame repo
15-
cd repo
16-
17-
echo "start the test"
13+
clone_repo "$reponame" repo
1814

1915
out=$($GITLFS track "*.dat" 2>&1)
20-
echo $out | grep "dat"
16+
echo "$out" | grep "Tracking \*.dat"
17+
18+
contents=$(printf "a")
19+
contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ")
20+
21+
printf "$contents" > a.dat
22+
git add a.dat
23+
git add .gitattributes
24+
out=$(git commit -m "add a.dat" 2>&1)
25+
echo "$out" | grep "master (root-commit)"
26+
echo "$out" | grep "2 files changed"
27+
echo "$out" | grep "create mode 100644 a.dat"
28+
echo "$out" | grep "create mode 100644 .gitattributes"
29+
30+
out=$(cat a.dat)
31+
if [ "$out" != "a" ]; then
32+
exit 1
33+
fi
34+
35+
assert_pointer "master" "a.dat" "$contents_oid" 1
36+
37+
refute_server_object "$contents_oid"
38+
39+
out=$(git push origin master 2>&1)
40+
echo "$out" | grep "(1 of 1 files) 1 B / 1 B 100.00 %"
41+
echo "$out" | grep "master -> master"
42+
43+
assert_server_object "$contents_oid" "$contents"
44+
45+
out=$(clone_repo "$reponame" clone)
46+
echo "$out" | grep "Cloning into 'clone'"
47+
echo "$out" | grep "Downloading a.dat (1 B)"
48+
49+
out=$(cat a.dat)
50+
if [ "$out" != "a" ]; then
51+
exit 1
52+
fi
53+
54+
assert_pointer "master" "a.dat" "$contents_oid" 1
2155
)
2256
end_test

test/testhelpers.sh

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
11
#!/bin/sh
22

3-
shutdown() {
4-
if [ "$SHUTDOWN_LFS" != "no" ]; then
5-
curl "$GITSERVER/shutdown"
6-
rm -rf "$LFS_URL_FILE"
3+
assert_pointer() {
4+
local ref=$1
5+
local path=$2
6+
local oid=$3
7+
local size=$4
8+
9+
gitblob=$(git ls-tree -l $ref | grep $path | cut -f 3 -d " ")
10+
actual=$(git cat-file -p $gitblob)
11+
expected=$(pointer $oid $size)
12+
13+
if [ "$expected" != "$actual" ]; then
14+
exit 1
715
fi
816
}
917

18+
# no-op. check that the object does not exist in the git lfs server
19+
refute_server_object() {
20+
echo "refute server object: no-op"
21+
}
22+
23+
# no-op. check that the object does exist in the git lfs server
24+
assert_server_object() {
25+
echo "assert server object: no-op"
26+
}
27+
28+
pointer() {
29+
local oid=$1
30+
local size=$2
31+
printf "version https://git-lfs.github.com/spec/v1
32+
oid sha256:%s
33+
size %s
34+
" "$oid" "$size"
35+
}
36+
1037
wait_for_file() {
1138
local filename=$1
1239
n=0
@@ -24,25 +51,62 @@ wait_for_file() {
2451

2552
setup_remote_repo() {
2653
local reponame=$1
27-
echo "set up 'remote' git repository: $reponame"
54+
echo "set up remote git repository: $reponame"
2855
repodir="$REMOTEDIR/$reponame.git"
29-
mkdir -p $repodir
30-
cd $repodir
56+
mkdir -p "$repodir"
57+
cd "$repodir"
3158
git init --bare
3259
git config http.receivepack true
3360
git config receive.denyCurrentBranch ignore
3461

35-
cd $TRASHDIR
62+
# dump a simple git config file so clones use this test's Git LFS command
63+
# and the custom credential helper
64+
printf "[filter \"lfs\"]
65+
required = true
66+
smudge = %s smudge %%f
67+
clean = %s clean %%f
68+
[credential]
69+
helper = %s
70+
[remote \"origin\"]
71+
url = %s/%s
72+
fetch = +refs/heads/*:refs/remotes/origin/*
73+
" "$GITLFS" "$GITLFS" lfstest "$GITSERVER" "$reponame" > "$LFS_CONFIG-$reponame"
74+
}
75+
76+
clone_repo() {
77+
cd "$TRASHDIR"
78+
79+
local reponame=$1
80+
local dir=$2
81+
echo "clone local git repository $reponame to $dir"
82+
out=$(GIT_CONFIG="$LFS_CONFIG-$reponame" git clone "$GITSERVER/$reponame" "$dir" 2>&1)
83+
cd "$dir"
84+
85+
git config credential.helper lfstest
86+
echo "$out"
3687
}
3788

3889
setup() {
39-
cd $ROOTDIR
90+
cd "$ROOTDIR"
91+
92+
rm -rf "test/remote"
93+
mkdir "test/remote"
94+
4095
echo "compile git-lfs for $0"
4196
script/bootstrap
4297

43-
rm -rf "test/remote"
44-
mkdir -p "test/remote"
98+
for go in test/cmd/*.go; do
99+
go build -o "$BINPATH/$(basename $go .go)" "$go"
100+
done
45101

46-
LFSTEST_URL=$LFS_URL_FILE LFSTEST_DIR=$REMOTEDIR go run "$ROOTDIR/test/cmd/lfstest-gitserver.go" &
47-
wait_for_file $LFS_URL_FILE
102+
echo "LFSTEST_URL=$LFS_URL_FILE LFSTEST_DIR=$REMOTEDIR lfstest-gitserver"
103+
LFSTEST_URL="$LFS_URL_FILE" LFSTEST_DIR="$REMOTEDIR" lfstest-gitserver > "$TRASHDIR/gitserver.log" &
104+
wait_for_file "$LFS_URL_FILE"
105+
}
106+
107+
shutdown() {
108+
if [ "$SHUTDOWN_LFS" != "no" ]; then
109+
curl "$GITSERVER/shutdown"
110+
rm -rf "$LFS_URL_FILE"
111+
fi
48112
}

test/testlib.sh

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
set -e
2323

2424
# Put bin path on PATH
25-
PATH="$(cd $(dirname "$0")/.. && pwd)/bin:$PATH"
25+
ROOTDIR=$(cd $(dirname "$0")/.. && pwd)
26+
BINPATH="$ROOTDIR/bin"
27+
PATH="$BINPATH:$PATH"
2628

2729
# create a temporary work space
2830
TMPDIR="$(cd $(dirname "$0")/.. && pwd)"/tmp
@@ -37,9 +39,13 @@ atexit () {
3739
rm -rf "$TRASHDIR"
3840
shutdown
3941

40-
if [ $failures -gt 0 ]
41-
then exit 1
42-
else exit 0
42+
if [ $failures -gt 0 ]; then
43+
if [ -s "$TRASHDIR/gitserver.log" ]; then
44+
cat "$TRASHDIR/gitserver.log"
45+
fi
46+
exit 1
47+
else
48+
exit 0
4349
fi
4450
}
4551

@@ -49,12 +55,12 @@ mkdir -p "$TRASHDIR"
4955

5056
. "test/testhelpers.sh"
5157

52-
ROOTDIR="`pwd`"
53-
GITLFS="$ROOTDIR/bin/git-lfs"
58+
GITLFS="$BINPATH/git-lfs"
5459
SHUTDOWN_LFS=yes
5560
GITSERVER=undefined
5661
REMOTEDIR="$ROOTDIR/test/remote"
5762
LFS_URL_FILE="$REMOTEDIR/url"
63+
LFS_CONFIG="$REMOTEDIR/config"
5864

5965
# if the file exists, assume another process started it, and will clean it up
6066
# when it's done
@@ -67,7 +73,6 @@ fi
6773
GITSERVER=$(cat "$LFS_URL_FILE")
6874
cd "$TRASHDIR"
6975

70-
7176
# Mark the beginning of a test. A subshell should immediately follow this
7277
# statement.
7378
begin_test () {

0 commit comments

Comments
 (0)