Skip to content

Commit

Permalink
fix compiler.go
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoehler committed Nov 21, 2024
1 parent 8867168 commit eacc737
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 37 deletions.
29 changes: 6 additions & 23 deletions cloud/cpi_cmd_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var _ = Describe("CpiCmdRunner", func() {
cmdRunner *fakesys.FakeCmdRunner
cpi CPI
apiVersion int
logger boshlog.Logger
)

BeforeEach(func() {
Expand All @@ -35,7 +36,7 @@ var _ = Describe("CpiCmdRunner", func() {
}

cmdRunner = fakesys.NewFakeCmdRunner()
logger := boshlog.NewLogger(boshlog.LevelNone)
logger = boshlog.NewLogger(boshlog.LevelNone)
cpiCmdRunner = NewCPICmdRunner(cmdRunner, cpi, logger, true)

apiVersion = 1
Expand Down Expand Up @@ -63,7 +64,7 @@ var _ = Describe("CpiCmdRunner", func() {
Expect(actualCmd.Env).To(Equal(map[string]string{
"BOSH_PACKAGES_DIR": cpi.PackagesDir,
"BOSH_JOBS_DIR": cpi.JobsDir,
"PATH": "/usr/local/bin:/usr/bin:/bin:/sbin",
"PATH": os.Getenv("PATH"),
}))
Expect(actualCmd.UseIsolatedEnv).To(BeTrue())
bytes, err := io.ReadAll(actualCmd.Stdin)
Expand All @@ -89,11 +90,8 @@ var _ = Describe("CpiCmdRunner", func() {
apiVersion = 2
})

AfterEach(func() {
os.Unsetenv("BOSH_CPI_USE_ISOLATED_ENV")
})
It("creates correct command with UseIsolatedEnv false if BOSH_CPI_USE_ISOLATED_ENV is set", func() {
os.Setenv("BOSH_CPI_USE_ISOLATED_ENV", "false")
It("creates correct command with UseIsolatedEnv false if NewCPICmdRunner is initialized with false", func() {
cpiCmdRunner = NewCPICmdRunner(cmdRunner, cpi, logger, false)
cmdOutput := CmdOutput{}
outputBytes, err := json.Marshal(cmdOutput)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -109,21 +107,6 @@ var _ = Describe("CpiCmdRunner", func() {
Expect(actualCmd.UseIsolatedEnv).To(BeFalse())

})
It("throws helpful error if the value of BOSH_CPI_USE_ISOLATED_ENV cannot be parsed into a bool", func() {
os.Setenv("BOSH_CPI_USE_ISOLATED_ENV", "falasdse")
cmdOutput := CmdOutput{}
outputBytes, err := json.Marshal(cmdOutput)
Expect(err).NotTo(HaveOccurred())

result := fakesys.FakeCmdResult{
Stdout: string(outputBytes),
ExitStatus: 0,
}
cmdRunner.AddCmdResult("/jobs/cpi/bin/cpi", result)
_, err = cpiCmdRunner.Run(context, "fake-method", apiVersion, "fake-argument-1", "fake-argument-2")
Expect(err).To(HaveOccurred())
Expect(MatchRegexp("BOSH_CPI_USE_ISOLATED_ENV cannot be parsed", err))
})
It("creates correct command with stemcell api_version in context", func() {
cmdOutput := CmdOutput{}
outputBytes, err := json.Marshal(cmdOutput)
Expand All @@ -145,7 +128,7 @@ var _ = Describe("CpiCmdRunner", func() {
Expect(actualCmd.Env).To(Equal(map[string]string{
"BOSH_PACKAGES_DIR": cpi.PackagesDir,
"BOSH_JOBS_DIR": cpi.JobsDir,
"PATH": "/usr/local/bin:/usr/bin:/bin:/sbin",
"PATH": os.Getenv("PATH"),
}))
Expect(actualCmd.UseIsolatedEnv).To(BeTrue())
bytes, err := io.ReadAll(actualCmd.Stdin)
Expand Down
28 changes: 14 additions & 14 deletions installation/pkg/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,20 @@ func (c *compiler) Compile(pkg birelpkg.Compilable) (bistatepkg.CompiledPackageR
return record, isCompiledPackage, bosherr.Errorf("Packaging script for package '%s' not found", pkg.Name())
}

cmd := boshsys.Command{
Name: "bash",
Args: []string{"-x", "packaging"},
Env: map[string]string{
"BOSH_COMPILE_TARGET": packageSrcDir,
"BOSH_INSTALL_TARGET": installDir,
"BOSH_PACKAGE_NAME": pkg.Name(),
"BOSH_PACKAGES_DIR": c.packagesDir,
"PATH": os.Getenv("PATH"),
"LD_LIBRARY_PATH": os.Getenv("LD_LIBRARY_PATH"),
},
UseIsolatedEnv: c.useIsolatedEnv,
WorkingDir: packageSrcDir,
}
cmd := boshsys.Command{
Name: "bash",
Args: []string{"-x", "packaging"},
Env: map[string]string{
"BOSH_COMPILE_TARGET": packageSrcDir,
"BOSH_INSTALL_TARGET": installDir,
"BOSH_PACKAGE_NAME": pkg.Name(),
"BOSH_PACKAGES_DIR": c.packagesDir,
"PATH": os.Getenv("PATH"),
"LD_LIBRARY_PATH": os.Getenv("LD_LIBRARY_PATH"),
},
UseIsolatedEnv: c.useIsolatedEnv,
WorkingDir: packageSrcDir,
}

_, _, _, err = c.runner.RunComplexCommand(cmd)
if err != nil {
Expand Down

0 comments on commit eacc737

Please sign in to comment.