예제 #1
0
파일: get.go 프로젝트: AaronGoldman/ccfs
//GetList retrieves a list parces it and returns it or an error
func GetList(objectHash objects.HCID) (l objects.List, err error) {
	listbytes, err := GetBlob(objectHash)

	if err != nil || len(listbytes) == 0 {
		return nil, err
	}
	l, err = objects.ListFromBytes(listbytes)
	if err != nil {
		return nil, err
	}
	return
}
예제 #2
0
func TestGetCommit(t *testing.T) {
	testhkid := objects.HkidFromDString("65232373562705602286177837897283294165955126"+
		"49112249373497830592072241416893611216069423804730437860475300564272"+
		"976762085068519188612732562106886379081213385", 10)
	outdata, err := services.Get(testhkid, "TestPostCommit")
	outlist, err := objects.ListFromBytes(outdata)
	typeString, hash := outlist.HashForNamesegment("TestPostBlob")
	//truthdata := []byte("90014ae279fa5034a51def77132457cd" +
	//	"66403facc3d88b54bd3e84ecade8f633,blob,TestPostBlob")
	if typeString != "blob" ||
		hash.Hex() != "90014ae279fa5034a51def77132457cd"+
			"66403facc3d88b54bd3e84ecade8f633" ||
		err != nil {
		log.Printf("\n\tTestGetList:\n\t%s\n", outdata)
		t.Fail()
	}
}
예제 #3
0
func Testbadfrombytes(t *testing.T) {
	var err error
	_, err = objects.ListFromBytes([]byte{})
	if err.Error() != "Could not parse list bytes" {
		t.Errorf("[] should not parse")
	}
	_, err = objects.CommitFromBytes([]byte{})
	if err.Error() != "Could not parse commit bytes" {
		t.Errorf("[] should not parse")
	}
	_, err = objects.TagFromBytes([]byte{})
	if err.Error() != "Could not parse tag bytes" {
		t.Errorf("[] should not parse")
	}
	_, err = objects.PrivateKeyFromBytes([]byte{})
	if err.Error() != "Could not parse commit bytes" {
		t.Errorf("[] should not parse")
	}
}
예제 #4
0
func BenchmarkLowLevelPath(b *testing.B) {
	//key for tag
	hkidT := objects.HkidFromDString("39968110670682397993178679825250942322686997267223"+
		"4437068973021071131498376777586055610149840018574420844767320660902612889"+
		"4016152514163591905578729891874833", 10)

	//key for commit
	hkidC := objects.HkidFromDString("4629814823893296480016411334808793836186124559723200"+
		"9799621767537249764640887064630013835561124248209118706504211519889067517"+
		"10824965155500230480521264034469", 10)

	for i := 0; i < b.N; i++ {

		blobHcid := postBlob("testing")
		postTag(blobHcid, hkidT)
		tagHcid := postList(hkidT)
		postCommit(tagHcid, hkidC)

		//get commit
		hkid, _ := hex.DecodeString(
			"1312ac161875b270da2ae4e1471ba94a9883419250caa4c2f1fd80a91b37907e",
		)
		testcommit, err := services.GetCommit(hkid)
		if err != nil {
			log.Panic(err)
		}

		//log.Printf("authentic commit:%v\n", testcommit.Verify())
		if !testcommit.Verify() {
			b.FailNow()
		}
		//get list
		listbytes, err := services.GetBlob(testcommit.ListHash)
		if err != nil {
			log.Panic(err)
		}

		testlist, err := objects.ListFromBytes(listbytes)

		//log.Printf("authentic list:%v\n", )
		if !bytes.Equal(testcommit.ListHash, testlist.Hash()) {
			b.FailNow()
		}
		//get tag
		_, testTagHash := testlist.HashForNamesegment("testTag")
		testTag, err := services.GetTag(testTagHash.Bytes(), "testBlob")
		//log.Printf("authentic tag:%v\n", testTag.Verify())
		if !testTag.Verify() {
			b.FailNow()
		}
		//get blob
		testBlob, err := services.GetBlob(testTag.HashBytes.(objects.HCID))
		//log.Printf("authentic blob:%v\n", bytes.Equal(testTag.HashBytes,
		//	testBlob.Hash()))
		if err != nil {
			b.Fatalf("Get Blob Error: %s\n", err)
		}
		if !bytes.Equal(testTag.HashBytes.(objects.HCID), testBlob.Hash()) {
			b.FailNow()
		}
	}
}