summaryrefslogtreecommitdiffstats
path: root/src/test/rgw/test-ceph-diff-sorted.sh
blob: dddf4ae1b18f25d7918d7916b8b6e0f6215d3330 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash

# set -e -x

. "`dirname $0`/test-rgw-common.sh"

temp_prefix="/tmp/`basename $0`-$$"

short=${temp_prefix}-short
short_w_blank=${temp_prefix}-short-w-blank
long=${temp_prefix}-long
unsorted=${temp_prefix}-unsorted
empty=${temp_prefix}-empty
fake=${temp_prefix}-fake

out1=${temp_prefix}-out1
out2=${temp_prefix}-out2

cat >"${short}" <<EOF
bear
fox
hippo
zebra
EOF

cat >"${short_w_blank}" <<EOF
bear
fox
hippo

zebra
EOF

cat >"${long}" <<EOF
badger
cuttlefish
fox
llama
octopus
penguine
seal
squid
whale
yak
zebra
EOF

cat >"${unsorted}" <<EOF
bear
hippo
fox
zebra
EOF

touch $empty

#### testing ####

# test perfect match
ceph-diff-sorted $long $long >"${out1}"
$assert $? -eq 0
$assert $(cat $out1 | wc -l) -eq 0

# test non-match; use /bin/diff to verify
/bin/diff $short $long >"${out2}"
ceph-diff-sorted $short $long >"${out1}"
$assert $? -eq 1
$assert $(cat $out1 | grep '^<' | wc -l) -eq $(cat $out2 | grep '^<' | wc -l)
$assert $(cat $out1 | grep '^>' | wc -l) -eq $(cat $out2 | grep '^>' | wc -l)

/bin/diff $long $short >"${out2}"
ceph-diff-sorted $long $short >"${out1}"
$assert $? -eq 1
$assert $(cat $out1 | grep '^<' | wc -l) -eq $(cat $out2 | grep '^<' | wc -l)
$assert $(cat $out1 | grep '^>' | wc -l) -eq $(cat $out2 | grep '^>' | wc -l)

# test w blank line
ceph-diff-sorted $short $short_w_blank 2>/dev/null
$assert $? -eq 4

ceph-diff-sorted $short_w_blank $short 2>/dev/null
$assert $? -eq 4

# test unsorted input
ceph-diff-sorted $short $unsorted >"${out2}" 2>/dev/null
$assert $? -eq 4

ceph-diff-sorted $unsorted $short >"${out2}" 2>/dev/null
$assert $? -eq 4

# test bad # of args
ceph-diff-sorted 2>/dev/null
$assert $? -eq 2

ceph-diff-sorted $short 2>/dev/null
$assert $? -eq 2

# test bad file path

ceph-diff-sorted $short $fake 2>/dev/null
$assert $? -eq 3

ceph-diff-sorted $fake $short 2>/dev/null
$assert $? -eq 3

#### clean-up ####

/bin/rm -f $short $short_w_blank $long $unsorted $empty $out1 $out2