Skip to content

Commit

Permalink
Path aren't cross platform in the code, so updated those and then con…
Browse files Browse the repository at this point in the history
…tinued to update tests
  • Loading branch information
Fydon committed Feb 23, 2017
1 parent 513d8d2 commit 84b4d14
Show file tree
Hide file tree
Showing 49 changed files with 750 additions and 744 deletions.
3 changes: 2 additions & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"path/filepath"

"github.com/cppforlife/go-patch/patch"

Expand Down Expand Up @@ -385,7 +386,7 @@ func (c Cmd) configureUI() {
}

func (c Cmd) configureFS() {
tmpDirPath, err := c.deps.FS.ExpandPath("~/.bosh/tmp")
tmpDirPath, err := c.deps.FS.ExpandPath(filepath.Join("~", ".bosh", "tmp"))
c.panicIfErr(err)

err = c.deps.FS.ChangeTempRoot(tmpDirPath)
Expand Down
24 changes: 12 additions & 12 deletions cmd/create_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ var _ = Describe("CreateEnvCmd", func() {
userInterface = biui.NewWriterUI(stdOut, stdErr, logger)
fs = fakesys.NewFakeFileSystem()
fs.EnableStrictTempRootBehavior()
deploymentManifestPath = "/path/to/manifest.yml"
deploymentStatePath = "/path/to/manifest-state.json"
deploymentManifestPath = filepath.Join("/", "path", "to", "manifest.yml")
deploymentStatePath = filepath.Join("/", "path", "to", "manifest-state.json")
fs.RegisterOpenFile(deploymentManifestPath, &fakesys.FakeFile{
Stats: &fakesys.FakeFileStats{FileType: fakesys.FakeFileTypeFile},
})
Expand Down Expand Up @@ -212,12 +212,12 @@ var _ = Describe("CreateEnvCmd", func() {
manifestSHA = "ed173647f91a1001fa3859cb7857b0318794a7e92b40412146a93bebfb052218c91c0299e7b495470bf67b462722b807e8db7b9df3b59866451efcf4ae9e27a4"
Expect(err).ToNot(HaveOccurred())

cpiReleaseTarballPath = "/release/tarball/path"
cpiReleaseTarballPath = filepath.Join("/", "release", "tarball", "path")

stemcellTarballPath = "/stemcell/tarball/path"
stemcellTarballPath = filepath.Join("/", "stemcell", "tarball", "path")
extractedStemcell = bistemcell.NewExtractedStemcell(
bistemcell.Manifest{
ImagePath: "/stemcell/image/path",
ImagePath: filepath.Join("/", "stemcell", "image", "path"),
Name: "fake-stemcell-name",
Version: "fake-stemcell-version",
SHA1: "fake-stemcell-sha1",
Expand Down Expand Up @@ -387,7 +387,7 @@ var _ = Describe("CreateEnvCmd", func() {

command = bicmd.NewCreateEnvCmd(userInterface, doGet)

expectLegacyMigrate = mockLegacyDeploymentStateMigrator.EXPECT().MigrateIfExists("/path/to/bosh-deployments.yml").AnyTimes()
expectLegacyMigrate = mockLegacyDeploymentStateMigrator.EXPECT().MigrateIfExists(filepath.Join("/", "path", "to", "bosh-deployments.yml")).AnyTimes()

fakeStemcellExtractor.SetExtractBehavior(stemcellTarballPath, extractedStemcell, nil)

Expand Down Expand Up @@ -443,7 +443,7 @@ var _ = Describe("CreateEnvCmd", func() {
It("prints the deployment manifest", func() {
err := command.Run(fakeStage, defaultCreateEnvOpts)
Expect(err).NotTo(HaveOccurred())
Expect(stdOut).To(gbytes.Say("Deployment manifest: '/path/to/manifest.yml'"))
Expect(stdOut).To(gbytes.Say("Deployment manifest: '" + regexp.QuoteMeta(filepath.Join("/", "path", "to", "manifest.yml")) + "'"))
})

Context("when state file is NOT specified", func() {
Expand All @@ -457,15 +457,15 @@ var _ = Describe("CreateEnvCmd", func() {
Context("when state file is specified", func() {
It("prints specified state file path", func() {
createEnvOptsWithStatePath := bicmd.CreateEnvOpts{
StatePath: "/specified/path/to/cool-state.json",
StatePath: filepath.Join("/", "specified", "path", "to", "cool-state.json"),
Args: bicmd.CreateEnvArgs{
Manifest: bicmd.FileBytesWithPathArg{Path: deploymentManifestPath},
},
}

err := command.Run(fakeStage, createEnvOptsWithStatePath)
Expect(err).NotTo(HaveOccurred())
Expect(stdOut).To(gbytes.Say("Deployment state: '/specified/path/to/cool-state.json'"))
Expect(stdOut).To(gbytes.Say("Deployment state: '" + regexp.QuoteMeta(filepath.Join("/", "specified", "path", "to", "cool-state.json")) + "'"))
})
})
})
Expand All @@ -491,9 +491,9 @@ var _ = Describe("CreateEnvCmd", func() {
Expect(err).NotTo(HaveOccurred())
Expect(fakeInstallationParser.ParsePath).To(Equal(deploymentManifestPath))

Expect(stdOut).To(gbytes.Say("Deployment manifest: '/path/to/manifest.yml'"))
Expect(stdOut).To(gbytes.Say("Deployment manifest: '" + regexp.QuoteMeta(filepath.Join("/", "path", "to", "manifest.yml")) + "'"))
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'"))
Expect(stdOut).To(gbytes.Say("Migrated legacy deployments file: '" + regexp.QuoteMeta(filepath.Join("/", "path", "to", "bosh-deployments.yml")) + "'"))
})

It("sets the temp root", func() {
Expand Down Expand Up @@ -739,7 +739,7 @@ var _ = Describe("CreateEnvCmd", func() {
)

BeforeEach(func() {
otherReleaseTarballPath = "/path/to/other-release.tgz"
otherReleaseTarballPath = filepath.Join("/", "path", "to", "other-release.tgz")
fs.WriteFileString(otherReleaseTarballPath, "")

otherRelease = &fakebirel.FakeRelease{}
Expand Down
8 changes: 4 additions & 4 deletions cmd/env_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"os"
gopath "path"
"path/filepath"
"time"

"github.com/cppforlife/go-patch/patch"
Expand Down Expand Up @@ -78,10 +78,10 @@ func NewEnvFactory(deps BasicDeps, manifestPath string, statePath string, manife
releaseJobResolver := bideplrel.NewJobResolver(f.releaseManager)

// todo expand path?
workspaceRootPath := gopath.Join(os.Getenv("HOME"), ".bosh")
workspaceRootPath := filepath.Join(os.Getenv("HOME"), ".bosh")

{
tarballCacheBasePath := gopath.Join(workspaceRootPath, "downloads")
tarballCacheBasePath := filepath.Join(workspaceRootPath, "downloads")
tarballCache := bitarball.NewCache(tarballCacheBasePath, deps.FS, deps.Logger)
httpClient := bihttpclient.NewHTTPClient(bitarball.HTTPClient, deps.Logger)
tarballProvider := bitarball.NewProvider(
Expand Down Expand Up @@ -122,7 +122,7 @@ func NewEnvFactory(deps BasicDeps, manifestPath string, statePath string, manife
}

f.targetProvider = boshinst.NewTargetProvider(
f.deploymentStateService, deps.UUIDGen, gopath.Join(workspaceRootPath, "installations"))
f.deploymentStateService, deps.UUIDGen, filepath.Join(workspaceRootPath, "installations"))

{
diskRepo := biconfig.NewDiskRepo(f.deploymentStateService, deps.UUIDGen)
Expand Down
41 changes: 21 additions & 20 deletions cmd/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd_test
import (
"errors"
"os"
"path/filepath"

boshlog "github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
Expand Down Expand Up @@ -35,32 +36,32 @@ var _ = Describe("Factory", func() {

Describe("unknown commands, args and flags", func() {
BeforeEach(func() {
err := fs.WriteFileString("/file", "")
err := fs.WriteFileString(filepath.Join("/", "file"), "")
Expect(err).ToNot(HaveOccurred())
})

cmds := map[string][]string{
"help": []string{},
"add-blob": []string{"/file", "directory"},
"add-blob": []string{filepath.Join("/", "file"), "directory"},
"attach-disk": []string{"instance/abad1dea", "disk-cid-123"},
"blobs": []string{},
"interpolate": []string{"/file"},
"interpolate": []string{filepath.Join("/", "file")},
"cancel-task": []string{"1234"},
"clean-up": []string{},
"cloud-check": []string{},
"cloud-config": []string{},
"create-env": []string{"/file"},
"sha2ify-release": []string{"/file", "/file2"},
"create-release": []string{"/file"},
"create-env": []string{filepath.Join("/", "file")},
"sha2ify-release": []string{filepath.Join("/", "file"), filepath.Join("/", "file2")},
"create-release": []string{filepath.Join("/", "file")},
"delete-deployment": []string{},
"delete-disk": []string{"cid"},
"delete-env": []string{"/file"},
"delete-env": []string{filepath.Join("/", "file")},
"delete-release": []string{"release-version"},
"delete-snapshot": []string{"cid"},
"delete-snapshots": []string{},
"delete-stemcell": []string{"name/version"},
"delete-vm": []string{"cid"},
"deploy": []string{"/file"},
"deploy": []string{filepath.Join("/", "file")},
"deployment": []string{},
"deployments": []string{},
"disks": []string{},
Expand All @@ -70,9 +71,9 @@ var _ = Describe("Factory", func() {
"errands": []string{},
"events": []string{},
"export-release": []string{"release/version", "os/version"},
"finalize-release": []string{"/file"},
"generate-job": []string{"/file"},
"generate-package": []string{"/file"},
"finalize-release": []string{filepath.Join("/", "file")},
"generate-job": []string{filepath.Join("/", "file")},
"generate-package": []string{filepath.Join("/", "file")},
"init-release": []string{},
"inspect-release": []string{"name/version"},
"instances": []string{},
Expand All @@ -83,7 +84,7 @@ var _ = Describe("Factory", func() {
"manifest": []string{},
"recreate": []string{"slug"},
"releases": []string{},
"remove-blob": []string{"/file"},
"remove-blob": []string{filepath.Join("/", "file")},
"reset-release": []string{},
"restart": []string{"slug"},
"run-errand": []string{"name"},
Expand All @@ -96,12 +97,12 @@ var _ = Describe("Factory", func() {
"take-snapshot": []string{"group/id"},
"task": []string{"1234"},
"tasks": []string{},
"update-cloud-config": []string{"/file"},
"update-cloud-config": []string{filepath.Join("/", "file")},
"update-resurrection": []string{"off"},
"update-runtime-config": []string{"/file"},
"update-runtime-config": []string{filepath.Join("/", "file")},
"upload-blobs": []string{},
"upload-release": []string{"/file"},
"upload-stemcell": []string{"/file"},
"upload-release": []string{filepath.Join("/", "file")},
"upload-stemcell": []string{filepath.Join("/", "file")},
"vms": []string{},
}

Expand Down Expand Up @@ -191,12 +192,12 @@ var _ = Describe("Factory", func() {

Describe("deploy command", func() {
BeforeEach(func() {
err := fs.WriteFileString("/file", "")
err := fs.WriteFileString(filepath.Join("/", "file"), "")
Expect(err).ToNot(HaveOccurred())
})

It("parses multiple skip-drain flags", func() {
cmd, err := factory.New([]string{"deploy", "--skip-drain=job1", "--skip-drain=job2", "/file"})
cmd, err := factory.New([]string{"deploy", "--skip-drain=job1", "--skip-drain=job2", filepath.Join("/", "file")})
Expect(err).ToNot(HaveOccurred())

slug1, _ := boshdir.NewInstanceGroupOrInstanceSlugFromString("job1")
Expand All @@ -210,13 +211,13 @@ var _ = Describe("Factory", func() {
})

It("errors when excluding = from --skip-drain", func() {
_, err := factory.New([]string{"deploy", "--skip-drain", "job1", "/file"})
_, err := factory.New([]string{"deploy", "--skip-drain", "job1", filepath.Join("/", "file")})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("Not found: open job1: no such file or directory"))
})

It("defaults --skip-drain option value to all", func() {
cmd, err := factory.New([]string{"deploy", "--skip-drain", "/file"})
cmd, err := factory.New([]string{"deploy", "--skip-drain", filepath.Join("/", "file")})
Expect(err).ToNot(HaveOccurred())

opts := cmd.Opts.(*DeployOpts)
Expand Down
3 changes: 2 additions & 1 deletion common/util/file_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
boshsys "github.com/cloudfoundry/bosh-utils/system"
gopath "path"
"path/filepath"
"strings"
)
Expand Down Expand Up @@ -29,7 +30,7 @@ func AbsolutifyPath(pathToManifest string, pathToFile string, fs boshsys.FileSys
absPath = filepath.Join(filepath.Dir(pathToManifest), pathToFile)
} else {
pathToFile = strings.Replace(pathToFile, "file://", "", 1)
absPath = filepath.Join(filepath.Dir(pathToManifest), pathToFile)
absPath = gopath.Join(gopath.Dir(pathToManifest), pathToFile)
absPath = "file://" + absPath
}

Expand Down
2 changes: 1 addition & 1 deletion common/util/file_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var _ = Describe("AbsolutifyPath", func() {
It("makes the file path relative to the manifest directory", func() {
fakeFilePath = "fake/relative/path/file.tgz"
result, err := util.AbsolutifyPath(fakeManifestPath, fakeFilePath, realfs)
Expect(result).To(Equal("/fake/manifest/path/fake/relative/path/file.tgz"))
Expect(result).To(Equal(filepath.Join("/", "fake", "manifest", "path", "fake", "relative", "path", "file.tgz")))
Expect(err).ToNot(HaveOccurred())
})
})
Expand Down
4 changes: 2 additions & 2 deletions config/legacy_deployment_state_migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package config

import (
"github.com/pivotal-golang/yaml"
"path"
"path/filepath"
"regexp"

bosherr "github.com/cloudfoundry/bosh-utils/errors"
Expand Down Expand Up @@ -164,5 +164,5 @@ type instance struct {
}

func LegacyDeploymentStatePath(deploymentManifestPath string) string {
return path.Join(path.Dir(deploymentManifestPath), "bosh-deployments.yml")
return filepath.Join(filepath.Dir(deploymentManifestPath), "bosh-deployments.yml")
}
9 changes: 5 additions & 4 deletions crypto/digest_calculator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package crypto_test

import (
"errors"
"path/filepath"

fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/onsi/ginkgo"
Expand All @@ -26,14 +27,14 @@ var _ = Describe("Sha1Calculator", func() {
Describe("Calculate", func() {
Context("when path is a file", func() {
BeforeEach(func() {
fs.RegisterOpenFile("/fake-archived-templates-path", &fakesys.FakeFile{
fs.RegisterOpenFile(filepath.Join("/", "fake-archived-templates-path"), &fakesys.FakeFile{
Contents: []byte("fake-archive-contents"),
Stats: &fakesys.FakeFileStats{FileType: fakesys.FakeFileTypeFile},
})
})

It("returns sha1 of the file", func() {
sha1, err := digestCalculator.Calculate("/fake-archived-templates-path")
sha1, err := digestCalculator.Calculate(filepath.Join("/", "fake-archived-templates-path"))
Expect(err).ToNot(HaveOccurred())
Expect(sha1).To(Equal("4603db250d7b5b78dfe17869649784353177b549"))
})
Expand All @@ -45,7 +46,7 @@ var _ = Describe("Sha1Calculator", func() {
boshcrypto.DigestAlgorithmSHA256,
})

multipleDigestStr, err := digestCalculator.Calculate("/fake-archived-templates-path")
multipleDigestStr, err := digestCalculator.Calculate(filepath.Join("/", "fake-archived-templates-path"))
Expect(err).ToNot(HaveOccurred())
Expect(multipleDigestStr).To(Equal("4603db250d7b5b78dfe17869649784353177b549;sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"))
})
Expand All @@ -57,7 +58,7 @@ var _ = Describe("Sha1Calculator", func() {
})

It("returns an error", func() {
_, err := digestCalculator.Calculate("/fake-archived-templates-path")
_, err := digestCalculator.Calculate(filepath.Join("/", "fake-archived-templates-path"))
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-open-file-error"))
})
Expand Down
3 changes: 1 addition & 2 deletions installation/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package installation

import (
"fmt"
"path"
"path/filepath"

"github.com/cloudfoundry/bosh-cli/installation/blobextract"
Expand Down Expand Up @@ -124,7 +123,7 @@ func (i *installer) installJob(renderedJobRef RenderedJobRef, stage biui.Stage)
return bosherr.WrapErrorf(stageErr, "Extracting blob with ID '%s'", renderedJobRef.BlobstoreID)
}

stageErr = i.blobExtractor.ChmodExecutables(path.Join(jobDir, "bin", "*"))
stageErr = i.blobExtractor.ChmodExecutables(filepath.Join(jobDir, "bin", "*"))
if stageErr != nil {
return bosherr.WrapErrorf(stageErr, "Chmoding binaries for '%s'", jobDir)
}
Expand Down
5 changes: 2 additions & 3 deletions installation/pkg/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pkg

import (
"os"
"path"
"path/filepath"

"github.com/cloudfoundry/bosh-cli/installation/blobextract"
Expand Down Expand Up @@ -80,7 +79,7 @@ func (c *compiler) Compile(pkg birelpkg.Compilable) (bistatepkg.CompiledPackageR

c.logger.Debug(c.logTag, "Compiling package '%s/%s'", pkg.Name(), pkg.Fingerprint())

installDir := path.Join(c.packagesDir, pkg.Name())
installDir := filepath.Join(c.packagesDir, pkg.Name())

err = c.fileSystem.MkdirAll(installDir, os.ModePerm)
if err != nil {
Expand All @@ -89,7 +88,7 @@ func (c *compiler) Compile(pkg birelpkg.Compilable) (bistatepkg.CompiledPackageR

packageSrcDir := pkg.(*birelpkg.Package).ExtractedPath()

if !c.fileSystem.FileExists(path.Join(packageSrcDir, "packaging")) {
if !c.fileSystem.FileExists(filepath.Join(packageSrcDir, "packaging")) {
return record, isCompiledPackage, bosherr.Errorf("Packaging script for package '%s' not found", pkg.Name())
}

Expand Down
Loading

0 comments on commit 84b4d14

Please sign in to comment.