本文整理汇总了Golang中github.com/attic-labs/noms/go/chunks.NewChunk函数的典型用法代码示例。如果您正苦于以下问题:Golang NewChunk函数的具体用法?Golang NewChunk怎么用?Golang NewChunk使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewChunk函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestHandlePostRoot
func TestHandlePostRoot(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
input1, input2 := "abc", "def"
chnx := []chunks.Chunk{
chunks.NewChunk([]byte(input1)),
chunks.NewChunk([]byte(input2)),
}
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()
w := httptest.NewRecorder()
HandleRootPost(w, &http.Request{URL: u, Method: "POST"}, 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, &http.Request{URL: u, Method: "POST"}, params{}, cs)
assert.Equal(http.StatusOK, w.Code, "Handler error:\n%s", string(w.Body.Bytes()))
}
开发者ID:willhite,项目名称:noms-old,代码行数:28,代码来源:remote_database_handlers_test.go
示例2: TestBuildWriteValueRequest
func TestBuildWriteValueRequest(t *testing.T) {
assert := assert.New(t)
input1, input2 := "abc", "def"
chnx := []chunks.Chunk{
chunks.NewChunk([]byte(input1)),
chunks.NewChunk([]byte(input2)),
}
hints := map[hash.Hash]struct{}{
hash.Parse("sha1-0000000000000000000000000000000000000002"): struct{}{},
hash.Parse("sha1-0000000000000000000000000000000000000003"): struct{}{},
}
compressed := buildWriteValueRequest(serializeChunks(chnx, assert), hints)
gr := snappy.NewReader(compressed)
count := 0
for hint := range deserializeHints(gr) {
count++
_, present := hints[hint]
assert.True(present)
}
assert.Equal(len(hints), count)
chunkChan := make(chan *chunks.Chunk, 16)
go chunks.DeserializeToChan(gr, chunkChan)
for c := range chunkChan {
assert.Equal(chnx[0].Hash(), c.Hash())
chnx = chnx[1:]
}
assert.Empty(chnx)
}
开发者ID:willhite,项目名称:noms-old,代码行数:31,代码来源:remote_database_handlers_test.go
示例3: TestHandleGetRefs
func TestHandleGetRefs(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
input1, input2 := "abc", "def"
chnx := []chunks.Chunk{
chunks.NewChunk([]byte(input1)),
chunks.NewChunk([]byte(input2)),
}
err := cs.PutMany(chnx)
assert.NoError(err)
body := strings.NewReader(fmt.Sprintf("ref=%s&ref=%s", chnx[0].Hash(), chnx[1].Hash()))
w := httptest.NewRecorder()
HandleGetRefs(w,
&http.Request{Body: ioutil.NopCloser(body), Method: "POST", Header: http.Header{
"Content-Type": {"application/x-www-form-urlencoded"},
}},
params{},
cs,
)
if assert.Equal(http.StatusOK, w.Code, "Handler error:\n%s", string(w.Body.Bytes())) {
chunkChan := make(chan *chunks.Chunk)
go chunks.DeserializeToChan(w.Body, chunkChan)
for c := range chunkChan {
assert.Equal(chnx[0].Hash(), c.Hash())
chnx = chnx[1:]
}
assert.Empty(chnx)
}
}
开发者ID:willhite,项目名称:noms-old,代码行数:32,代码来源:remote_database_handlers_test.go
示例4: TestHas
func (suite *HTTPBatchStoreSuite) TestHas() {
chnx := []chunks.Chunk{
chunks.NewChunk([]byte("abc")),
chunks.NewChunk([]byte("def")),
}
suite.NoError(suite.cs.PutMany(chnx))
suite.True(suite.store.Has(chnx[0].Hash()))
suite.True(suite.store.Has(chnx[1].Hash()))
}
开发者ID:Richardphp,项目名称:noms,代码行数:9,代码来源:http_batch_store_test.go
示例5: TestGetSame
func (suite *HTTPBatchStoreSuite) TestGetSame() {
chnx := []chunks.Chunk{
chunks.NewChunk([]byte("def")),
chunks.NewChunk([]byte("def")),
}
suite.NoError(suite.cs.PutMany(chnx))
got := suite.store.Get(chnx[0].Hash())
suite.Equal(chnx[0].Hash(), got.Hash())
got = suite.store.Get(chnx[1].Hash())
suite.Equal(chnx[1].Hash(), got.Hash())
}
开发者ID:Richardphp,项目名称:noms,代码行数:11,代码来源:http_batch_store_test.go
示例6: TestHandlePostRoot
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()))
}
开发者ID:Richardphp,项目名称:noms,代码行数:32,代码来源:remote_database_handlers_test.go
示例7: TestUpdateRootWithParams
func (suite *HTTPBatchStoreSuite) TestUpdateRootWithParams() {
u := fmt.Sprintf("http://localhost:9000?access_token=%s&other=19", testAuthToken)
store := newAuthenticatingHTTPBatchStoreForTest(suite, u)
c := chunks.NewChunk([]byte("abc"))
suite.True(store.UpdateRoot(c.Hash(), hash.Hash{}))
suite.Equal(c.Hash(), suite.cs.Root())
}
开发者ID:kalman,项目名称:noms-pre-release,代码行数:7,代码来源:http_batch_store_test.go
示例8: EncodeValue
func EncodeValue(v Value, vw ValueWriter) chunks.Chunk {
w := &binaryNomsWriter{make([]byte, initialBufferSize, initialBufferSize), 0}
enc := newValueEncoder(w, vw)
enc.writeValue(v)
c := chunks.NewChunk(w.data())
if cacher, ok := v.(hashCacher); ok {
assignHash(cacher, c.Hash())
}
return c
}
开发者ID:willhite,项目名称:noms-old,代码行数:12,代码来源:codec.go
示例9: EncodeValue
func EncodeValue(v Value, vw ValueWriter) chunks.Chunk {
w := newBinaryNomsWriter()
enc := newValueEncoder(w, vw)
enc.writeValue(v)
c := chunks.NewChunk(w.data())
if cacher, ok := v.(hashCacher); ok {
assignHash(cacher, c.Hash())
}
return c
}
开发者ID:Richardphp,项目名称:noms,代码行数:12,代码来源:codec.go
示例10: TestHandleHasRefs
func TestHandleHasRefs(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
input1, input2 := "abc", "def"
chnx := []chunks.Chunk{
chunks.NewChunk([]byte(input1)),
chunks.NewChunk([]byte(input2)),
}
err := cs.PutMany(chnx)
assert.NoError(err)
absent := hash.Parse("00000000000000000000000000000002")
body := strings.NewReader(fmt.Sprintf("ref=%s&ref=%s&ref=%s", chnx[0].Hash(), chnx[1].Hash(), absent))
w := httptest.NewRecorder()
HandleHasRefs(
w,
newRequest("POST", "", "", body, http.Header{
"Content-Type": {"application/x-www-form-urlencoded"},
}),
params{},
cs,
)
if assert.Equal(http.StatusOK, w.Code, "Handler error:\n%s", string(w.Body.Bytes())) {
scanner := bufio.NewScanner(w.Body)
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
h := hash.Parse(scanner.Text())
scanner.Scan()
if scanner.Text() == "true" {
assert.Equal(chnx[0].Hash(), h)
chnx = chnx[1:]
} else {
assert.Equal(absent, h)
}
}
assert.Empty(chnx)
}
}
开发者ID:Richardphp,项目名称:noms,代码行数:40,代码来源:remote_database_handlers_test.go
示例11: TestHandleGetRoot
func TestHandleGetRoot(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
c := chunks.NewChunk([]byte("abc"))
cs.Put(c)
assert.True(cs.UpdateRoot(c.Hash(), hash.Hash{}))
w := httptest.NewRecorder()
HandleRootGet(w, &http.Request{Method: "GET"}, params{}, cs)
if assert.Equal(http.StatusOK, w.Code, "Handler error:\n%s", string(w.Body.Bytes())) {
root := hash.Parse(string(w.Body.Bytes()))
assert.Equal(c.Hash(), root)
}
}
开发者ID:willhite,项目名称:noms-old,代码行数:15,代码来源:remote_database_handlers_test.go
示例12: TestCachingChunkHaver
func TestCachingChunkHaver(t *testing.T) {
assert := assert.New(t)
ts := chunks.NewTestStore()
ccs := newCachingChunkHaver(ts)
input := "abc"
c := chunks.NewChunk([]byte(input))
assert.False(ccs.Has(c.Hash()))
assert.Equal(ts.Hases, 1)
assert.False(ccs.Has(c.Hash()))
assert.Equal(ts.Hases, 1)
ts.Put(c)
ccs = newCachingChunkHaver(ts)
assert.True(ccs.Has(c.Hash()))
assert.Equal(ts.Hases, 2)
assert.True(ccs.Has(c.Hash()))
assert.Equal(ts.Hases, 2)
}
开发者ID:willhite,项目名称:noms-old,代码行数:19,代码来源:caching_chunk_haver_test.go
示例13: TestVersionMismatch
func (suite *HTTPBatchStoreSuite) TestVersionMismatch() {
store := newBadVersionHTTPBatchStoreForTest(suite)
c := chunks.NewChunk([]byte("abc"))
suite.Panics(func() { store.UpdateRoot(c.Hash(), hash.Hash{}) })
}
开发者ID:Richardphp,项目名称:noms,代码行数:5,代码来源:http_batch_store_test.go
示例14: TestUpdateRoot
func (suite *HTTPBatchStoreSuite) TestUpdateRoot() {
c := chunks.NewChunk([]byte("abc"))
suite.True(suite.store.UpdateRoot(c.Hash(), hash.Hash{}))
suite.Equal(c.Hash(), suite.cs.Root())
}
开发者ID:kalman,项目名称:noms-pre-release,代码行数:5,代码来源:http_batch_store_test.go
注:本文中的github.com/attic-labs/noms/go/chunks.NewChunk函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论