master
sh 168 lines 5.15 KB
Raw
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2016 Jeromy Johnson
4 # MIT Licensed; see the LICENSE file in this repository.
5 #
6
7 test_description="Test object diff command"
8
9 . lib/test-lib.sh
10
11 test_init_ipfs
12
13 test_expect_success "create some objects for testing diffs" '
14 mkdir foo &&
15 echo "stuff" > foo/bar &&
16 mkdir foo/baz &&
17 A=$(ipfs add -r -Q foo) &&
18 AR=$(ipfs add --raw-leaves -r -Q foo) &&
19 echo "more things" > foo/cat &&
20 B=$(ipfs add -r -Q foo) &&
21 BR=$(ipfs add --raw-leaves -r -Q foo) &&
22 echo "nested" > foo/baz/dog &&
23 C=$(ipfs add -r -Q foo)
24 CR=$(ipfs add --raw-leaves -r -Q foo)
25 echo "changed" > foo/bar &&
26 D=$(ipfs add -r -Q foo) &&
27 DR=$(ipfs add --raw-leaves -r -Q foo) &&
28 echo "" > single_file &&
29 SINGLE_FILE=$(ipfs add -r -Q single_file) &&
30 SINGLE_FILE_RAW=$(ipfs add --raw-leaves -r -Q single_file) &&
31 mkdir empty_dir
32 EMPTY_DIR=$(ipfs add -r -Q empty_dir)
33 EMPTY_DIR_RAW=$(ipfs add --raw-leaves -r -Q empty_dir)
34 '
35
36 test_expect_success "diff against self is empty" '
37 ipfs object diff $A $A > diff_out
38 '
39
40 test_expect_success "identity diff output looks good" '
41 printf "" > diff_exp &&
42 test_cmp diff_exp diff_out
43 '
44
45 test_expect_success "diff (raw-leaves) against self is empty" '
46 ipfs object diff $AR $AR > diff_raw_out
47 '
48
49 test_expect_success "identity diff (raw-leaves) output looks good" '
50 printf "" > diff_raw_exp &&
51 test_cmp diff_raw_exp diff_raw_out
52 '
53
54 test_expect_success "diff against self (single file) is empty" '
55 ipfs object diff $SINGLE_FILE $SINGLE_FILE > diff_out &&
56 printf "" > diff_exp &&
57 test_cmp diff_exp diff_out
58 '
59
60 test_expect_success "diff (raw-leaves) against self (single file) is empty" '
61 ipfs object diff $SINGLE_FILE_RAW $SINGLE_FILE_RAW > diff_raw_out &&
62 printf "" > diff_raw_exp &&
63 test_cmp diff_raw_exp diff_raw_out
64 '
65
66 test_expect_success "diff against self (empty dir) is empty" '
67 ipfs object diff $EMPTY_DIR $EMPTY_DIR > diff_out &&
68 printf "" > diff_exp &&
69 test_cmp diff_exp diff_out
70 '
71
72 test_expect_success "diff (raw-leaves) against self (empty dir) is empty" '
73 ipfs object diff $EMPTY_DIR_RAW $EMPTY_DIR_RAW > diff_raw_out &&
74 printf "" > diff_raw_exp &&
75 test_cmp diff_raw_exp diff_raw_out
76 '
77
78 test_expect_success "diff added link works" '
79 ipfs object diff $A $B > diff_out
80 '
81
82 test_expect_success "diff added link looks right" '
83 echo + QmUSvcqzhdfYM1KLDbM76eLPdS9ANFtkJvFuPYeZt73d7A \"cat\" > diff_exp &&
84 test_cmp diff_exp diff_out
85 '
86
87 test_expect_success "diff (raw-leaves) added link works" '
88 ipfs object diff $AR $BR > diff_raw_out
89 '
90
91 test_expect_success "diff (raw-leaves) added link looks right" '
92 echo + bafkreig43bpnc6sjo6izaiqzzq5esapazosa3f3wt6jsflwiu3x7ydhq2u \"cat\" > diff_raw_exp &&
93 test_cmp diff_raw_exp diff_raw_out
94 '
95
96 test_expect_success "verbose diff added link works" '
97 ipfs object diff -v $A $B > diff_out
98 '
99
100 test_expect_success "verbose diff added link looks right" '
101 echo Added new link \"cat\" pointing to QmUSvcqzhdfYM1KLDbM76eLPdS9ANFtkJvFuPYeZt73d7A. > diff_exp &&
102 test_cmp diff_exp diff_out
103 '
104
105 test_expect_success "verbose diff (raw-leaves) added link works" '
106 ipfs object diff -v $AR $BR > diff_raw_out
107 '
108
109 test_expect_success "verbose diff (raw-leaves) added link looks right" '
110 echo Added new link \"cat\" pointing to bafkreig43bpnc6sjo6izaiqzzq5esapazosa3f3wt6jsflwiu3x7ydhq2u. > diff_raw_exp &&
111 test_cmp diff_raw_exp diff_raw_out
112 '
113
114 test_expect_success "diff removed link works" '
115 ipfs object diff -v $B $A > diff_out
116 '
117
118 test_expect_success "diff removed link looks right" '
119 echo Removed link \"cat\" \(was QmUSvcqzhdfYM1KLDbM76eLPdS9ANFtkJvFuPYeZt73d7A\). > diff_exp &&
120 test_cmp diff_exp diff_out
121 '
122
123 test_expect_success "diff (raw-leaves) removed link works" '
124 ipfs object diff -v $BR $AR > diff_raw_out
125 '
126
127 test_expect_success "diff (raw-leaves) removed link looks right" '
128 echo Removed link \"cat\" \(was bafkreig43bpnc6sjo6izaiqzzq5esapazosa3f3wt6jsflwiu3x7ydhq2u\). > diff_raw_exp &&
129 test_cmp diff_raw_exp diff_raw_out
130 '
131
132 test_expect_success "diff nested add works" '
133 ipfs object diff -v $B $C > diff_out
134 '
135
136 test_expect_success "diff looks right" '
137 echo Added new link \"baz/dog\" pointing to QmdNJQUTZuDpsUcec7YDuCfRfvw1w4J13DCm7YcU4VMZdS. > diff_exp &&
138 test_cmp diff_exp diff_out
139 '
140
141 test_expect_success "diff (raw-leaves) nested add works" '
142 ipfs object diff -v $BR $CR > diff_raw_out
143 '
144
145 test_expect_success "diff (raw-leaves) looks right" '
146 echo Added new link \"baz/dog\" pointing to bafkreibxbkgajofglo2esqtv53bcp4nwstnqjr3nu2ylrlui5unldf4qum. > diff_raw_exp &&
147 test_cmp diff_raw_exp diff_raw_out
148 '
149
150 test_expect_success "diff changed link works" '
151 ipfs object diff -v $C $D > diff_out
152 '
153
154 test_expect_success "diff looks right" '
155 echo Changed \"bar\" from QmNgd5cz2jNftnAHBhcRUGdtiaMzb5Rhjqd4etondHHST8 to QmRfFVsjSXkhFxrfWnLpMae2M4GBVsry6VAuYYcji5MiZb. > diff_exp &&
156 test_cmp diff_exp diff_out
157 '
158
159 test_expect_success "diff (raw-leaves) changed link works" '
160 ipfs object diff -v $CR $DR > diff_raw_out
161 '
162
163 test_expect_success "diff(raw-leaves) looks right" '
164 echo Changed \"bar\" from bafkreidfn2oemjv5ns2fnc4ukgbjwt6bq5gdd4ciz4mpnehqi2dvwxfbde to bafkreid7rmo7yrtlmje7a3f6kxerotpsk6hhovg2pe755use55olukry6e. > diff_raw_exp &&
165 test_cmp diff_raw_exp diff_raw_out
166 '
167
168 test_done