當前位置: 首頁>>代碼示例>>Golang>>正文


Golang blob.MustParse函數代碼示例

本文整理匯總了Golang中camlistore/org/pkg/blob.MustParse函數的典型用法代碼示例。如果您正苦於以下問題:Golang MustParse函數的具體用法?Golang MustParse怎麽用?Golang MustParse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了MustParse函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestHubFiring

func TestHubFiring(t *testing.T) {
	hub := &SimpleBlobHub{}
	ch := make(chan blob.Ref)
	bch := make(chan blob.Ref)
	blob1 := blob.MustParse("sha1-0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")
	blobsame := blob.MustParse("sha1-0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")

	hub.NotifyBlobReceived(blob1) // no-op

	hub.RegisterListener(ch)
	hub.RegisterBlobListener(blob1, bch)

	hub.NotifyBlobReceived(blobsame)

	tmr1 := time.NewTimer(1e9)
	select {
	case <-tmr1.C:
		t.Fatal("timer expired on receiving from ch")
	case got := <-ch:
		if got != blob1 {
			t.Fatalf("got wrong blob")
		}
	}

	select {
	case <-tmr1.C:
		t.Fatal("timer expired on receiving from bch")
	case got := <-bch:
		if got != blob1 {
			t.Fatalf("got wrong blob")
		}
	}
	tmr1.Stop()
}
開發者ID:JayBlaze420,項目名稱:camlistore,代碼行數:34,代碼來源:blobhub_test.go

示例2: TestShareExpiration

func TestShareExpiration(t *testing.T) {
	defer func() { clockNow = time.Now }()
	b, err := BlobFromReader(
		blob.MustParse("sha1-64ffa72fa9bcb2f825e7ed40b9451e5cadca4c2c"),
		strings.NewReader(`{"camliVersion": 1,
  "authType": "haveref",
  "camliSigner": "sha1-f2b0b7da718b97ce8c31591d8ed4645c777f3ef4",
  "camliType": "claim",
  "claimDate": "2013-09-08T23:58:53.656549677Z",
  "claimType": "share",
  "expires": "2013-09-09T23:58:53.65658012Z",
  "target": "sha1-f1d2d2f924e986ac86fdf7b36c94bcdf32beec15",
  "transitive": false
,"camliSig":"wsBcBAABCAAQBQJSLQ89CRApMaZ8JvWr2gAAcuEIABRQolhn+yKksfaBx6oLo18NWvWQ+aYweF+5Gu0TH0Ixur7t1o5HFtFSSfFISyggSZDJSjsxoxaawhWrvCe9dZuU2s/zgRpgUtd2xmBt82tLOn9JidnUavsNGFXbfCwdUBSkzN0vDYLmgXW0VtiybB354uIKfOInZor2j8Mq0p6pkWzK3qq9W0dku7iE96YFaTb4W7eOikqoSC6VpjC1/4MQWOYRHLcPcIEY6xJ8es2sYMMSNXuVaR9nMupz8ZcTygP4jh+lPR1OH61q/FSjpRp7GKt4wZ1PknYjMbnpIzVjiSz0MkYd65bpZwuPOwZh/h2kHW7wvHNQZfWUJHEsOAI==J2ID"}`),
	)
	if err != nil {
		t.Fatal(err)
	}
	s, ok := b.AsShare()
	if !ok {
		t.Fatal("expected share")
	}
	clockNow = func() time.Time { return time.Unix(100, 0) }
	if s.IsExpired() {
		t.Error("expected not expired")
	}
	clockNow = func() time.Time { return time.Unix(1378687181+2*86400, 0) }
	if !s.IsExpired() {
		t.Error("expected expired")
	}

	// And without an expiration time:
	b, err = BlobFromReader(
		blob.MustParse("sha1-931875ec6b8d917b7aae9f672f4f92de1ffaeeb1"),
		strings.NewReader(`{"camliVersion": 1,
  "authType": "haveref",
  "camliSigner": "sha1-f2b0b7da718b97ce8c31591d8ed4645c777f3ef4",
  "camliType": "claim",
  "claimDate": "2013-09-09T01:01:09.907842963Z",
  "claimType": "share",
  "target": "sha1-64ffa72fa9bcb2f825e7ed40b9451e5cadca4c2c",
  "transitive": false
,"camliSig":"wsBcBAABCAAQBQJSLR3VCRApMaZ8JvWr2gAA14kIAKmi5rCI5JTBvHbBuAu7wPVA87BLXm/BaD6zjqOENB4U8B+6KxyuT6KXe9P591IDXdZmJTP5tesbLtKw0iAWiRf2ea0Y7Ms3K77nLnSZM5QIOzb4aQKd1668p/5KqU3VfNayoHt69YkXyKBkqyEPjHINzC03QuLz5NIEBMYJaNqKKtEtSgh4gG8BBYq5qQzdKFg/Hx7VhkhW1y/1wwGSFJjaiPFMIJsF4d/gaO01Ip7XLro63ccyCy81tqKHnVjv0uULmZdbpgd3RHGGSnW3c9BfqkGvc3Wl11UQKzqc9OT+WTAWp8TXg6bLES9sQNzerx2wUfjKB9J4Yrk14iBfjl8==AynO"}`),
	)
	if err != nil {
		t.Fatal(err)
	}
	s, ok = b.AsShare()
	if !ok {
		t.Fatal("expected share")
	}
	clockNow = func() time.Time { return time.Unix(100, 0) }
	if s.IsExpired() {
		t.Error("expected not expired")
	}
	clockNow = func() time.Time { return time.Unix(1378687181+2*86400, 0) }
	if s.IsExpired() {
		t.Error("expected not expired")
	}
}
開發者ID:rfistman,項目名稱:camlistore,代碼行數:60,代碼來源:schema_test.go

示例3: TestKVClaim

func TestKVClaim(t *testing.T) {
	tests := []struct {
		k, v string
		ok   bool
		want camtypes.Claim
	}{
		{
			k:  "claim|sha1-b380b3080f9c71faa5c1d82bbd4d583a473bc77d|2931A67C26F5ABDA|2011-11-28T01:32:37.000123456Z|sha1-b3d93daee62e40d36237ff444022f42d7d0e43f2",
			v:  "set-attribute|tag|foo1|sha1-ad87ca5c78bd0ce1195c46f7c98e6025abbaf007",
			ok: true,
			want: camtypes.Claim{
				BlobRef:   blob.MustParse("sha1-b3d93daee62e40d36237ff444022f42d7d0e43f2"),
				Signer:    blob.MustParse("sha1-ad87ca5c78bd0ce1195c46f7c98e6025abbaf007"),
				Permanode: blob.MustParse("sha1-b380b3080f9c71faa5c1d82bbd4d583a473bc77d"),
				Type:      "set-attribute",
				Attr:      "tag",
				Value:     "foo1",
				Date:      time.Time(types.ParseTime3339OrZero("2011-11-28T01:32:37.000123456Z")),
			},
		},
	}
	for _, tt := range tests {
		got, ok := index.ExpKvClaim(tt.k, tt.v, blob.Parse)
		if ok != tt.ok {
			t.Errorf("kvClaim(%q, %q) = ok %v; want %v", tt.k, tt.v, ok, tt.ok)
			continue
		}
		if got != tt.want {
			t.Errorf("kvClaim(%q, %q) = %+v; want %+v", tt.k, tt.v, got, tt.want)
			continue
		}
	}
}
開發者ID:camlistore,項目名稱:camlistore,代碼行數:33,代碼來源:corpus_test.go

示例4: handlerDescribeTestSetupWithImage

// extends handlerDescribeTestSetup but adds a camliContentImage to pn.
func handlerDescribeTestSetupWithImage(fi *test.FakeIndex) index.Interface {
	handlerDescribeTestSetup(fi)
	pn := blob.MustParse("perma-123")
	imageRef := blob.MustParse("fakeref-789")
	fi.AddMeta(imageRef, "", 789)
	fi.AddClaim(owner, pn, "set-attribute", "camliContentImage", imageRef.String())
	return fi
}
開發者ID:camarox53,項目名稱:coreos-baremetal,代碼行數:9,代碼來源:handler_test.go

示例5: TestDescribeMarshal

func TestDescribeMarshal(t *testing.T) {
	// Empty Describe
	q := &SearchQuery{
		Describe: &DescribeRequest{},
	}
	enc, err := json.Marshal(q)
	if err != nil {
		t.Fatal(err)
	}
	if got, want := string(enc), `{"describe":{"blobref":null,"at":null}}`; got != want {
		t.Errorf("JSON: %s; want %s", got, want)
	}
	back := &SearchQuery{}
	err = json.Unmarshal(enc, back)
	if err != nil {
		t.Fatal(err)
	}
	if !reflect.DeepEqual(q, back) {
		t.Errorf("Didn't round-trip. Got %#v; want %#v", back, q)
	}

	// DescribeRequest with multiple blobref
	q = &SearchQuery{
		Describe: &DescribeRequest{
			BlobRefs: []blob.Ref{blob.MustParse("sha-1234"), blob.MustParse("sha-abcd")},
		},
	}
	enc, err = json.Marshal(q)
	if err != nil {
		t.Fatal(err)
	}
	if got, want := string(enc), `{"describe":{"blobrefs":["sha-1234","sha-abcd"],"blobref":null,"at":null}}`; got != want {
		t.Errorf("JSON: %s; want %s", got, want)
	}
	back = &SearchQuery{}
	err = json.Unmarshal(enc, back)
	if err != nil {
		t.Fatal(err)
	}
	if !reflect.DeepEqual(q, back) {
		t.Errorf("Didn't round-trip. Got %#v; want %#v", back, q)
	}

	// and the zero value
	q = &SearchQuery{}
	enc, err = json.Marshal(q)
	if err != nil {
		t.Fatal(err)
	}
	if string(enc) != "{}" {
		t.Errorf(`Zero value: %q; want null`, enc)
	}
}
開發者ID:rn2dy,項目名稱:camlistore,代碼行數:53,代碼來源:query_test.go

示例6: AddClaim

func (fi *FakeIndex) AddClaim(owner, permanode blob.Ref, claimType, attr, value string) {
	fi.lk.Lock()
	defer fi.lk.Unlock()
	date := fi.nextDate()

	claim := &search.Claim{
		Permanode: permanode,
		Signer:    blob.Ref{},
		BlobRef:   blob.Ref{},
		Date:      date,
		Type:      claimType,
		Attr:      attr,
		Value:     value,
	}
	key := permanode.String() + "/" + owner.String()
	fi.ownerClaims[key] = append(fi.ownerClaims[key], claim)

	if claimType == "set-attribute" && strings.HasPrefix(attr, "camliPath:") {
		suffix := attr[len("camliPath:"):]
		path := &search.Path{
			Target: blob.MustParse(value),
			Suffix: suffix,
		}
		fi.path[fmt.Sprintf("%s\x00%s\x00%s", owner, permanode, suffix)] = path
	}
}
開發者ID:JayBlaze420,項目名稱:camlistore,代碼行數:26,代碼來源:fakeindex.go

示例7: missingBlobs

func missingBlobs(dbDir, blobDir string) error {
	fsck, err := db.NewRO(dbDir)
	if err != nil {
		return err
	}
	defer fsck.Close()
	bs, err := dir.New(blobDir)
	if err != nil {
		return err
	}
	// defer s.Close() - where is this??
	missing := 0
	// TODO(dichro): cache Parents() call results?
	for ref := range fsck.Missing() {
		if body, size, err := bs.Fetch(blob.MustParse(ref)); err == nil {
			log.Printf("missing ref %q found with size %d", ref, size)
			body.Close()
			continue
		}
		fmt.Println(ref)
		missing++
		nodes, err := fsck.Parents(ref)
		if err != nil {
			log.Print(err)
			continue
		}
		printHierarchy(fsck, bs, 1, "", nodes)
	}
	fmt.Println("total", missing)
	return nil
}
開發者ID:dichro,項目名稱:cameloff,代碼行數:31,代碼來源:fsck.go

示例8: TestShareSearchSerialization

func TestShareSearchSerialization(t *testing.T) {
	signer := blob.MustParse("yyy-5678")

	q := &search.SearchQuery{
		Expression: "is:image",
		Limit:      42,
	}
	bb := schema.NewShareRef(schema.ShareHaveRef, true)
	bb.SetShareSearch(q)
	bb = bb.SetSigner(signer)
	bb = bb.SetClaimDate(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC))
	s := bb.Blob().JSON()

	want := `{"camliVersion": 1,
  "authType": "haveref",
  "camliSigner": "yyy-5678",
  "camliType": "claim",
  "claimDate": "2009-11-10T23:00:00Z",
  "claimType": "share",
  "search": {
    "expression": "is:image",
    "limit": 42,
    "around": null
  },
  "transitive": true
}`
	if want != s {
		t.Errorf("Incorrect serialization of shared search. Wanted:\n %s\nGot:\n%s\n", want, s)
	}
}
開發者ID:camarox53,項目名稱:coreos-baremetal,代碼行數:30,代碼來源:schema_public_test.go

示例9: TestCorpusAppendPermanodeAttrValues

func TestCorpusAppendPermanodeAttrValues(t *testing.T) {
	c, pn, sig1, sig2 := newTestCorpusWithPermanode()
	s := func(s ...string) []string { return s }

	sigMissing := blob.MustParse("xyz-123")

	tests := []struct {
		attr string
		want []string
		t    time.Time
		sig  blob.Ref
	}{
		{attr: "not-exist", want: s()},
		{attr: "DelAll", want: s()},
		{attr: "DelOne", want: s("b", "c", "e")},
		{attr: "foo", want: s("foov")},
		{attr: "tag", want: s("c", "e", "f")},
		{attr: "tag", want: s("a", "b"), t: time.Unix(102, 0)},
		{attr: "SetAfterAdd", want: s("setv")},
		// sig1
		{attr: "not-exist", want: s(), sig: sig1},
		{attr: "DelAll", want: s(), sig: sig1},
		{attr: "DelOne", want: s("b", "c"), sig: sig1},
		{attr: "foo", want: s("foov"), sig: sig1},
		{attr: "tag", want: s("c", "e"), sig: sig1},
		{attr: "tag", want: s("a", "b"), t: time.Unix(102, 0), sig: sig1},
		{attr: "SetAfterAdd", want: s("setv"), sig: sig1},
		// sig2
		{attr: "DelAll", want: s("c"), sig: sig2},
		{attr: "DelOne", want: s("e"), sig: sig2},
		{attr: "tag", want: s("d"), t: time.Unix(105, 0), sig: sig2},
		{attr: "SetAfterAdd", want: s("c"), sig: sig2},
		// sigMissing (not present in pn)
		{attr: "tag", want: s(), sig: sigMissing},
	}
	for i, tt := range tests {
		got := c.AppendPermanodeAttrValues(nil, pn, tt.attr, tt.t, tt.sig)
		if len(got) == 0 && len(tt.want) == 0 {
			continue
		}
		if !reflect.DeepEqual(got, tt.want) {
			t.Errorf("%d. attr %q = %q; want %q",
				i, tt.attr, got, tt.want)
		}

		if !tt.t.IsZero() {
			// skip equivalence test if specific time was given
			continue
		}
		got = c.AppendPermanodeAttrValues(nil, pn, tt.attr, time.Unix(200, 0), tt.sig)
		if len(got) == 0 && len(tt.want) == 0 {
			continue
		}
		if !reflect.DeepEqual(got, tt.want) {
			t.Errorf("%d. attr %q = %q; want %q",
				i, tt.attr, got, tt.want)
		}
	}
}
開發者ID:camlistore,項目名稱:camlistore,代碼行數:59,代碼來源:corpus_test.go

示例10: okayWithoutMeta

func okayWithoutMeta(refStr string) func(*packTest) {
	return func(pt *packTest) {
		if pt.okayNoMeta == nil {
			pt.okayNoMeta = map[blob.Ref]bool{}
		}
		pt.okayNoMeta[blob.MustParse(refStr)] = true
	}
}
開發者ID:rfistman,項目名稱:camlistore,代碼行數:8,代碼來源:blobpacked_test.go

示例11: setupContent

func setupContent(owner blob.Ref, rootName string) *test.FakeIndex {

	picNode := blob.MustParse("picpn-1234")
	galRef := blob.MustParse("gal-1234")
	rootRef := blob.MustParse("root-abcd")
	camp0 := blob.MustParse("picpn-9876543210")
	camp1 := blob.MustParse("picpn-9876543211")
	camp0f := blob.MustParse("picfile-f00ff00f00a5")
	camp1f := blob.MustParse("picfile-f00ff00f00b6")

	idx := test.NewFakeIndex()
	idx.AddSignerAttrValue(owner, "camliRoot", rootName, rootRef)

	idx.AddMeta(owner, "", 100)
	for _, br := range []blob.Ref{picNode, galRef, rootRef, camp0, camp1} {
		idx.AddMeta(br, "permanode", 100)
	}
	for _, br := range []blob.Ref{camp0f, camp1f} {
		idx.AddMeta(br, "file", 100)
	}

	idx.AddClaim(owner, rootRef, "set-attribute", "camliPath:singlepic", picNode.String())
	idx.AddClaim(owner, rootRef, "set-attribute", "camliPath:camping", galRef.String())
	idx.AddClaim(owner, galRef, "add-attribute", "camliMember", camp0.String())
	idx.AddClaim(owner, galRef, "add-attribute", "camliMember", camp1.String())
	idx.AddClaim(owner, camp0, "set-attribute", "camliContent", camp0f.String())
	idx.AddClaim(owner, camp1, "set-attribute", "camliContent", camp1f.String())

	return idx
}
開發者ID:rayleyva,項目名稱:camlistore,代碼行數:30,代碼來源:publish_test.go

示例12: testMergeFileInfoRow

func testMergeFileInfoRow(t *testing.T, wholeRef string) {
	c := index.ExpNewCorpus()
	value := "100|something%2egif|image%2Fgif"
	want := camtypes.FileInfo{
		Size:     100,
		MIMEType: "image/gif",
		FileName: "something.gif",
	}
	if wholeRef != "" {
		value += "|" + wholeRef
		want.WholeRef = blob.MustParse(wholeRef)
	}
	c.Exp_mergeFileInfoRow("fileinfo|sha1-579f7f246bd420d486ddeb0dadbb256cfaf8bf6b", value)
	fi := c.Exp_files(blob.MustParse("sha1-579f7f246bd420d486ddeb0dadbb256cfaf8bf6b"))
	if !reflect.DeepEqual(want, fi) {
		t.Errorf("Got %+v; want %+v", fi, want)
	}
}
開發者ID:rfistman,項目名稱:camlistore,代碼行數:18,代碼來源:index_test.go

示例13: handlerDescribeTestSetup

func handlerDescribeTestSetup(fi *test.FakeIndex) index.Interface {
	pn := blob.MustParse("perma-123")
	fi.AddMeta(pn, "permanode", 123)
	fi.AddClaim(owner, pn, "set-attribute", "camliContent", "fakeref-232")
	fi.AddMeta(blob.MustParse("fakeref-232"), "", 878)

	// Test deleting all attributes
	fi.AddClaim(owner, pn, "add-attribute", "wont-be-present", "x")
	fi.AddClaim(owner, pn, "add-attribute", "wont-be-present", "y")
	fi.AddClaim(owner, pn, "del-attribute", "wont-be-present", "")

	// Test deleting a specific attribute.
	fi.AddClaim(owner, pn, "add-attribute", "only-delete-b", "a")
	fi.AddClaim(owner, pn, "add-attribute", "only-delete-b", "b")
	fi.AddClaim(owner, pn, "add-attribute", "only-delete-b", "c")
	fi.AddClaim(owner, pn, "del-attribute", "only-delete-b", "b")
	return fi
}
開發者ID:camarox53,項目名稱:coreos-baremetal,代碼行數:18,代碼來源:handler_test.go

示例14: TestPaths

func TestPaths(t *testing.T) {
	br := blob.MustParse("digalg-abcd")
	ds := &DiskStorage{root: "/tmp/dir"}

	slash := filepath.ToSlash
	if e, g := "/tmp/dir/digalg/abc/d__", slash(ds.blobDirectory("", br)); e != g {
		t.Errorf("short blobref dir; expected path %q; got %q", e, g)
	}
	if e, g := "/tmp/dir/digalg/abc/d__/digalg-abcd.dat", slash(ds.blobPath("", br)); e != g {
		t.Errorf("short blobref path; expected path %q; got %q", e, g)
	}

	br = blob.MustParse("sha1-c22b5f9178342609428d6f51b2c5af4c0bde6a42")
	if e, g := "/tmp/dir/partition/foo/sha1/c22/b5f", slash(ds.blobDirectory("foo", br)); e != g {
		t.Errorf("amazon queue dir; expected path %q; got %q", e, g)
	}

}
開發者ID:jakubbrzeski,項目名稱:camlistore,代碼行數:18,代碼來源:path_test.go

示例15: sendTestBlobs

func sendTestBlobs(ch chan blob.SizedRef, list string, size uint32) {
	defer close(ch)
	if list == "" {
		return
	}
	for _, br := range strings.Split(list, ",") {
		ch <- blob.SizedRef{blob.MustParse(br), size}
	}
}
開發者ID:camarox53,項目名稱:coreos-baremetal,代碼行數:9,代碼來源:sync_test.go


注:本文中的camlistore/org/pkg/blob.MustParse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。