@cryptotaxi247 / kubo / commits / 3bf7d5c27

test for pinning semantics

Jeromy committed Mar 18, 2015 at 16:48 UTC 3bf7d5c27e6d3100588271ce93bbfd96fa2a2eff
2 files changed +40 -1
pin/pin_test.go
+38
@@ -152,3 +152,41 @@ func TestPinnerBasic(t *testing.T) {
152 t.Fatal("could not find recursively pinned node")
153 }
154 }
155 +
156 +func TestDuplicateSemantics(t *testing.T) {
157 + dstore := dssync.MutexWrap(ds.NewMapDatastore())
158 + bstore := blockstore.NewBlockstore(dstore)
159 + bserv, err := bs.New(bstore, offline.Exchange(bstore))
160 + if err != nil {
161 + t.Fatal(err)
162 + }
163 +
164 + dserv := mdag.NewDAGService(bserv)
165 +
166 + // TODO does pinner need to share datastore with blockservice?
167 + p := NewPinner(dstore, dserv)
168 +
169 + a, _ := randNode()
170 + _, err = dserv.Add(a)
171 + if err != nil {
172 + t.Fatal(err)
173 + }
174 +
175 + // pin is recursively
176 + err = p.Pin(a, true)
177 + if err != nil {
178 + t.Fatal(err)
179 + }
180 +
181 + // pinning directly should fail
182 + err = p.Pin(a, false)
183 + if err == nil {
184 + t.Fatal("expected direct pin to fail")
185 + }
186 +
187 + // pinning recursively again should succeed
188 + err = p.Pin(a, true)
189 + if err != nil {
190 + t.Fatal(err)
191 + }
192 +}
test/sharness/t0080-repo.sh
+2 -1
@@ -48,6 +48,7 @@ test_expect_success "file no longer pinned" '
48 # we expect the welcome files to show up here
49 echo "$HASH_WELCOME_DOCS" >expected2 &&
50 ipfs refs -r "$HASH_WELCOME_DOCS" >>expected2 &&
51 + echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >> expected2 &&
52 sort expected2 >expected_sorted2 &&
53 ipfs pin ls -type=recursive >actual2 &&
54 sort actual2 >actual_sorted2 &&
@@ -127,7 +128,6 @@ test_expect_success "pin something directly" '
128
129 test_expect_success "'ipfs pin ls -type=direct' is correct" '
130 echo "$DIRECTPIN" >directpinexpected &&
130 - echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >>directpinexpected &&
131 sort directpinexpected >dp_exp_sorted &&
132 ipfs pin ls -type=direct >directpinout &&
133 sort directpinout >dp_out_sorted &&
@@ -137,6 +137,7 @@ test_expect_success "'ipfs pin ls -type=direct' is correct" '
137 test_expect_success "'ipfs pin ls -type=recursive' is correct" '
138 echo "$MBLOCKHASH" >rp_expected &&
139 echo "$HASH_WELCOME_DOCS" >>rp_expected &&
140 + echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >>rp_expected &&
141 ipfs refs -r "$HASH_WELCOME_DOCS" >>rp_expected &&
142 sort rp_expected >rp_exp_sorted &&
143 ipfs pin ls -type=recursive >rp_actual &&