github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/repo/test/spec/test_profilestore.go (about)

     1  package spec
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/qri-io/qri/profile"
     8  )
     9  
    10  func testProfileStore(t *testing.T, rmf RepoMakerFunc) {
    11  	r, cleanup := rmf(t)
    12  	defer cleanup()
    13  	ctx := context.Background()
    14  	ps := r.Profiles()
    15  
    16  	if err := ps.PutProfile(ctx, &profile.Profile{}); err == nil {
    17  		t.Error("expected PutProfile to require an ID field")
    18  	}
    19  
    20  	id, err := profile.IDB58Decode("QmZePf5LeXow3RW5U1AgEiNbW46YnRGhZ7HPvm1UmPFPwt")
    21  	if err != nil {
    22  		t.Fatal(err)
    23  	}
    24  	if err := ps.PutProfile(ctx, &profile.Profile{ID: id, Peername: "uniq"}); err != nil {
    25  		t.Errorf("PutProfile err: %s", err)
    26  	}
    27  
    28  	p, err := ps.GetProfile(ctx, id)
    29  	if err != nil {
    30  		t.Errorf("GetProfile: %s", err)
    31  	}
    32  
    33  	// TODO - write a CompareProfiles function in profile package
    34  	if p.Peername != "uniq" {
    35  		t.Errorf("GetProfile returned the wrong profile")
    36  	}
    37  
    38  	if err := ps.DeleteProfile(ctx, id); err != nil {
    39  		t.Errorf("DeleteProfile err: %s", err)
    40  	}
    41  
    42  }