github.com/bilus/oya@v0.0.3-0.20190301162104-da4acbd394c6/testutil/fixtures.go (about)

     1  package testutil
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  
     7  	"github.com/bilus/oya/pkg/oyafile"
     8  	"github.com/bilus/oya/pkg/pack"
     9  	"github.com/bilus/oya/pkg/project"
    10  	"github.com/bilus/oya/pkg/semver"
    11  	"github.com/bilus/oya/pkg/types"
    12  	"github.com/pkg/errors"
    13  )
    14  
    15  func MustListOyafiles(t *testing.T, rootDir string) []*oyafile.Oyafile {
    16  	t.Helper()
    17  	project, err := project.Detect(rootDir, filepath.Join(rootDir, ".packs"))
    18  	AssertNoErr(t, err, "Error detecting project")
    19  	oyafiles, err := project.Oyafiles()
    20  	AssertNoErr(t, err, "Error listing Oyafiles")
    21  	AssertTrue(t, len(oyafiles) > 0, "No Oyafiles found")
    22  	return oyafiles
    23  }
    24  
    25  func MustListOyafilesSubdir(t *testing.T, rootDir, subDir string) []*oyafile.Oyafile {
    26  	t.Helper()
    27  	project, err := project.Detect(rootDir, filepath.Join(rootDir, ".packs"))
    28  	AssertNoErr(t, err, "Error detecting project")
    29  	oyafiles, err := project.List(subDir)
    30  	AssertNoErr(t, err, "Error listing Oyafiles")
    31  	AssertTrue(t, len(oyafiles) > 0, "No Oyafiles found")
    32  	return oyafiles
    33  }
    34  
    35  func MustLoadOyafile(t *testing.T, dir, rootDir string) *oyafile.Oyafile {
    36  	t.Helper()
    37  	o, found, err := oyafile.LoadFromDir(dir, rootDir)
    38  	AssertNoErr(t, err, "Error loading root Oyafile")
    39  	AssertTrue(t, found, "Root Oyafile not found")
    40  	return o
    41  }
    42  
    43  type mockRepo struct {
    44  	importPath types.ImportPath
    45  }
    46  
    47  func (p mockRepo) Install(version semver.Version, installDir string) error {
    48  	return errors.Errorf("mockRepo#Install is not implemented")
    49  }
    50  
    51  func (p mockRepo) IsInstalled(version semver.Version, installDir string) (bool, error) {
    52  	return false, errors.Errorf("mockRepo#IsInstalled is not implemented")
    53  }
    54  
    55  func (p mockRepo) InstallPath(version semver.Version, installDir string) string {
    56  	panic(errors.Errorf("mockRepo#InstallPath is not implemented"))
    57  }
    58  
    59  func (p mockRepo) ImportPath() types.ImportPath {
    60  	return p.importPath
    61  }
    62  
    63  func mustMakeMockRepo(importPath string) pack.Repo {
    64  	return mockRepo{
    65  		importPath: types.ImportPath(importPath),
    66  	}
    67  }
    68  
    69  func MustMakeMockPack(importPath string, version string) pack.Pack {
    70  	pack, err := pack.New(mustMakeMockRepo(importPath), semver.MustParse(version))
    71  	if err != nil {
    72  		panic(err)
    73  	}
    74  	return pack
    75  }