func TestHandlePostRoot(t *testing.T) { assert := assert.New(t) cs := chunks.NewTestStore() vs := types.NewValueStore(types.NewBatchStoreAdaptor(cs)) commit := NewCommit(types.String("head"), types.NewSet(), types.NewStruct("Meta", types.StructData{})) newHead := types.NewMap(types.String("dataset1"), vs.WriteValue(commit)) chnx := []chunks.Chunk{ chunks.NewChunk([]byte("abc")), types.EncodeValue(newHead, nil), } err := cs.PutMany(chnx) assert.NoError(err) // First attempt should fail, as 'last' won't match. u := &url.URL{} queryParams := url.Values{} queryParams.Add("last", chnx[0].Hash().String()) queryParams.Add("current", chnx[1].Hash().String()) u.RawQuery = queryParams.Encode() url := u.String() w := httptest.NewRecorder() HandleRootPost(w, newRequest("POST", "", url, nil, nil), params{}, cs) assert.Equal(http.StatusConflict, w.Code, "Handler error:\n%s", string(w.Body.Bytes())) // Now, update the root manually to 'last' and try again. assert.True(cs.UpdateRoot(chnx[0].Hash(), hash.Hash{})) w = httptest.NewRecorder() HandleRootPost(w, newRequest("POST", "", url, nil, nil), params{}, cs) assert.Equal(http.StatusOK, w.Code, "Handler error:\n%s", string(w.Body.Bytes())) }
func newLocalDatabase(cs chunks.ChunkStore) *LocalDatabase { bs := types.NewBatchStoreAdaptor(cs) return &LocalDatabase{ newDatabaseCommon(newCachingChunkHaver(cs), types.NewValueStore(bs), bs), cs, } }