@cryptotaxi247 / kubo / commits / 7cda005a5

test(diff): separate diff test cases

License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>

Overbool committed Sep 18, 2018 at 08:56 UTC 7cda005a5f8bd87f112f23e8d84becd7a3690169
2 files changed +63 -21
dagutils/diff.go
+1 -1
@@ -95,7 +95,7 @@ func ApplyChange(ctx context.Context, ds ipld.DAGService, nd *dag.ProtoNode, cs
95 }
96
97 // Diff returns a set of changes that transform node 'a' into node 'b'.
98 -// It supports two nodes forms: ProtoNode and RawNode. Because we treats
98 +// It supports two nodes forms: ProtoNode and RawNode. Because we treat
99 // the nodes as IPLD nodes as long as possible and only convert them
100 // to ProtoNode when necessary: when we need to remove links, and at that point
101 // (if they have links to remove) we know they are not raw nodes.
test/sharness/t0052-object-diff.sh
+62 -20
@@ -34,92 +34,134 @@ test_expect_success "create some objects for testing diffs" '
34 '
35
36 test_expect_success "diff against self is empty" '
37 - ipfs object diff $A $A > diff_out &&
38 - ipfs object diff $AR $AR > diff_raw_out
37 + ipfs object diff $A $A > diff_out
38 '
39
40 test_expect_success "identity diff output looks good" '
41 printf "" > diff_exp &&
43 - printf "" > diff_raw_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 &&
50 - ipfs object diff $SINGLE_FILE_RAW $SINGLE_FILE_RAW > diff_raw_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 &&
53 - test_cmp diff_exp diff_out &&
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
59 - ipfs object diff $EMPTY_DIR_RAW $EMPTY_DIR_RAW > diff_raw_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 &&
62 - test_cmp diff_exp diff_out &&
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
68 - ipfs object diff $AR $BR > diff_raw_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 + zb2rhmWNFDCdMjJoCZPE5b5NuU38yoRzRmEtfzb4exxk3R8g4 \"cat\" > diff_raw_exp &&
74 - test_cmp diff_exp diff_out &&
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
80 - ipfs object diff -v $AR $BR > diff_raw_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 zb2rhmWNFDCdMjJoCZPE5b5NuU38yoRzRmEtfzb4exxk3R8g4. > diff_raw_exp &&
86 - test_cmp diff_exp diff_out &&
111 test_cmp diff_raw_exp diff_raw_out
112 '
113
114 test_expect_success "diff removed link works" '
91 - ipfs object diff -v $B $A > diff_out &&
92 - ipfs object diff -v $BR $AR > diff_raw_out
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 zb2rhmWNFDCdMjJoCZPE5b5NuU38yoRzRmEtfzb4exxk3R8g4\). > diff_raw_exp &&
98 - test_cmp diff_exp diff_out &&
129 test_cmp diff_raw_exp diff_raw_out
130 '
131
132 test_expect_success "diff nested add works" '
103 - ipfs object diff -v $B $C > diff_out &&
104 - ipfs object diff -v $BR $CR > diff_raw_out
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 zb2rhaM8wjDfi8A22dEqk89raWtViq8pjxvKQu2eaKtWhYKgE. > diff_raw_exp &&
110 - test_cmp diff_exp diff_out &&
147 test_cmp diff_raw_exp diff_raw_out
148 '
149
150 test_expect_success "diff changed link works" '
115 - ipfs object diff -v $C $D > diff_out &&
116 - ipfs object diff -v $CR $DR > diff_raw_out
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 zb2rhdUECGnPgMJNgmghaMKdqqGdpTe9GmEJiPna488ThfLBz to zb2rhfEA1M13SPoeayrsPcKhCezgMQPjguGFLH56G8qQ2qpDn. > diff_raw_exp &&
122 - test_cmp diff_exp diff_out &&
165 test_cmp diff_raw_exp diff_raw_out
166 '
167