This commit is contained in:
Colin Marc 2014-10-31 19:18:16 +01:00
Родитель f6f2303527
Коммит e04c25b9bb
4 изменённых файлов: 167 добавлений и 5 удалений

Просмотреть файл

@ -2,11 +2,15 @@ language: go
go:
- 1.2
- 1.3
before_install:
- sudo add-apt-repository ppa:duggan/bats --yes
- sudo apt-get update -qq
- sudo apt-get install -qq bats
install: make get-deps
env:
- HADOOP_DISTRO=cdh
- HADOOP_DISTRO=hdp
- HADOOP_DISTRO=cdh
- HADOOP_DISTRO=hdp
before_script:
- NN_PORT=9000 ./setup_test_env.sh
- export HADOOP_NAMENODE="localhost:9000"
- NN_PORT=9000 ./setup_test_env.sh
- export HADOOP_NAMENODE="localhost:9000"
script: make test

Просмотреть файл

@ -9,8 +9,9 @@ hdfs: get-deps
install: get-deps
$(GOCMD) install ./...
test: get-deps
test: hdfs
$(GOCMD) test ./...
bats ./cmd/hdfs/test/*.bats
get-deps:
$(GOCMD) get code.google.com/p/goprotobuf/proto

84
cmd/hdfs/test/helper.bash Normal file
Просмотреть файл

@ -0,0 +1,84 @@
#!/bin/bash
if [ ! -d "$HADOOP_HOME" ]; then
flunk "HADOOP_HOME not set"
fi
export HADOOP_FS="$HADOOP_HOME/bin/hadoop fs -Ddfs.block.size=1048576"
export HDFS="$BATS_TEST_DIRNAME/../../../hdfs"
# stolen from https://github.com/sstephenson/rbenv/blob/master/test/test_helper.bash
flunk() {
if [ "$#" -eq 0 ]; then cat -
else echo "$@"
fi
return 1
}
assert_success() {
if [ "$status" -ne 0 ]; then
flunk "command failed with exit status $status"
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi
}
assert_failure() {
if [ "$status" -eq 0 ]; then
flunk "expected failed exit status"
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi
}
assert_equal() {
if [ "$1" != "$2" ]; then
{ echo "expected: $1"
echo "actual: $2"
} | flunk
fi
}
assert_output() {
local expected
if [ $# -eq 0 ]; then expected="$(cat -)"
else expected="$1"
fi
assert_equal "$expected" "$output"
}
assert_line() {
if [ "$1" -ge 0 ] 2>/dev/null; then
assert_equal "$2" "${lines[$1]}"
else
local line
for line in "${lines[@]}"; do
if [ "$line" = "$1" ]; then return 0; fi
done
flunk "expected line \`$1'"
fi
}
refute_line() {
if [ "$1" -ge 0 ] 2>/dev/null; then
local num_lines="${#lines[@]}"
if [ "$1" -lt "$num_lines" ]; then
flunk "output has $num_lines lines"
fi
else
local line
for line in "${lines[@]}"; do
if [ "$line" = "$1" ]; then
flunk "expected to not find line \`$line'"
fi
done
fi
}
assert() {
if ! "$@"; then
flunk "failed: $@"
fi
}

73
cmd/hdfs/test/ls.bats Normal file
Просмотреть файл

@ -0,0 +1,73 @@
#!/usr/bin/env bats
load helper
setup() {
$HDFS mkdir -p /_test_cmd/ls/dir1
$HDFS mkdir -p /_test_cmd/ls/dir2
$HDFS mkdir -p /_test_cmd/ls/dir3
$HDFS touch /_test_cmd/ls/dir1/a
$HDFS touch /_test_cmd/ls/dir1/b
$HDFS touch /_test_cmd/ls/dir1/c
$HDFS touch /_test_cmd/ls/dir2/d
}
@test "simple ls" {
run $HDFS ls /_test_cmd/ls/dir1
assert_success
assert_output <<OUT
a
b
c
OUT
}
@test "ls nonexistent" {
run $HDFS ls /_test_cmd/nonexistent
assert_failure
assert_output <<OUT
stat /_test_cmd/nonexistent: file does not exist
OUT
}
@test "ls with glob" {
run $HDFS ls /_test_cmd/ls/dir*
assert_success
assert_output <<OUT
/_test_cmd/ls/dir1/:
a
b
c
/_test_cmd/ls/dir2/:
d
/_test_cmd/ls/dir3/:
OUT
}
@test "ls with two globs, one of which is qualified" {
run $HDFS ls /_test_cmd/ls/dir*/*
assert_success
assert_output <<OUT
a
b
c
d
OUT
}
@test "ls with two globs" {
run $HDFS ls /_test_cmd/ls/*/*
assert_success
assert_output <<OUT
a
b
c
d
OUT
}
teardown() {
$HDFS rm -r /_test_cmd/ls
}