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

     1  package spec
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/qri-io/qri/event"
     7  	"github.com/qri-io/qri/repo"
     8  	repotest "github.com/qri-io/qri/repo/test"
     9  )
    10  
    11  func TestNewTestRepo(t *testing.T) {
    12  	rmf := func(t *testing.T) (repo.Repo, func()) {
    13  		mr, err := repotest.NewEmptyTestRepo(event.NilBus)
    14  		if err != nil {
    15  			t.Fatal(err)
    16  		}
    17  		return mr, func() {}
    18  	}
    19  
    20  	RunRepoTests(t, rmf)
    21  }
    22  
    23  func TestNewMemRepoFromDir(t *testing.T) {
    24  	repo, _, err := repotest.NewMemRepoFromDir("../testdata")
    25  	if err != nil {
    26  		t.Error(err.Error())
    27  		return
    28  	}
    29  
    30  	c, err := repo.RefCount()
    31  	if err != nil {
    32  		t.Error(err.Error())
    33  		return
    34  	}
    35  
    36  	// this should match count of valid testcases
    37  	// in testdata
    38  	expectRefCount := 6
    39  
    40  	if c != expectRefCount {
    41  		t.Errorf("expected %d datasets. got %d", expectRefCount, c)
    42  	}
    43  }
    44  
    45  func TestNewTestRepoWithHistory(t *testing.T) {
    46  	repo, log, err := repotest.NewTestRepoWithHistory()
    47  	if err != nil {
    48  		t.Fatal(err)
    49  	}
    50  	c, err := repo.RefCount()
    51  	if err != nil {
    52  		t.Error(err.Error())
    53  		return
    54  	}
    55  	// there is only one ref that does not have a previous path:
    56  	expectRefCount := 1
    57  	if c != expectRefCount {
    58  		t.Errorf("expected %d datasets, got %d", expectRefCount, c)
    59  	}
    60  
    61  	expectLogCount := 5
    62  	if len(log) != expectLogCount {
    63  		t.Errorf("expected %d datasets, got %d", expectLogCount, len(log))
    64  	}
    65  
    66  	for i, ref := range log {
    67  		if ref.Name != "logtest" {
    68  			t.Errorf("index %d, expected all datasets to have name 'logtest', got '%s'", i, ref.Name)
    69  		}
    70  	}
    71  }