Skip to content

Commit

Permalink
Fix issues preventing unit tests from passing on Windows
Browse files Browse the repository at this point in the history
Signed-off-by: Shatarupa Nandi <snandi@pivotal.io>
  • Loading branch information
Ben Moss authored and benmoss committed Dec 16, 2015
1 parent 2e0bb27 commit 8a5c6ee
Show file tree
Hide file tree
Showing 25 changed files with 100 additions and 99 deletions.
4 changes: 2 additions & 2 deletions agent/action/run_errand.go
Expand Up @@ -2,7 +2,7 @@ package action

import (
"errors"
"path/filepath"
"path"
"time"

boshas "github.com/cloudfoundry/bosh-agent/agent/applier/applyspec"
Expand Down Expand Up @@ -65,7 +65,7 @@ func (a RunErrandAction) Run() (ErrandResult, error) {
}

command := boshsys.Command{
Name: filepath.Join(a.jobsDir, currentSpec.JobSpec.Template, "bin", "run"),
Name: path.Join(a.jobsDir, currentSpec.JobSpec.Template, "bin", "run"),
Env: map[string]string{
"PATH": "/usr/sbin:/usr/bin:/sbin:/bin",
},
Expand Down
4 changes: 2 additions & 2 deletions agent/action/ssh.go
Expand Up @@ -2,7 +2,7 @@ package action

import (
"errors"
"path/filepath"
"path"

boshplatform "github.com/cloudfoundry/bosh-agent/platform"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
Expand Down Expand Up @@ -71,7 +71,7 @@ func (a SSHAction) Run(cmd string, params SSHParams) (SSHResult, error) {
func (a SSHAction) setupSSH(params SSHParams) (SSHResult, error) {
var result SSHResult

boshSSHPath := filepath.Join(a.dirProvider.BaseDir(), "bosh_ssh")
boshSSHPath := path.Join(a.dirProvider.BaseDir(), "bosh_ssh")

err := a.platform.CreateUser(params.User, params.Password, boshSSHPath)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion agent/applier/bundlecollection/file_bundle.go
Expand Up @@ -2,6 +2,7 @@ package bundlecollection

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

bosherr "github.com/cloudfoundry/bosh-utils/errors"
Expand Down Expand Up @@ -43,7 +44,7 @@ func (b FileBundle) Install(sourcePath string) (boshsys.FileSystem, string, erro
return nil, "", bosherr.WrapError(err, "Setting permissions on source directory")
}

err = b.fs.MkdirAll(filepath.Dir(b.installPath), installDirsPerms)
err = b.fs.MkdirAll(path.Dir(b.installPath), installDirsPerms)
if err != nil {
return nil, "", bosherr.WrapError(err, "Creating parent installation directory")
}
Expand Down
18 changes: 9 additions & 9 deletions agent/applier/bundlecollection/file_bundle_collection.go
@@ -1,7 +1,7 @@
package bundlecollection

import (
"path/filepath"
"path"

bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
Expand All @@ -16,18 +16,18 @@ type fileBundleDefinition struct {
}

func newFileBundleDefinition(installPath string) fileBundleDefinition {
cleanInstallPath := filepath.Clean(installPath) // no trailing slash
cleanInstallPath := path.Clean(installPath) // no trailing slash

// If the path is empty, Base returns ".".
// If the path consists entirely of separators, Base returns a single separator.

name := filepath.Base(filepath.Dir(cleanInstallPath))
if name == "." || name == string(filepath.Separator) {
name := path.Base(path.Dir(cleanInstallPath))
if name == "." || name == string("/") {
name = ""
}

version := filepath.Base(cleanInstallPath)
if version == "." || version == string(filepath.Separator) {
version := path.Base(cleanInstallPath)
if version == "." || version == string("/") {
version = ""
}

Expand Down Expand Up @@ -68,15 +68,15 @@ func (bc FileBundleCollection) Get(definition BundleDefinition) (Bundle, error)
return nil, bosherr.Error("Missing bundle version")
}

installPath := filepath.Join(bc.installPath, bc.name, definition.BundleName(), definition.BundleVersion())
enablePath := filepath.Join(bc.enablePath, bc.name, definition.BundleName())
installPath := path.Join(bc.installPath, bc.name, definition.BundleName(), definition.BundleVersion())
enablePath := path.Join(bc.enablePath, bc.name, definition.BundleName())
return NewFileBundle(installPath, enablePath, bc.fs, bc.logger), nil
}

func (bc FileBundleCollection) List() ([]Bundle, error) {
var bundles []Bundle

bundleInstallPaths, err := bc.fs.Glob(filepath.Join(bc.installPath, bc.name, "*", "*"))
bundleInstallPaths, err := bc.fs.Glob(path.Join(bc.installPath, bc.name, "*", "*"))
if err != nil {
return bundles, bosherr.WrapError(err, "Globbing bundles")
}
Expand Down
14 changes: 7 additions & 7 deletions agent/applier/jobs/rendered_job_applier.go
Expand Up @@ -3,7 +3,7 @@ package jobs
import (
"fmt"
"os"
"path/filepath"
"path"
"strings"

boshbc "github.com/cloudfoundry/bosh-agent/agent/applier/bundlecollection"
Expand Down Expand Up @@ -121,8 +121,8 @@ func (s *renderedJobApplier) downloadAndInstall(job models.Job, jobBundle boshbc
return bosherr.WrapError(err, "Decompressing files to temp dir")
}

binPath := filepath.Join(tmpDir, job.Source.PathInArchive, "bin") + "/"
err = s.fs.Walk(filepath.Join(tmpDir, job.Source.PathInArchive), func(path string, info os.FileInfo, err error) error {
binPath := path.Join(tmpDir, job.Source.PathInArchive, "bin") + "/"
err = s.fs.Walk(path.Join(tmpDir, job.Source.PathInArchive), func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
} else if info.IsDir() || strings.HasPrefix(path, binPath) {
Expand All @@ -135,7 +135,7 @@ func (s *renderedJobApplier) downloadAndInstall(job models.Job, jobBundle boshbc
return bosherr.WrapError(err, "Correcting file permissions")
}

_, _, err = jobBundle.Install(filepath.Join(tmpDir, job.Source.PathInArchive))
_, _, err = jobBundle.Install(path.Join(tmpDir, job.Source.PathInArchive))
if err != nil {
return bosherr.WrapError(err, "Installing job bundle")
}
Expand Down Expand Up @@ -178,7 +178,7 @@ func (s *renderedJobApplier) Configure(job models.Job, jobIndex int) (err error)
return
}

monitFilePath := filepath.Join(jobDir, "monit")
monitFilePath := path.Join(jobDir, "monit")
if fs.FileExists(monitFilePath) {
err = s.jobSupervisor.AddJob(job.Name, jobIndex, monitFilePath)
if err != nil {
Expand All @@ -187,14 +187,14 @@ func (s *renderedJobApplier) Configure(job models.Job, jobIndex int) (err error)
}
}

monitFilePaths, err := fs.Glob(filepath.Join(jobDir, "*.monit"))
monitFilePaths, err := fs.Glob(path.Join(jobDir, "*.monit"))
if err != nil {
err = bosherr.WrapError(err, "Looking for additional monit files")
return
}

for _, monitFilePath := range monitFilePaths {
label := strings.Replace(filepath.Base(monitFilePath), ".monit", "", 1)
label := strings.Replace(path.Base(monitFilePath), ".monit", "", 1)
subJobName := fmt.Sprintf("%s_%s", job.Name, label)

err = s.jobSupervisor.AddJob(subJobName, jobIndex, monitFilePath)
Expand Down
4 changes: 2 additions & 2 deletions agent/applier/packages/compiled_package_applier_provider.go
@@ -1,7 +1,7 @@
package packages

import (
"path/filepath"
"path"

boshbc "github.com/cloudfoundry/bosh-agent/agent/applier/bundlecollection"
boshblob "github.com/cloudfoundry/bosh-utils/blobstore"
Expand Down Expand Up @@ -50,7 +50,7 @@ func (p compiledPackageApplierProvider) Root() Applier {
// JobSpecific provides package applier that operates on job-specific packages.
// (e.g manages /var/vcap/jobs/job-name/packages/pkg-a -> /var/vcap/data/packages/pkg-a)
func (p compiledPackageApplierProvider) JobSpecific(jobName string) Applier {
enablePath := filepath.Join(p.jobSpecificEnablePath, jobName)
enablePath := path.Join(p.jobSpecificEnablePath, jobName)
packagesBc := boshbc.NewFileBundleCollection(p.installPath, enablePath, p.name, p.fs, p.logger)
return NewCompiledPackageApplier(packagesBc, false, p.blobstore, p.compressor, p.fs, p.logger)
}
Expand Down
8 changes: 4 additions & 4 deletions agent/cmdrunner/file_logging_cmd_runner.go
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"fmt"
"os"
"path/filepath"
"path"
"unicode/utf8"

bosherr "github.com/cloudfoundry/bosh-utils/errors"
Expand Down Expand Up @@ -62,7 +62,7 @@ func NewFileLoggingCmdRunner(
}

func (f FileLoggingCmdRunner) RunCommand(jobName string, taskName string, cmd boshsys.Command) (*CmdResult, error) {
logsDir := filepath.Join(f.baseDir, jobName)
logsDir := path.Join(f.baseDir, jobName)

err := f.fs.RemoveAll(logsDir)
if err != nil {
Expand All @@ -74,8 +74,8 @@ func (f FileLoggingCmdRunner) RunCommand(jobName string, taskName string, cmd bo
return nil, bosherr.WrapErrorf(err, "Creating log dir for job %s", jobName)
}

stdoutPath := filepath.Join(logsDir, fmt.Sprintf("%s.stdout.log", taskName))
stderrPath := filepath.Join(logsDir, fmt.Sprintf("%s.stderr.log", taskName))
stdoutPath := path.Join(logsDir, fmt.Sprintf("%s.stdout.log", taskName))
stderrPath := path.Join(logsDir, fmt.Sprintf("%s.stderr.log", taskName))

stdoutFile, err := f.fs.OpenFile(stdoutPath, fileOpenFlag, fileOpenPerm)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions agent/compiler/concrete_compiler.go
Expand Up @@ -3,7 +3,7 @@ package compiler
import (
"fmt"
"os"
"path/filepath"
"path"

boshbc "github.com/cloudfoundry/bosh-agent/agent/applier/bundlecollection"
boshmodels "github.com/cloudfoundry/bosh-agent/agent/applier/models"
Expand Down Expand Up @@ -62,7 +62,7 @@ func (c concreteCompiler) Compile(pkg Package, deps []boshmodels.Package) (strin
}
}

compilePath := filepath.Join(c.compileDirProvider.CompileDir(), pkg.Name)
compilePath := path.Join(c.compileDirProvider.CompileDir(), pkg.Name)
err = c.fetchAndUncompress(pkg, compilePath)
if err != nil {
return "", "", bosherr.WrapErrorf(err, "Fetching package %s", pkg.Name)
Expand Down Expand Up @@ -92,7 +92,7 @@ func (c concreteCompiler) Compile(pkg Package, deps []boshmodels.Package) (strin
return "", "", bosherr.WrapError(err, "Enabling new package bundle")
}

scriptPath := filepath.Join(compilePath, "packaging")
scriptPath := path.Join(compilePath, "packaging")

if c.fs.FileExists(scriptPath) {
command := boshsys.Command{
Expand Down
5 changes: 3 additions & 2 deletions agent/script/concrete_job_script_provider.go
Expand Up @@ -2,6 +2,7 @@ package script

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

"github.com/pivotal-golang/clock"
Expand Down Expand Up @@ -37,7 +38,7 @@ func NewConcreteJobScriptProvider(
}

func (p ConcreteJobScriptProvider) NewScript(jobName string, scriptName string) Script {
path := filepath.Join(p.dirProvider.JobBinDir(jobName), scriptName)
path := path.Join(p.dirProvider.JobBinDir(jobName), scriptName)

stdoutLogFilename := fmt.Sprintf("%s.stdout.log", scriptName)
stdoutLogPath := filepath.Join(p.dirProvider.LogsDir(), jobName, stdoutLogFilename)
Expand All @@ -49,7 +50,7 @@ func (p ConcreteJobScriptProvider) NewScript(jobName string, scriptName string)
}

func (p ConcreteJobScriptProvider) NewDrainScript(jobName string, params boshdrain.ScriptParams) CancellableScript {
path := filepath.Join(p.dirProvider.JobsDir(), jobName, "bin", "drain")
path := path.Join(p.dirProvider.JobsDir(), jobName, "bin", "drain")

return boshdrain.NewConcreteScript(p.fs, p.cmdRunner, jobName, path, params, p.timeService, p.logger)
}
Expand Down
4 changes: 2 additions & 2 deletions agent/task/concrete_manager.go
Expand Up @@ -2,7 +2,7 @@ package task

import (
"encoding/json"
"path/filepath"
"path"

bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
Expand All @@ -20,7 +20,7 @@ func (provider concreteManagerProvider) NewManager(
fs boshsys.FileSystem,
dir string,
) Manager {
return NewManager(logger, fs, filepath.Join(dir, "tasks.json"))
return NewManager(logger, fs, path.Join(dir, "tasks.json"))
}

type concreteManager struct {
Expand Down
5 changes: 5 additions & 0 deletions app/app_test.go
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -26,6 +27,10 @@ func init() {
)

BeforeEach(func() {
if runtime.GOOS == "windows" {
Skip("Pending on Windows")
}

var err error

baseDir, err = ioutil.TempDir("", "go-agent-test")
Expand Down
6 changes: 2 additions & 4 deletions infrastructure/devicepathresolver/id_device_path_resolver.go
Expand Up @@ -2,8 +2,7 @@ package devicepathresolver

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

boshudev "github.com/cloudfoundry/bosh-agent/platform/udevdevice"
Expand Down Expand Up @@ -63,8 +62,7 @@ func (idpr idDevicePathResolver) GetRealDevicePath(diskSettings boshsettings.Dis

time.Sleep(100 * time.Millisecond)

deviceIDPath := filepath.Join(string(os.PathSeparator), "dev", "disk", "by-id", fmt.Sprintf("virtio-%s", diskID))

deviceIDPath := path.Join("/", "dev", "disk", "by-id", fmt.Sprintf("virtio-%s", diskID))
realPath, err = idpr.fs.ReadLink(deviceIDPath)
if err != nil {
continue
Expand Down
6 changes: 3 additions & 3 deletions jobsupervisor/monit_job_supervisor.go
Expand Up @@ -2,7 +2,7 @@ package jobsupervisor

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

"github.com/pivotal/go-smtpd/smtpd"
Expand Down Expand Up @@ -238,7 +238,7 @@ func (m monitJobSupervisor) getIncarnation() (int, error) {

func (m monitJobSupervisor) AddJob(jobName string, jobIndex int, configPath string) error {
targetFilename := fmt.Sprintf("%04d_%s.monitrc", jobIndex, jobName)
targetConfigPath := filepath.Join(m.dirProvider.MonitJobsDir(), targetFilename)
targetConfigPath := path.Join(m.dirProvider.MonitJobsDir(), targetFilename)

configContent, err := m.fs.ReadFile(configPath)
if err != nil {
Expand Down Expand Up @@ -280,5 +280,5 @@ func (m monitJobSupervisor) MonitorJobFailures(handler JobFailureHandler) (err e
}

func (m monitJobSupervisor) stoppedFilePath() string {
return filepath.Join(m.dirProvider.MonitDir(), "stopped")
return path.Join(m.dirProvider.MonitDir(), "stopped")
}
4 changes: 2 additions & 2 deletions platform/disk/diskutil.go
@@ -1,7 +1,7 @@
package disk

import (
"path/filepath"
"path"

boshdevutil "github.com/cloudfoundry/bosh-agent/platform/deviceutil"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
Expand Down Expand Up @@ -53,7 +53,7 @@ func (util diskUtil) GetFilesContents(fileNames []string) ([][]byte, error) {
contents := [][]byte{}

for _, fileName := range fileNames {
diskFilePath := filepath.Join(tempDir, fileName)
diskFilePath := path.Join(tempDir, fileName)

util.logger.Debug(util.logTag, "Reading contents of '%s'", diskFilePath)

Expand Down
4 changes: 2 additions & 2 deletions platform/dummy_platform.go
Expand Up @@ -2,7 +2,7 @@ package platform

import (
"encoding/json"
"path/filepath"
"path"

boshdpresolv "github.com/cloudfoundry/bosh-agent/infrastructure/devicepathresolver"
boshcert "github.com/cloudfoundry/bosh-agent/platform/cert"
Expand Down Expand Up @@ -198,7 +198,7 @@ func (p dummyPlatform) PrepareForNetworkingChange() error {
func (p dummyPlatform) GetDefaultNetwork() (boshsettings.Network, error) {
var network boshsettings.Network

networkPath := filepath.Join(p.dirProvider.BoshDir(), "dummy-default-network-settings.json")
networkPath := path.Join(p.dirProvider.BoshDir(), "dummy-default-network-settings.json")
contents, err := p.fs.ReadFile(networkPath)
if err != nil {
return network, nil
Expand Down
4 changes: 2 additions & 2 deletions platform/fakes/fake_platform.go
@@ -1,7 +1,7 @@
package fakes

import (
"path/filepath"
"path"

boshdpresolv "github.com/cloudfoundry/bosh-agent/infrastructure/devicepathresolver"
fakedpresolv "github.com/cloudfoundry/bosh-agent/infrastructure/devicepathresolver/fakes"
Expand Down Expand Up @@ -301,7 +301,7 @@ func (p *FakePlatform) GetFilesContentsFromDisk(diskPath string, fileNames []str

result := [][]byte{}
for _, fileName := range fileNames {
fileDiskPath := filepath.Join(diskPath, fileName)
fileDiskPath := path.Join(diskPath, fileName)
err := p.GetFileContentsFromDiskErrs[fileDiskPath]
if err != nil {
return [][]byte{}, err
Expand Down

0 comments on commit 8a5c6ee

Please sign in to comment.