internal

package
v0.6.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2020 License: Apache-2.0, MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertBumpedVersion

func AssertBumpedVersion(t *testing.T, newRepoDir, oldRepoDir string, oldVersion uint64)

AssertBumpedVersion checks that the version oldRepoDir is as expected, that the version in newRepoDir is updated by 1

func AssertLinked

func AssertLinked(t *testing.T, repoDir, repoLink string)

AssertLinked verifies that repoLink points to oldRepoDir

func AssertLogged

func AssertLogged(t *testing.T, logFile *os.File, subStr string)

AssertLogged asserts that a given string is contained in the given log file.

func AssertNewRepoInstalled

func AssertNewRepoInstalled(t *testing.T, newRepoDir, oldRepoDir, repoLink string)

AssertNewRepoInstalled verifies that the repoLink points to newRepoDir, and that oldRepoDir is still there

func AssertRepoVersion

func AssertRepoVersion(t *testing.T, versionStr, repoPath string)

AssertRepoVersion verifies that the version in repoPath is equal to versionStr

func CloneRepo

func CloneRepo(linkPath string, newVersion uint) (string, error)

CloneRepo copies a linked repo directory to a new, writable repo directory. The directory created will be named with a timestamp, version number, and uniqueifyig tag if necessary.

Params:

linkPath: path to a symlink, which links to an actual repo directory to be cloned.

func InstallNewRepo

func InstallNewRepo(linkPath, newRepoPath string) error

InstallNewRepo updates a symlink to point to a new repo directory.

func RequireInitRepo

func RequireInitRepo(t *testing.T, version uint) (container, repoLink string)

RequireInitRepo establishes a new repo symlink and directory inside a temporary container directory. Migrations of the repo are expected to be placed within the same container, such that a test can clean up arbitrary migrations by removing the container. Returns the path to the container directory, and the repo symlink inside it.

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger logs migration events to disk and, if initialized with verbose, stdout too.

func NewLogger

func NewLogger(wc io.WriteCloser, verbose bool) *Logger

NewLogger creates a new Logger. All log writes go to f, the logging file. If the verbose flag is true all log writes also go to stdout.

func (*Logger) Close

func (l *Logger) Close() error

Close closes the logfile backing the Logger.

func (*Logger) Error

func (l *Logger) Error(err error)

Error logs an error to the logging output.

func (*Logger) Print

func (l *Logger) Print(msg string)

Print logs a string to the logging output.

func (*Logger) Printf

func (l *Logger) Printf(format string, v ...interface{})

Printf logs and formats a string to the logging output.

type Migration

type Migration interface {
	// Describe returns a list of steps, as a formatted string, that a given Migration will take.
	// These should correspond to named functions in the given Migration.
	Describe() string

	// Migrate performs all migration steps for the Migration that implements the interface.
	// Migrate  expects newRepo to be:
	//		a directory
	// 		read/writeable by this process,
	//      contain a copy of the old repo.
	Migrate(newRepoPath string) error

	// Versions returns valid from and to migration versions for this migration.
	Versions() (from, to uint)

	// Validate performs validation operations, using oldRepo for comparison.
	// Validation requirements will be different for every migration.
	// Validate expects newRepo to be
	//		a directory
	//      readable by this process
	//      already migrated
	//  It expects oldRepo to be
	//		a directory
	//      read-only by this process
	//  A successful validation returns nil.
	Validate(oldRepoPath, newRepoPath string) error
}

Migration is the interface to all repo migration versions.

func DefaultMigrationsProvider

func DefaultMigrationsProvider() []Migration

DefaultMigrationsProvider is the migrations provider dependency used in production. You may provide a test version when needed. Please see runner_test.go for more information.

type MigrationRunner

type MigrationRunner struct {

	// MigrationsProvider is a dependency for fetching available migrations
	// to allow unit tests to supply test migrations without creating test fixtures.
	MigrationsProvider func() []Migration
	// contains filtered or unexported fields
}

MigrationRunner represents a migration command

func NewMigrationRunner

func NewMigrationRunner(logger *Logger, command, oldRepoOpt, newRepoOpt string) (*MigrationRunner, error)

NewMigrationRunner builds a MigrationRunner for the given command and repo options Returns an error if homepath expansion fails for oldRepoOpt or newRepoOpt

func (*MigrationRunner) Run

func (m *MigrationRunner) Run() RunResult

Run executes the MigrationRunner

type RunResult

type RunResult struct {
	// full path to new repo (migrated or not).
	// This is blank unless repo was cloned -- if it errors out too early or for "describe"
	NewRepoPath string

	// Old version and new version. If no applicable migration is found, these will be equal,
	// and if errors early they will = 0.
	OldVersion, NewVersion uint

	// Any errors encountered by Run
	Err error
}

RunResult stores the needed results of calling Run()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL