Beispiel #1
0
func ensureGDMExists(repo, localPath string, log func(string, ...interface{})) error {
	s, err := os.Stat(localPath)
	if err == nil && s.IsDir() {
		files, err := ioutil.ReadDir(localPath)
		if err != nil {
			return err
		}
		if len(files) != 0 {
			// The directory exists and is not empty, do nothing.
			if repo != "" {
				log("not pulling repo %q; directory already exist and is not empty: %q", repo, localPath)
			}
			return nil
		}
	}
	if err := config.EnsureDirExists(localPath); err != nil {
		return EnsureErrorResult(err)
	}
	sh, err := shell.DefaultInDir(localPath)
	if err != nil {
		return EnsureErrorResult(err)
	}
	g, err := git.NewClient(sh)
	if err != nil {
		return EnsureErrorResult(err)
	}
	log("cloning %q into %q ...", repo, localPath)
	if err := g.CloneRepo(repo, localPath); err != nil {
		return EnsureErrorResult(err)
	}
	log("done")
	return nil
}
func TestDetect(t *testing.T) {
	const baseDir = "testdata/gen"
	os.RemoveAll(baseDir)
	for i, test := range detectTests {
		testDir := fmt.Sprintf("%s/%d", baseDir, i)
		if err := os.MkdirAll(testDir, 0777); err != nil {
			t.Fatal(err)
		}
		sh, err := shell.DefaultInDir(testDir)
		if err != nil {
			t.Fatal(err)
		}
		c := &sous.BuildContext{
			Sh:     sh,
			Source: sous.SourceContext{},
		}
		if test.Dockerfile != "" {
			dockerfilePath := path.Join(testDir, "Dockerfile")
			dockerfileBytes := []byte(test.Dockerfile)
			if err := ioutil.WriteFile(dockerfilePath, dockerfileBytes, 0777); err != nil {
				t.Fatal(err)
			}
		}
		dr, err := (&DockerfileBuildpack{}).Detect(c)
		if err := assertError(test.Error, err); err != nil {
			t.Error(err)
		}
		if err := assertResult(test.DetectResult, dr, err); err != nil {
			t.Error(err)
		}
	}
}
Beispiel #3
0
func newLocalWorkDirShell(verbosity *config.Verbosity, l LocalWorkDir) (v LocalWorkDirShell, err error) {
	v.Sh, err = shell.DefaultInDir(string(l))
	v.TeeEcho = os.Stdout //XXX should use a writer
	v.Sh.Debug = verbosity.Debug
	//v.TeeOut = os.Stdout
	//v.TeeErr = os.Stderr
	return v, initErr(err, "getting current working directory")
}
Beispiel #4
0
// TODO: This should register a cleanup task with the cli, to delete the temp
// dir.
func newScratchDirShell() (v ScratchDirShell, err error) {
	const what = "getting scratch directory"
	dir, err := ioutil.TempDir("", "sous")
	if err != nil {
		return v, initErr(err, what)
	}
	v.Sh, err = shell.DefaultInDir(dir)
	v.TeeOut = os.Stdout
	v.TeeErr = os.Stderr
	return v, initErr(err, what)
}