func TestRepoAddGetDirFile(t *testing.T) {
    ctx := context.Background()

    ds := dstest.Mock()

    rp := NewRepoProps()

    rp.SetType("infostore")
    rp.SetKind("blog")
    rp.SetName("mytestblog")
    rp.SetOffset(0)
    rp.SetArea(0)
    rp.SetCat(0)
    rp.SetPath("/index/reposet/mytestblog")

    sr, err := NewStoreRoot(ctx, ds, nil)
    if err != nil {
         t.Fatal(err)
    }

    rpid, err := sr.AddProps("repoprops", rp)
    if err != nil {
         t.Fatal(err)
    }

    rrpid, err := sr.HasProps("repoprops", rp)
    if err != nil {
         t.Fatal(err)
    }

    if rrpid == nil {
         t.Fatal("added repoprops does not exist.")
    }

    if rrpid.String() != rpid.String() {
        t.Fatal(fmt.Errorf("repoprops cid mismatch, expected %v found %v", rpid.String(), rrpid.String()))
    }

    // validate the bytes we wrote
    b, err := rp.Marshal()
    if err != nil {
        t.Fatal(err)
    }

    bb, size, err := sr.bytesFromFile("repoprops", int64(len(b)))
    if err != nil {
         t.Fatal(err)
    }

    // assert size is as expected
    if size != int64(len(b)) {
        t.Fatal("size is incorrect")
    }

    // assert valid bytes
    if !bytes.Equal(bb, b) {
        t.Fatal("data read was different than data written")
    }

    // create repoprops from file in directory
    ri, err := sr.GetProps("repoprops", rp)
    if err != nil {
         t.Fatal(err)
    }

    rp2, ok := ri.(RepoProps)
    if !ok {
        t.Fatal("invalid return type, expected.")
    }

    // assert object from file content matches object we wrote
    if !rp.Equal(rp2) {
        t.Fatal("data read was different than data written")
    }

}
// Test Repo DAG node Add/Get using Directory and File objects
Test Repo DAG node Add/Get using Directory and File objects
// Test Repo DAG node Add / Get using Directory and File objects
func TestRepoAddGetDirFile(t *testing.T) {
    ctx := context.Background()
    ds := dstest.Mock()
    rp := NewRepoProps()
    rp.SetType("infostore")
    rp.SetKind("blog")
    rp.SetName("mytestblog")
    rp.SetOffset(0)
    rp.SetArea(0)
    rp.SetCat(0)
    rp.SetPath("/index/reposet/mytestblog")
    sr, err := NewStoreRoot(ctx, ds, nil)
    if err != nil {
         t.Fatal(err)
    }
    rpid, err := sr.AddProps("repoprops", rp)
    if err != nil {
         t.Fatal(err)
    }
    rrpid, err := sr.HasProps("repoprops", rp)
    if err != nil {
         t.Fatal(err)
    }
    if rrpid == nil {
         t.Fatal("added repoprops does not exist.")
    }
    if rrpid.String() != rpid.String() {
        t.Fatal(fmt.Errorf("repoprops cid mismatch, expected %v found %v", rpid.String(), rrpid.String()))
    }
    b, err := rp.Marshal()
    if err != nil {
        t.Fatal(err)
    }
    bb, size, err := sr.bytesFromFile("repoprops", int64(len(b)))
    if err != nil {
         t.Fatal(err)
    }
    if size != int64(len(b)) {
        t.Fatal("size is incorrect")
    }
    if !bytes.Equal(bb, b) {
        t.Fatal("data read was different than data written")
    }
    ri, err := sr.GetProps("repoprops", rp)
    if err != nil {
         t.Fatal(err)
    }
    rp2, ok := ri.(RepoProps)
    if !ok {
        t.Fatal("invalid return type, expected.")
    }
    if !rp.Equal(rp2) {
        t.Fatal("data read was different than data written")
    }
}
func TestRepoAddGetDirFile ( t * testing . T ) { ctx := context . Background ( ) ds := dstest . Mock ( ) rp := NewRepoProps ( ) rp . SetType ( " " ) rp . SetKind ( " " ) rp . SetName ( " " ) rp . SetOffset ( 0 ) rp . SetArea ( 0 ) rp . SetCat ( 0 ) rp . SetPath ( " " ) sr , err := NewStoreRoot ( ctx , ds , nil ) if err != nil { t . Fatal ( err ) } rpid , err := sr . AddProps ( " " , rp ) if err != nil { t . Fatal ( err ) } rrpid , err := sr . HasProps ( " " , rp ) if err != nil { t . Fatal ( err ) } if rrpid == nil { t . Fatal ( " " ) } if rrpid . String ( ) != rpid . String ( ) { t . Fatal ( fmt . Errorf ( " " , rpid . String ( ) , rrpid . String ( ) ) ) } b , err := rp . Marshal ( ) if err != nil { t . Fatal ( err ) } bb , size , err := sr . bytesFromFile ( " " , int64 ( len ( b ) ) ) if err != nil { t . Fatal ( err ) } if size != int64 ( len ( b ) ) { t . Fatal ( " " ) } if ! bytes . Equal ( bb , b ) { t . Fatal ( " " ) } ri , err := sr . GetProps ( " " , rp ) if err != nil { t . Fatal ( err ) } rp2 , ok := ri . ( RepoProps ) if ! ok { t . Fatal ( " " ) } if ! rp . Equal ( rp2 ) { t . Fatal ( " " ) } }
Test Repo DAG node Add/Get using Directory and File objects
Test Repo DAG node Add / Get using Directory and File objects
// validate the bytes we wrote // assert size is as expected // assert valid bytes // create repoprops from file in directory // assert object from file content matches object we wrote