本文整理汇总了Golang中github.com/attic-labs/noms/go/hash.Parse函数的典型用法代码示例。如果您正苦于以下问题:Golang Parse函数的具体用法?Golang Parse怎么用?Golang Parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
示例2: handleRootPost
func handleRootPost(w http.ResponseWriter, req *http.Request, ps URLParams, cs chunks.ChunkStore) {
d.PanicIfTrue(req.Method != "POST", "Expected post method.")
params := req.URL.Query()
tokens := params["last"]
d.PanicIfTrue(len(tokens) != 1, `Expected "last" query param value`)
last := hash.Parse(tokens[0])
tokens = params["current"]
d.PanicIfTrue(len(tokens) != 1, `Expected "current" query param value`)
current := hash.Parse(tokens[0])
// Ensure that proposed new Root is present in cs
c := cs.Get(current)
d.PanicIfTrue(c.IsEmpty(), "Can't set Root to a non-present Chunk")
// Ensure that proposed new Root is a Map and, if it has anything in it, that it's <String, <RefCommit>>
v := types.DecodeValue(c, nil)
d.PanicIfTrue(v.Type().Kind() != types.MapKind, "Root of a Database must be a Map")
m := v.(types.Map)
if !m.Empty() && !isMapOfStringToRefOfCommit(m) {
panic(d.Wrap(fmt.Errorf("Root of a Database must be a Map<String, Ref<Commit>>, not %s", m.Type().Describe())))
}
if !cs.UpdateRoot(current, last) {
w.WriteHeader(http.StatusConflict)
return
}
}
示例3: TestChunkStoreRoot
func (suite *ChunkStoreTestSuite) TestChunkStoreRoot() {
oldRoot := suite.Store.Root()
suite.True(oldRoot.IsEmpty())
bogusRoot := hash.Parse("8habda5skfek1265pc5d5l1orptn5dr0")
newRoot := hash.Parse("8la6qjbh81v85r6q67lqbfrkmpds14lg")
// Try to update root with bogus oldRoot
result := suite.Store.UpdateRoot(newRoot, bogusRoot)
suite.False(result)
// Now do a valid root update
result = suite.Store.UpdateRoot(newRoot, oldRoot)
suite.True(result)
}
示例4: TestChunkStoreRoot
func (suite *ChunkStoreTestSuite) TestChunkStoreRoot() {
oldRoot := suite.Store.Root()
suite.True(oldRoot.IsEmpty())
bogusRoot := hash.Parse("sha1-81c870618113ba29b6f2b396ea3a69c6f1d626c5") // sha1("Bogus, Dude")
newRoot := hash.Parse("sha1-907d14fb3af2b0d4f18c2d46abe8aedce17367bd") // sha1("Hello, World")
// Try to update root with bogus oldRoot
result := suite.Store.UpdateRoot(newRoot, bogusRoot)
suite.False(result)
// Now do a valid root update
result = suite.Store.UpdateRoot(newRoot, oldRoot)
suite.True(result)
}
示例5: hasRefs
func (bhcs *httpBatchStore) hasRefs(hashes hashSet, batch chunks.ReadBatch) {
// POST http://<host>/hasRefs/. Post body: ref=sha1---&ref=sha1---& Response will be text of lines containing "|ref| |bool|".
u := *bhcs.host
u.Path = httprouter.CleanPath(bhcs.host.Path + constants.HasRefsPath)
req := newRequest("POST", bhcs.auth, u.String(), buildHashesRequest(hashes), http.Header{
"Accept-Encoding": {"x-snappy-framed"},
"Content-Type": {"application/x-www-form-urlencoded"},
})
res, err := bhcs.httpClient.Do(req)
d.Chk.NoError(err)
reader := resBodyReader(res)
defer closeResponse(reader)
d.Chk.True(http.StatusOK == res.StatusCode, "Unexpected response: %s", http.StatusText(res.StatusCode))
scanner := bufio.NewScanner(reader)
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
h := hash.Parse(scanner.Text())
d.Chk.True(scanner.Scan())
if scanner.Text() == "true" {
for _, outstanding := range batch[h] {
// This is a little gross, but OutstandingHas.Satisfy() expects a chunk. It ignores it, though, and just sends 'true' over the channel it's holding.
outstanding.Satisfy(chunks.EmptyChunk)
}
} else {
for _, outstanding := range batch[h] {
outstanding.Fail()
}
}
delete(batch, h)
}
}
示例6: handleRootPost
func handleRootPost(w http.ResponseWriter, req *http.Request, ps URLParams, rt chunks.ChunkStore) {
d.PanicIfTrue(req.Method != "POST", "Expected post method.")
params := req.URL.Query()
tokens := params["last"]
d.PanicIfTrue(len(tokens) != 1, `Expected "last" query param value`)
last := hash.Parse(tokens[0])
tokens = params["current"]
d.PanicIfTrue(len(tokens) != 1, `Expected "current" query param value`)
current := hash.Parse(tokens[0])
if !rt.UpdateRoot(current, last) {
w.WriteHeader(http.StatusConflict)
return
}
}
示例7: TestHintRoundTrip
func TestHintRoundTrip(t *testing.T) {
b := &bytes.Buffer{}
input := map[hash.Hash]struct{}{
hash.Parse("00000000000000000000000000000000"): struct{}{},
hash.Parse("00000000000000000000000000000001"): struct{}{},
hash.Parse("00000000000000000000000000000002"): struct{}{},
hash.Parse("00000000000000000000000000000003"): struct{}{},
}
serializeHints(b, input)
output := deserializeHints(b)
assert.Len(t, output, len(input), "Output has different number of elements than input: %v, %v", output, input)
for h := range output {
_, present := input[h]
assert.True(t, present, "%s is in output but not in input", h)
}
}
示例8: TestChunkStoreVersion
func (suite *ChunkStoreTestSuite) TestChunkStoreVersion() {
oldRoot := suite.Store.Root()
suite.True(oldRoot.IsEmpty())
newRoot := hash.Parse("11111222223333344444555556666677")
suite.True(suite.Store.UpdateRoot(newRoot, oldRoot))
suite.Equal(constants.NomsVersion, suite.Store.Version())
}
示例9: rootByKey
func (l *internalLevelDBStore) rootByKey(key []byte) hash.Hash {
val, err := l.db.Get(key, nil)
if err == errors.ErrNotFound {
return hash.Hash{}
}
d.Chk.NoError(err)
return hash.Parse(string(val))
}
示例10: Root
func (bhcs *httpBatchStore) Root() hash.Hash {
// GET http://<host>/root. Response will be ref of root.
res := bhcs.requestRoot("GET", hash.Hash{}, hash.Hash{})
defer closeResponse(res.Body)
d.Chk.True(http.StatusOK == res.StatusCode, "Unexpected response: %s", http.StatusText(res.StatusCode))
data, err := ioutil.ReadAll(res.Body)
d.Chk.NoError(err)
return hash.Parse(string(data))
}
示例11: TestWriteRef
func TestWriteRef(t *testing.T) {
typ := MakeRefType(NumberType)
r := hash.Parse("0123456789abcdefghijklmnopqrstuv")
assertEncoding(t,
[]interface{}{
uint8(RefKind), uint8(NumberKind), r.String(), uint64(4),
},
constructRef(typ, r, 4),
)
}
示例12: TestWriteCompoundBlob
func TestWriteCompoundBlob(t *testing.T) {
r1 := hash.Parse("00000000000000000000000000000001")
r2 := hash.Parse("00000000000000000000000000000002")
r3 := hash.Parse("00000000000000000000000000000003")
assertEncoding(t,
[]interface{}{
uint8(BlobKind), true,
uint32(3), // len
uint8(RefKind), uint8(BlobKind), r1.String(), uint64(11), uint8(NumberKind), Number(20), uint64(20),
uint8(RefKind), uint8(BlobKind), r2.String(), uint64(22), uint8(NumberKind), Number(40), uint64(40),
uint8(RefKind), uint8(BlobKind), r3.String(), uint64(33), uint8(NumberKind), Number(60), uint64(60),
},
newBlob(newBlobMetaSequence([]metaTuple{
newMetaTuple(constructRef(MakeRefType(BlobType), r1, 11), orderedKeyFromInt(20), 20, nil),
newMetaTuple(constructRef(MakeRefType(BlobType), r2, 22), orderedKeyFromInt(40), 40, nil),
newMetaTuple(constructRef(MakeRefType(BlobType), r3, 33), orderedKeyFromInt(60), 60, nil),
}, NewTestValueStore())),
)
}
示例13: extractHashes
func extractHashes(req *http.Request) hash.HashSlice {
err := req.ParseForm()
d.PanicIfError(err)
hashStrs := req.PostForm["ref"]
d.PanicIfTrue(len(hashStrs) <= 0, "PostForm is empty")
hashes := make(hash.HashSlice, len(hashStrs))
for idx, refStr := range hashStrs {
hashes[idx] = hash.Parse(refStr)
}
return hashes
}
示例14: extractHashes
func extractHashes(req *http.Request) hash.HashSlice {
err := req.ParseForm()
d.Exp.NoError(err)
hashStrs := req.PostForm["ref"]
d.Exp.True(len(hashStrs) > 0)
hashes := make(hash.HashSlice, len(hashStrs))
for idx, refStr := range hashStrs {
hashes[idx] = hash.Parse(refStr)
}
return hashes
}
示例15: TestBuildHashesRequest
func TestBuildHashesRequest(t *testing.T) {
assert := assert.New(t)
hashes := map[hash.Hash]struct{}{
hash.Parse("sha1-0000000000000000000000000000000000000002"): struct{}{},
hash.Parse("sha1-0000000000000000000000000000000000000003"): struct{}{},
}
r := buildHashesRequest(hashes)
b, err := ioutil.ReadAll(r)
assert.NoError(err)
urlValues, err := url.ParseQuery(string(b))
assert.NoError(err)
assert.NotEmpty(urlValues)
queryRefs := urlValues["ref"]
assert.Len(queryRefs, len(hashes))
for _, r := range queryRefs {
_, present := hashes[hash.Parse(r)]
assert.True(present, "Query contains %s, which is not in initial refs", r)
}
}