Exemple #1
0
/*
	Decorates a goconvey test with a tmpdir.

	See also https://github.com/smartystreets/goconvey/wiki/Decorating-tests-to-provide-common-logic
*/
func WithTmpdir(fn func()) func() {
	return func() {
		retreat, err := os.Getwd()
		if err != nil {
			panic(err)
		}
		if originalDir == "" {
			originalDir = retreat
		}

		convey.Reset(func() {
			os.Chdir(retreat)
		})

		tmpBase := def.Base()
		err = os.MkdirAll(tmpBase, 0755)
		if err != nil {
			panic(err)
		}
		err = os.Chdir(tmpBase)
		if err != nil {
			panic(err)
		}

		err = os.MkdirAll("repeatr-test", 0755)
		if err != nil {
			panic(err)
		}
		tmpdir, err := ioutil.TempDir("repeatr-test", "")
		if err != nil {
			panic(err)
		}
		tmpdir, err = filepath.Abs(tmpdir)
		if err != nil {
			panic(err)
		}
		convey.Reset(func() {
			os.RemoveAll(tmpdir)
		})
		err = os.Chdir(tmpdir)
		if err != nil {
			panic(err)
		}

		fn()
	}
}
Exemple #2
0
/*
	The default, "universal", dispatching Transmat.
	You should be able to throw pretty much any type of input spec at it.

	If you're building your own transports and data warehousing integrations,
	you'll need to assemble your own Transmat instead of this one --
	`integrity.DispatchingTransmat` is good for composing them so you can still
	use one interface to get any kind of data you want.
*/
func DefaultTransmat() integrity.Transmat {
	workDir := filepath.Join(def.Base(), "io")
	dirCacher := cachedir.New(filepath.Join(workDir, "dircacher"), map[integrity.TransmatKind]integrity.TransmatFactory{
		integrity.TransmatKind("dir"): dir.New,
		integrity.TransmatKind("tar"): tar.New,
		integrity.TransmatKind("s3"):  s3.New,
	})
	gitCacher := cachedir.New(filepath.Join(workDir, "dircacher-git"), map[integrity.TransmatKind]integrity.TransmatFactory{
		integrity.TransmatKind("git"): git.New,
	})
	universalTransmat := integrity.NewDispatchingTransmat(map[integrity.TransmatKind]integrity.Transmat{
		integrity.TransmatKind("dir"): dirCacher,
		integrity.TransmatKind("tar"): dirCacher,
		integrity.TransmatKind("s3"):  dirCacher,
		integrity.TransmatKind("git"): gitCacher,
	})
	return universalTransmat
}
Exemple #3
0
func Get(desire string) executor.Executor {
	var executor executor.Executor

	switch desire {
	case "null":
		executor = &null.Executor{}
	case "nsinit":
		executor = &nsinit.Executor{}
	case "chroot":
		executor = &chroot.Executor{}
	default:
		panic(def.ValidationError.New("No such executor %s", desire))
	}

	// Set the base path to operate from
	executor.Configure(filepath.Join(def.Base(), "executor", desire))

	return executor
}
Exemple #4
0
func determineBestAssembler() integrity.Assembler {
	if os.Getuid() != 0 {
		// Can't mount without root.
		fmt.Fprintf(os.Stderr, "WARN: using slow fs assembly system: need root privs to use faster systems.\n")
		return placer.NewAssembler(placer.CopyingPlacer)
	}
	if os.Getenv("TRAVIS") != "" {
		// Travis's own virtualization denies mounting.  whee.
		fmt.Fprintf(os.Stderr, "WARN: using slow fs assembly system: travis' environment blocks faster systems.\n")
		return placer.NewAssembler(placer.CopyingPlacer)
	}
	// If we *can* mount...
	if isAUFSAvailable() {
		// if AUFS is installed, AUFS+Bind is The Winner.
		return placer.NewAssembler(placer.NewAufsPlacer(filepath.Join(def.Base(), "aufs")))
	}
	// last fallback... :( copy it is
	fmt.Fprintf(os.Stderr, "WARN: using slow fs assembly system: install AUFS to use faster systems.\n")
	return placer.NewAssembler(placer.CopyingPlacer)
	// TODO we should be able to use copy for fallback RW isolator but still bind for RO.  write a new placer for that.  or really, maybe bind should chain.
}