Skip to content

Commit

Permalink
Use filepath to join paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Fydon committed Feb 17, 2017
1 parent 11d354b commit 513d8d2
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 24 deletions.
7 changes: 4 additions & 3 deletions cmd/create_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"path/filepath"
"regexp"

boshcrypto "github.com/cloudfoundry/bosh-utils/crypto"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
Expand Down Expand Up @@ -449,7 +450,7 @@ var _ = Describe("CreateEnvCmd", func() {
It("prints the default state file path", func() {
err := command.Run(fakeStage, defaultCreateEnvOpts)
Expect(err).NotTo(HaveOccurred())
Expect(stdOut).To(gbytes.Say("Deployment state: '/path/to/manifest-state.json'"))
Expect(stdOut).To(gbytes.Say("Deployment state: '" + regexp.QuoteMeta(filepath.Join("/", "path", "to", "manifest-state.json")) + "'"))
})
})

Expand Down Expand Up @@ -491,14 +492,14 @@ var _ = Describe("CreateEnvCmd", func() {
Expect(fakeInstallationParser.ParsePath).To(Equal(deploymentManifestPath))

Expect(stdOut).To(gbytes.Say("Deployment manifest: '/path/to/manifest.yml'"))
Expect(stdOut).To(gbytes.Say("Deployment state: '/path/to/manifest-state.json'"))
Expect(stdOut).To(gbytes.Say("Deployment state: '" + regexp.QuoteMeta(filepath.Join("/", "path", "to", "manifest-state.json")) + "'"))
Expect(stdOut).To(gbytes.Say("Migrated legacy deployments file: '/path/to/bosh-deployments.yml'"))
})

It("sets the temp root", func() {
err := command.Run(fakeStage, defaultCreateEnvOpts)
Expect(err).NotTo(HaveOccurred())
Expect(fs.TempRootPath).To(Equal("fake-install-dir/fake-installation-id/tmp"))
Expect(fs.TempRootPath).To(Equal(filepath.Join("fake-install-dir", "fake-installation-id", "tmp")))
})

Context("when setting the temp root fails", func() {
Expand Down
6 changes: 3 additions & 3 deletions cmd/deployment_deleteter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ cloud_provider:

var expectValidationInstallationDeletionEvents = func() {
Expect(fakeUI.Said).To(Equal([]string{
"Deployment state: '/deployment-dir/fake-deployment-manifest-state.json'\n",
"Deployment state: '" + filepath.Join("/", "deployment-dir", "fake-deployment-manifest-state.json") + "'\n",
}))

Expect(fakeStage.PerformCalls).To(Equal([]*fakebiui.PerformCall{
Expand Down Expand Up @@ -336,7 +336,7 @@ cloud_provider:
Expect(err).ToNot(HaveOccurred())

Expect(fakeUI.Said).To(Equal([]string{
"Deployment state: '/deployment-dir/fake-deployment-manifest-state.json'\n",
"Deployment state: '" + filepath.Join("/", "deployment-dir", "fake-deployment-manifest-state.json") + "'\n",
"No deployment state file found.\n",
}))
})
Expand Down Expand Up @@ -365,7 +365,7 @@ cloud_provider:
expectDeleteAndCleanup(true)
err := newDeploymentDeleter().DeleteDeployment(fakeStage)
Expect(err).NotTo(HaveOccurred())
Expect(fs.TempRootPath).To(Equal("fake-install-dir/fake-installation-id/tmp"))
Expect(fs.TempRootPath).To(Equal(filepath.Join("fake-install-dir", "fake-installation-id", "tmp")))
})

It("extracts & install CPI release tarball", func() {
Expand Down
3 changes: 2 additions & 1 deletion cmd/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"syscall"
"time"

Expand Down Expand Up @@ -40,7 +41,7 @@ var _ = Describe("UIDownloader", func() {
var expectedPath string

BeforeEach(func() {
expectedPath = "/fake-dst-dir/prefix-20091110-230102-000000333.tgz"
expectedPath = filepath.Join("/", "fake-dst-dir", "prefix-20091110-230102-000000333.tgz")

err := fs.MkdirAll("/fake-dst-dir", os.ModePerm)
Expect(err).ToNot(HaveOccurred())
Expand Down
6 changes: 4 additions & 2 deletions common/util/file_helper_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package util_test

import (
"path/filepath"

"github.com/cloudfoundry/bosh-cli/common/util"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
Expand All @@ -24,7 +26,7 @@ var _ = Describe("AbsolutifyPath", func() {
It("joins file path to the manifest directory", func() {
fakeFilePath = "../fake/relative/path/file.tgz"
Expect(util.AbsolutifyPath(fakeManifestPath, fakeFilePath, realfs)).To(
Equal("/fake/manifest/fake/relative/path/file.tgz"))
Equal(filepath.Join("/", "fake", "manifest", "fake", "relative", "path", "file.tgz")))
})
})
Context("File is located in same directory as manifest or subdirectory", func() {
Expand All @@ -44,7 +46,7 @@ var _ = Describe("AbsolutifyPath", func() {
currentUserHome, _ := realfs.HomeDir("")

result, err := util.AbsolutifyPath(fakeManifestPath, fakeFilePath, realfs)
Expect(result).To(Equal(currentUserHome + "/fake/absolute/path/file.tgz"))
Expect(result).To(Equal(currentUserHome + filepath.Join("/", "fake", "absolute", "path", "file.tgz")))
Expect(err).ToNot(HaveOccurred())
})
})
Expand Down
7 changes: 4 additions & 3 deletions config/file_system_deployment_state_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"encoding/json"
"errors"
"path/filepath"

boshlog "github.com/cloudfoundry/bosh-utils/logger"
biproperty "github.com/cloudfoundry/bosh-utils/property"
Expand All @@ -33,9 +34,9 @@ var _ = Describe("fileSystemDeploymentStateService", func() {
Describe("DeploymentStatePath", func() {
Context("when statePath is NOT specified", func() {
It("is based on the manifest path and name", func() {
Expect(DeploymentStatePath("/path/to/some-manifest.yml", "")).To(Equal("/path/to/some-manifest-state.json"))
Expect(DeploymentStatePath("/path/to/some-manifesty.yaml", "")).To(Equal("/path/to/some-manifesty-state.json"))
Expect(DeploymentStatePath("/path/to/some-manifest", "")).To(Equal("/path/to/some-manifest-state.json"))
Expect(DeploymentStatePath("/path/to/some-manifest.yml", "")).To(Equal(filepath.Join("/", "path", "to", "some-manifest-state.json")))
Expect(DeploymentStatePath("/path/to/some-manifesty.yaml", "")).To(Equal(filepath.Join("/", "path", "to", "some-manifesty-state.json")))
Expect(DeploymentStatePath("/path/to/some-manifest", "")).To(Equal(filepath.Join("/", "path", "to", "some-manifest-state.json")))
})
})

Expand Down
8 changes: 5 additions & 3 deletions installation/target_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"path/filepath"

biconfig "github.com/cloudfoundry/bosh-cli/config"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
Expand Down Expand Up @@ -46,7 +48,7 @@ var _ = Describe("TargetProvider", func() {
It("uses the existing installation_id & returns a target based on it", func() {
target, err := targetProvider.NewTarget()
Expect(err).ToNot(HaveOccurred())
Expect(target.Path()).To(Equal("/.bosh/installations/12345"))
Expect(target.Path()).To(Equal(filepath.Join("/", ".bosh", "installations", "12345")))
})

It("does not change the saved installation_id", func() {
Expand All @@ -68,7 +70,7 @@ var _ = Describe("TargetProvider", func() {
It("generates a new installation_id & returns a target based on it", func() {
target, err := targetProvider.NewTarget()
Expect(err).ToNot(HaveOccurred())
Expect(target.Path()).To(Equal("/.bosh/installations/fake-uuid-1"))
Expect(target.Path()).To(Equal(filepath.Join("/", ".bosh", "installations", "fake-uuid-1")))
})

It("saves the new installation_id", func() {
Expand All @@ -90,7 +92,7 @@ var _ = Describe("TargetProvider", func() {
It("generates a new installation_id & returns a target based on it", func() {
target, err := targetProvider.NewTarget()
Expect(err).ToNot(HaveOccurred())
Expect(target.Path()).To(Equal("/.bosh/installations/fake-uuid-1"))
Expect(target.Path()).To(Equal(filepath.Join("/", ".bosh", "installations", "fake-uuid-1")))
})

It("saves the new installation_id", func() {
Expand Down
12 changes: 7 additions & 5 deletions installation/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
. "github.com/cloudfoundry/bosh-cli/installation"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"path/filepath"
)

var _ = Describe("Target", func() {
Expand All @@ -14,23 +16,23 @@ var _ = Describe("Target", func() {
})

It("returns the blobstore path", func() {
Expect(target.BlobstorePath()).To(Equal("/home/fake/madcow/blobs"))
Expect(target.BlobstorePath()).To(Equal(filepath.Join("/", "home", "fake", "madcow", "blobs")))
})

It("returns the compiled packages index path", func() {
Expect(target.CompiledPackagedIndexPath()).To(Equal("/home/fake/madcow/compiled_packages.json"))
Expect(target.CompiledPackagedIndexPath()).To(Equal(filepath.Join("/", "home", "fake", "madcow", "compiled_packages.json")))
})

It("returns the templates index path", func() {
Expect(target.TemplatesIndexPath()).To(Equal("/home/fake/madcow/templates.json"))
Expect(target.TemplatesIndexPath()).To(Equal(filepath.Join("/", "home", "fake", "madcow", "templates.json")))
})

It("returns the packages path", func() {
Expect(target.PackagesPath()).To(Equal("/home/fake/madcow/packages"))
Expect(target.PackagesPath()).To(Equal(filepath.Join("/", "home", "fake", "madcow", "packages")))
})

It("returns the temp path", func() {
Expect(target.TmpPath()).To(Equal("/home/fake/madcow/tmp"))
Expect(target.TmpPath()).To(Equal(filepath.Join("/", "home", "fake", "madcow", "tmp")))
})
})
})
3 changes: 2 additions & 1 deletion installation/uninstaller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"log"
"path/filepath"
"regexp"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -39,7 +40,7 @@ var _ = Describe("Uninstaller", func() {
Expect(err).ToNot(HaveOccurred())

Expect(fs.FileExists(installationPath)).To(BeFalse())
Expect(logBuffer).To(gbytes.Say("Successfully uninstalled CPI from '%s'", installationPath))
Expect(logBuffer).To(gbytes.Say("Successfully uninstalled CPI from '%s'", regexp.QuoteMeta(installationPath)))
})

It("returns and logs errors when remove all fails", func() {
Expand Down
3 changes: 2 additions & 1 deletion stemcell/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package stemcell_test

import (
"errors"
"path/filepath"

. "github.com/cloudfoundry/bosh-cli/stemcell"
. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -50,7 +51,7 @@ cloud_properties:
Manifest{
Name: "fake-stemcell-name",
Version: "2690",
ImagePath: "fake-extracted-path/image",
ImagePath: filepath.Join("fake-extracted-path", "image"),
CloudProperties: biproperty.Map{
"infrastructure": "aws",
"ami": biproperty.Map{
Expand Down
5 changes: 3 additions & 2 deletions templatescompiler/erbrenderer/erb_renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package erbrenderer_test

import (
"errors"
"path/filepath"

. "github.com/cloudfoundry/bosh-cli/templatescompiler/erbrenderer"
fakebierbrenderer "github.com/cloudfoundry/bosh-cli/templatescompiler/erbrenderer/fakes"
Expand Down Expand Up @@ -37,8 +38,8 @@ var _ = Describe("ErbRenderer", func() {
boshsys.Command{
Name: "ruby",
Args: []string{
"fake-temp-dir/erb-render.rb",
"fake-temp-dir/erb-context.json",
filepath.Join("fake-temp-dir", "erb-render.rb"),
filepath.Join("fake-temp-dir", "erb-context.json"),
"fake-src-path",
"fake-dst-path",
},
Expand Down

0 comments on commit 513d8d2

Please sign in to comment.