in internal/buildpacktest/buildpacktest.go [287:347]
func runBuildpackPhase(t *testing.T, cfg *config) (bool, error) {
temps := buildpacktestenv.SetUpTempDirs(t, cfg.codeDir)
opts := []gcp.ContextOption{gcp.WithApplicationRoot(temps.CodeDir), gcp.WithBuildpackRoot(temps.BuildpackDir)}
// Mock out calls to ctx.Exec, if specified
if len(cfg.mockProcesses) > 0 {
eCmd, err := mockprocess.NewExecCmd(cfg.mockProcesses...)
if err != nil {
t.Fatalf("error creating mock exec command: %v", err)
}
opts = append(opts, gcp.WithExecCmd(eCmd))
}
// Logs all ctx.Exec commands to stderr
os.Setenv(env.DebugMode, "true")
ctx := gcp.NewContext(opts...)
if cfg.appPath != "" {
// Copy apps from test data into temp code dir
if err := fileutil.MaybeCopyPathContents(temps.CodeDir, filepath.Join(flagTestData, cfg.appPath), fileutil.AllPaths); err != nil {
return false, fmt.Errorf("unable to copy app directory %q to %q: %v", cfg.appPath, temps.CodeDir, err)
}
}
for f, c := range cfg.files {
fn := filepath.Join(temps.CodeDir, f)
if dir := path.Dir(fn); dir != "" {
if err := os.MkdirAll(dir, 0744); err != nil {
return false, fmt.Errorf("creating directory tree %s: %v", dir, err)
}
}
if err := ioutil.WriteFile(fn, []byte(c), 0644); err != nil {
return false, fmt.Errorf("writing file %s: %v", fn, err)
}
}
if err := os.Chdir(temps.CodeDir); err != nil {
return false, fmt.Errorf("changing to code dir %q: %v", temps.CodeDir, err)
}
if cfg.buildpackPhase == buildPhase {
if err := cfg.buildFn(ctx); err != nil {
return false, fmt.Errorf("build error: %v", err)
}
} else {
detect, err := cfg.detectFn(ctx)
if err != nil {
return false, fmt.Errorf("detect error: %v", err)
}
// Mimics the exit code of libcnb library when the detect function
// succeeds but does not pass detect.
if !detect.Result().Pass {
return false, nil
}
}
return true, nil
}