@@ -82,6 +82,41 @@ public void pinTest() {
8282 }
8383 }
8484
85+ @ org .junit .Test
86+ public void objectPatch () {
87+ try {
88+ MerkleNode obj = ipfs .object ._new (Optional .empty ());
89+ Multihash base = obj .hash ;
90+ // link tests
91+ String linkName = "alink" ;
92+ MerkleNode addLink = ipfs .object .patch (base , "add-link" , Optional .empty (), Optional .of (linkName ), Optional .of (base ));
93+ MerkleNode withLink = ipfs .object .get (addLink .hash );
94+ if (withLink .links .size () != 1 || !withLink .links .get (0 ).hash .equals (base ) || !withLink .links .get (0 ).name .get ().equals (linkName ))
95+ throw new RuntimeException ("Added link not correct!" );
96+ MerkleNode rmLink = ipfs .object .patch (addLink .hash , "rm-link" , Optional .empty (), Optional .of (linkName ), Optional .empty ());
97+ if (!rmLink .hash .equals (base ))
98+ throw new RuntimeException ("Adding not inverse of removing link!" );
99+
100+ // data tests
101+ byte [] data = "somerandomdata" .getBytes ();
102+ MerkleNode patched = ipfs .object .patch (base , "set-data" , Optional .of (data ), Optional .empty (), Optional .empty ());
103+ MerkleNode patchedResult = ipfs .object .get (patched .hash );
104+ if (!Arrays .equals (patchedResult .data .get (), data ))
105+ throw new RuntimeException ("object.patch: returned data != stored data!" );
106+
107+ MerkleNode twicePatched = ipfs .object .patch (patched .hash , "append-data" , Optional .of (data ), Optional .empty (), Optional .empty ());
108+ MerkleNode twicePatchedResult = ipfs .object .get (twicePatched .hash );
109+ byte [] twice = new byte [2 *data .length ];
110+ for (int i =0 ; i < 2 ; i ++)
111+ System .arraycopy (data , 0 , twice , i *data .length , data .length );
112+ if (!Arrays .equals (twicePatchedResult .data .get (), twice ))
113+ throw new RuntimeException ("object.patch: returned data after append != stored data!" );
114+
115+ } catch (IOException e ) {
116+ throw new RuntimeException (e );
117+ }
118+ }
119+
85120 @ org .junit .Test
86121 public void refsTest () {
87122 try {
0 commit comments