func TestPostTagTagBlob(t *testing.T) { testhkid := objects.HkidFromDString("46298148238932964800164113348087"+ "9383618612455972320097996217675372497646408870646300138355611242"+ "4820911870650421151988906751710824965155500230480521264034469", 10) domain1Hkid := objects.HkidFromDString("32076859881811206392323279987831"+ "3732334949433938278619036381396945204532895319697233476900342324"+ "1692155627674142765782672165943417419038514237233188152538761", 10) domain2Hkid := objects.HkidFromDString("49220288257701056900010210884990"+ "0714973444364727181180850528073586453638681999434006549298762097"+ "4197649255374796716934112121800838847071661501215957753532505", 10) err := services.InsertDomain(testhkid, "testTag1", domain1Hkid) if err != nil { t.Errorf("InsertDomain with error: %s", err) } err = services.InsertDomain(testhkid, "testTag1/testTag2", domain2Hkid) if err != nil { t.Errorf("InsertDomain with error: %s", err) } indata := objects.Blob([]byte("TestTagTagBlobData")) testpath := "testTag1/testTag2/testBlob" _, err = services.Post(testhkid, testpath, indata) outdata, err := services.Get(testhkid, testpath) if err != nil { log.Printf("[TestPostTagTagBlob] testhkid %s", testhkid) log.Printf("[TestPostTagTagBlob] domain1Hkid %s", domain1Hkid) log.Printf("[TestPostTagTagBlob] domain2Hkid %s", domain2Hkid) t.Errorf("Retreved with error: %s", err) } else if !bytes.Equal(indata, outdata) { t.Errorf("Expected:\n\t%s\nGot:\n\t%s", indata, outdata) } }
func BenchmarkTagBlobUpdate(b *testing.B) { err := services.InsertRepo(benchmarkRepo, "tagFound", benchmarkTagHkid) b.ResetTimer() for i := 0; i < b.N; i++ { err = services.InsertDomain(benchmarkRepo, "tagFound", benchmarkTagHkid) if err != nil { b.Fatal(err) } } }
func BenchmarkTagBlobInsert(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { err := services.InsertDomain(benchmarkRepo, "tagFound", benchmarkTagHkid) //TODO clear list after each insert if err != nil { b.Fatal(err) } } }
func TestPostTagBlob(t *testing.T) { testhkid := objects.HkidFromDString("65232373562705602286177837897283"+ "2941659551264911224937349783059207224141689361121606942380473043"+ "7860475300564272976762085068519188612732562106886379081213385", 10) testDomainHkid := objects.HkidFromDString("48133155371863219707191657794884"+ "7537768863308478273117048217437472569476796507874261675750733630"+ "0675115007319549300204862762937376227751462258339344895829332", 10) services.InsertDomain(testhkid, "TestPostTag", testDomainHkid) testpath := "TestPostTag/TestPostBlob" indata := []byte("TestPostTagBlobData") services.Post(testhkid, testpath, objects.Blob(indata)) outdata, err := services.Get(testhkid, testpath) if !bytes.Equal(indata, outdata) || err != nil { t.Fail() } }
func TestPostListTagBlob(t *testing.T) { testhkid := objects.HkidFromDString("46298148238932964800164113348087"+ "9383618612455972320097996217675372497646408870646300138355611242"+ "4820911870650421151988906751710824965155500230480521264034469", 10) domainHkid := objects.HkidFromDString("12796633883654089746486670711069"+ "9781359720828332046318301886846633714179790444071153863702142701"+ "146332294245448463914286494124849121460550667767568731696934", 10) err := services.InsertDomain(testhkid, "testList/testTag", domainHkid) indata := objects.Blob([]byte("TestListTagBlobData")) testpath := "testList/testTag/testBlob" _, err = services.Post(testhkid, testpath, indata) outdata, err := services.Get(testhkid, testpath) if err != nil { t.Errorf("Retreved with error: %s", err) } else if !bytes.Equal(indata, outdata) { t.Errorf("Expected:\n\t%s\nGot:\n\t%s", indata, outdata) } }
func BenchmarkTagBlobFound(b *testing.B) { err := services.InsertDomain(benchmarkRepo, "tagFound", benchmarkTagHkid) if err != nil { b.Fatal(err) } _, err = services.Post(benchmarkRepo, "tagFound/benchmarkBlob", objects.Blob("Benchmark Blob Data")) if err != nil { b.Fatal(err) } b.ResetTimer() for i := 0; i < b.N; i++ { _, err := services.Get(benchmarkRepo, "tagFound/benchmarkBlob") if err != nil { b.Fatal(err) } } }
func TestPostTagListBlob(t *testing.T) { testhkid := objects.HkidFromDString("46298148238932964800164113348087"+ "9383618612455972320097996217675372497646408870646300138355611242"+ "4820911870650421151988906751710824965155500230480521264034469", 10) domainHkid := objects.HkidFromDString("62089221762245310704629142682144"+ "1944826557905230450143203631438168806532495876980559885034903315"+ "4294997505754401230560960060918213268981906409591978967796584", 10) err := services.InsertDomain(testhkid, "testTag", domainHkid) if err != nil { t.Errorf("InsertDomain with error: %s", err) } indata := objects.Blob([]byte("TestTagListBlobData")) testpath := "testTag/testList/testBlob" _, err = services.Post(testhkid, testpath, indata) outdata, err := services.Get(testhkid, testpath) if !bytes.Equal(indata, outdata) || err != nil { t.Fail() } }
func TestPostListCommitBlob(t *testing.T) { testhkid := objects.HkidFromDString("46298148238932964800164113348087"+ "9383618612455972320097996217675372497646408870646300138355611242"+ "4820911870650421151988906751710824965155500230480521264034469", 10) repoHkid := objects.HkidFromDString("59803288656043806807393139191118"+ "0777289273091938777159029927847596771500408478956278378281366717"+ "7487960901581583946753338859223459810645621124266443931192097", 10) err := services.InsertDomain(testhkid, "testList/testCommit", repoHkid) if err != nil { t.Errorf("InsertDomain with error: %s", err) } indata := objects.Blob([]byte("TestListCommitBlobData")) testpath := "testList/testCommit/testBlob" _, err = services.Post(testhkid, testpath, indata) outdata, err := services.Get(testhkid, testpath) if err != nil { log.Printf("[TestPostListCommitBlob] testhkid %s", testhkid) log.Printf("[TestPostListCommitBlob] repoHkid %s", repoHkid) t.Errorf("Retreved with error: %s", err) } else if !bytes.Equal(indata, outdata) { t.Errorf("Expected:\n\t%s\nGot:\n\t%s", indata, outdata) } }
func TestPostTagCommitBlob(t *testing.T) { testhkid := objects.HkidFromDString("46298148238932964800164113348087"+ "9383618612455972320097996217675372497646408870646300138355611242"+ "4820911870650421151988906751710824965155500230480521264034469", 10) domainHkid := objects.HkidFromDString("39968110670682397993178679825250"+ "9423226869972672234437068973021071131498376777586055610149840018"+ "5744208447673206609026128894016152514163591905578729891874833", 10) repoHkid := objects.HkidFromDString("94522678075182002377842140271746"+ "1502019766737301062946423046280258817349516439546479625226895211"+ "80808353215150536034481206091147220911087792299373183736254", 10) err := services.InsertDomain(testhkid, "testTag", domainHkid) if err != nil { t.Errorf("InsertDomain with error: %s", err) } err = services.InsertRepo(testhkid, "testTag/testCommit", repoHkid) indata := objects.Blob([]byte("TestTagCommitBlobData")) testpath := "testTag/testCommit/testBlob" _, err = services.Post(testhkid, testpath, indata) outdata, err := services.Get(testhkid, testpath) if !bytes.Equal(indata, outdata) || err != nil { t.Fail() } }
func addCurators(inCommand struct { createDomain *bool createRepository *bool insertDomain *bool insertRepository *bool path *string hkid *string }) { if *inCommand.path != "" { //log.Printf("HKID: %s", *hkid) in := bufio.NewReader(os.Stdin) var err error h, collectionPath := fileSystemPath2CollectionPath(inCommand.path) //log.Printf("systemPath %s", *path) //log.Printf("collectionPath %s", collectionPath) FileInfos, err := ioutil.ReadDir(*inCommand.path) if err != nil { log.Printf("Error reading directory %s", err) os.Exit(2) return } if len(FileInfos) != 0 { fmt.Printf("The folder is not empty") os.Exit(2) return // Ends function } collectionName := filepath.Base(*inCommand.path) //fmt.Printf("Name of Collection: %s\n", collectionName) switch { case *inCommand.createDomain: //err = InitDomain(h, fmt.Sprintf("%s/%s", collectionPath, collectionName)) err = services.InitDomain(h, collectionPath) if err != nil { log.Println(err) return } case *inCommand.createRepository: //err = InitRepo(h, fmt.Sprintf("%s/%s", collectionPath, collectionName)) err = services.InitRepo(h, collectionPath) if err != nil { log.Println(err) return } case *inCommand.insertDomain: fmt.Println("Insert HKID as a hexadecimal number:") hex := *inCommand.hkid if *inCommand.hkid == "" { hex, _ = in.ReadString('\n') hex = strings.Trim(hex, "\n") } log.Print(len(hex)) foreignHkid, err := objects.HkidFromHex(hex) if err != nil { log.Printf("Somethng went wrong in insertDomain %s", err) os.Exit(2) } log.Printf("hkid: %s\n", h) err = services.InsertDomain(h, fmt.Sprintf("%s/%s", collectionPath, collectionName), foreignHkid) if err != nil { log.Println(err) return } case *inCommand.insertRepository: fmt.Println("Insert HKID as a hexadecimal number:") hex := *inCommand.hkid if *inCommand.hkid == "" { hex, _ = in.ReadString('\n') hex = strings.Trim(hex, "\n") } fmt.Printf("%s", hex) foreignHkid, err := objects.HkidFromHex(hex) if err != nil { log.Printf("Somethng went wrong in insertRepo %s", err) os.Exit(2) } fmt.Printf("hkid: %s", h) err = services.InsertRepo(h, fmt.Sprintf("%s/%s", collectionPath, collectionName), foreignHkid) if err != nil { log.Println(err) return } } } }