本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem类的典型用法代码示例。如果您正苦于以下问题:Golang FakeFileSystem类的具体用法?Golang FakeFileSystem怎么用?Golang FakeFileSystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FakeFileSystem类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
Describe("compiledPackageApplier", func() {
var (
packagesBc *fakebc.FakeBundleCollection
blobstore *fakeblob.FakeBlobstore
compressor *fakecmd.FakeCompressor
fs *fakesys.FakeFileSystem
logger boshlog.Logger
applier Applier
)
BeforeEach(func() {
packagesBc = fakebc.NewFakeBundleCollection()
blobstore = fakeblob.NewFakeBlobstore()
compressor = fakecmd.NewFakeCompressor()
fs = fakesys.NewFakeFileSystem()
logger = boshlog.NewLogger(boshlog.LevelNone)
applier = NewCompiledPackageApplier(packagesBc, true, blobstore, compressor, fs, logger)
})
Describe("Prepare & Apply", func() {
var (
pkg models.Package
bundle *fakebc.FakeBundle
)
BeforeEach(func() {
pkg, bundle = buildPkg(packagesBc)
})
ItInstallsPkg := func(act func() error) {
It("returns error when installing package fails", func() {
bundle.InstallError = errors.New("fake-install-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-install-error"))
})
It("downloads and later cleans up downloaded package blob", func() {
blobstore.GetFileName = "/fake-blobstore-file-name"
err := act()
Expect(err).ToNot(HaveOccurred())
Expect(blobstore.GetBlobIDs[0]).To(Equal("fake-blobstore-id"))
Expect(blobstore.GetFingerprints[0]).To(Equal("fake-blob-sha1"))
// downloaded file is cleaned up
Expect(blobstore.CleanUpFileName).To(Equal("/fake-blobstore-file-name"))
})
It("returns error when downloading package blob fails", func() {
blobstore.GetError = errors.New("fake-get-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-get-error"))
})
It("decompresses package blob to tmp path and later cleans it up", func() {
fs.TempDirDir = "/fake-tmp-dir"
blobstore.GetFileName = "/fake-blobstore-file-name"
var tmpDirExistsBeforeInstall bool
bundle.InstallCallBack = func() {
tmpDirExistsBeforeInstall = true
}
err := act()
Expect(err).ToNot(HaveOccurred())
Expect(compressor.DecompressFileToDirTarballPaths[0]).To(Equal("/fake-blobstore-file-name"))
Expect(compressor.DecompressFileToDirDirs[0]).To(Equal("/fake-tmp-dir"))
// tmp dir exists before bundle install
Expect(tmpDirExistsBeforeInstall).To(BeTrue())
// tmp dir is cleaned up after install
Expect(fs.FileExists(fs.TempDirDir)).To(BeFalse())
})
It("returns error when temporary directory creation fails", func() {
fs.TempDirError = errors.New("fake-filesystem-tempdir-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-filesystem-tempdir-error"))
})
It("returns error when decompressing package blob fails", func() {
compressor.DecompressFileToDirErr = errors.New("fake-decompress-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-decompress-error"))
})
It("installs bundle from decompressed tmp path of a package blob", func() {
fs.TempDirDir = "/fake-tmp-dir"
//.........这里部分代码省略.........
开发者ID:viovanov,项目名称:bosh-agent,代码行数:101,代码来源:compiled_package_applier_test.go
示例2:
import (
"encoding/json"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/gomega"
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
. "github.com/cloudfoundry/bosh-agent/infrastructure"
)
var _ = Describe("FileRegistry", func() {
var (
fs *fakesys.FakeFileSystem
fileRegistry Registry
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
fileRegistry = NewFileRegistry("/fake-registry-file-path", fs)
})
Describe("GetSettings", func() {
Context("when the registry file exists", func() {
var (
expectedSettings boshsettings.Settings
)
BeforeEach(func() {
expectedSettings = boshsettings.Settings{
开发者ID:tacgomes,项目名称:bosh-agent,代码行数:31,代码来源:file_registry_test.go
示例3: JobChange
jobNextState string
jobNextStateErr error
}
func (p fakeParams) JobChange() (change string) { return p.jobChange }
func (p fakeParams) HashChange() (change string) { return p.hashChange }
func (p fakeParams) UpdatedPackages() (pkgs []string) { return p.updatedPackages }
func (p fakeParams) JobState() (string, error) { return p.jobState, p.jobStateErr }
func (p fakeParams) JobNextState() (string, error) { return p.jobNextState, p.jobNextStateErr }
var _ = Describe("ConcreteScript", func() {
var (
runner *fakesys.FakeCmdRunner
fs *fakesys.FakeFileSystem
script ConcreteScript
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
runner = fakesys.NewFakeCmdRunner()
script = NewConcreteScript(fs, runner, "/fake/script")
})
Describe("Run", func() {
var (
params fakeParams
)
BeforeEach(func() {
开发者ID:viovanov,项目名称:bosh-agent,代码行数:30,代码来源:concrete_script_test.go
示例4:
package infrastructure_test
import (
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/infrastructure"
boshlog "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
)
var _ = Describe("FileMetadataService", func() {
var (
fs *fakesys.FakeFileSystem
metadataService MetadataService
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
logger := boshlog.NewLogger(boshlog.LevelNone)
metadataService = NewFileMetadataService(
"fake-metadata-file-path",
"fake-userdata-file-path",
"fake-settings-file-path",
fs,
logger,
)
})
Describe("GetInstanceID", func() {
开发者ID:viovanov,项目名称:bosh-agent,代码行数:31,代码来源:file_metadata_service_test.go
示例5: describeLinuxPlatform
func describeLinuxPlatform() {
var (
collector *fakestats.FakeCollector
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
diskManager *fakedisk.FakeDiskManager
dirProvider boshdirs.Provider
devicePathResolver *fakedpresolv.FakeDevicePathResolver
platform Platform
cdutil *fakedevutil.FakeDeviceUtil
compressor boshcmd.Compressor
copier boshcmd.Copier
vitalsService boshvitals.Service
netManager *fakenet.FakeManager
certManager *fakecert.FakeManager
monitRetryStrategy *fakeretry.FakeRetryStrategy
fakeDefaultNetworkResolver *fakenet.FakeDefaultNetworkResolver
options LinuxOptions
logger boshlog.Logger
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LevelNone)
collector = &fakestats.FakeCollector{}
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
diskManager = fakedisk.NewFakeDiskManager()
dirProvider = boshdirs.NewProvider("/fake-dir")
cdutil = fakedevutil.NewFakeDeviceUtil()
compressor = boshcmd.NewTarballCompressor(cmdRunner, fs)
copier = boshcmd.NewCpCopier(cmdRunner, fs, logger)
vitalsService = boshvitals.NewService(collector, dirProvider)
netManager = &fakenet.FakeManager{}
certManager = new(fakecert.FakeManager)
monitRetryStrategy = fakeretry.NewFakeRetryStrategy()
devicePathResolver = fakedpresolv.NewFakeDevicePathResolver()
fakeDefaultNetworkResolver = &fakenet.FakeDefaultNetworkResolver{}
options = LinuxOptions{}
fs.SetGlob("/sys/bus/scsi/devices/*:0:0:0/block/*", []string{
"/sys/bus/scsi/devices/0:0:0:0/block/sr0",
"/sys/bus/scsi/devices/6:0:0:0/block/sdd",
"/sys/bus/scsi/devices/fake-host-id:0:0:0/block/sda",
})
fs.SetGlob("/sys/bus/scsi/devices/fake-host-id:0:fake-disk-id:0/block/*", []string{
"/sys/bus/scsi/devices/fake-host-id:0:fake-disk-id:0/block/sdf",
})
})
JustBeforeEach(func() {
platform = NewLinuxPlatform(
fs,
cmdRunner,
collector,
compressor,
copier,
dirProvider,
vitalsService,
cdutil,
diskManager,
netManager,
certManager,
monitRetryStrategy,
devicePathResolver,
5*time.Millisecond,
options,
logger,
fakeDefaultNetworkResolver,
)
})
Describe("SetupRuntimeConfiguration", func() {
It("setups runtime configuration", func() {
err := platform.SetupRuntimeConfiguration()
Expect(err).NotTo(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(1))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"bosh-agent-rc"}))
})
})
Describe("CreateUser", func() {
It("creates user", func() {
expectedUseradd := []string{
"useradd",
"-m",
"-b", "/some/path/to/home",
"-s", "/bin/bash",
"-p", "bar-pwd",
"foo-user",
}
err := platform.CreateUser("foo-user", "bar-pwd", "/some/path/to/home")
Expect(err).NotTo(HaveOccurred())
basePathStat := fs.GetFileTestStat("/some/path/to/home")
Expect(basePathStat.FileType).To(Equal(fakesys.FakeFileTypeDir))
//.........这里部分代码省略.........
开发者ID:guoger,项目名称:bosh-agent,代码行数:101,代码来源:linux_platform_test.go
示例6:
boshalert "github.com/cloudfoundry/bosh-agent/agent/alert"
boshlog "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/cloudfoundry/bosh-agent/jobsupervisor"
boshmonit "github.com/cloudfoundry/bosh-agent/jobsupervisor/monit"
fakemonit "github.com/cloudfoundry/bosh-agent/jobsupervisor/monit/fakes"
boshdir "github.com/cloudfoundry/bosh-agent/settings/directories"
)
var _ = Describe("monitJobSupervisor", func() {
var (
fs *fakesys.FakeFileSystem
runner *fakesys.FakeCmdRunner
client *fakemonit.FakeMonitClient
logger boshlog.Logger
dirProvider boshdir.Provider
jobFailuresServerPort int
monit JobSupervisor
)
var jobFailureServerPort = 5000
getJobFailureServerPort := func() int {
jobFailureServerPort++
return jobFailureServerPort
}
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
runner = fakesys.NewFakeCmdRunner()
开发者ID:viovanov,项目名称:bosh-agent,代码行数:30,代码来源:monit_job_supervisor_test.go
示例7: BundleName
boshlog "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
)
type testBundle struct {
Name string
Version string
}
func (s testBundle) BundleName() string { return s.Name }
func (s testBundle) BundleVersion() string { return s.Version }
var _ = Describe("FileBundleCollection", func() {
var (
fs *fakesys.FakeFileSystem
logger boshlog.Logger
fileBundleCollection FileBundleCollection
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
logger = boshlog.NewLogger(boshlog.LevelNone)
fileBundleCollection = NewFileBundleCollection(
"/fake-collection-path/data",
"/fake-collection-path",
"fake-collection-name",
fs,
logger,
)
})
开发者ID:viovanov,项目名称:bosh-agent,代码行数:30,代码来源:file_bundle_collection_test.go
示例8:
import (
"time"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/gomega"
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
. "github.com/cloudfoundry/bosh-agent/infrastructure/devicepathresolver"
)
var _ = Describe("VSphere Path Resolver", func() {
var (
fs *fakesys.FakeFileSystem
resolver DevicePathResolver
diskSettings boshsettings.DiskSettings
)
const sleepInterval = time.Millisecond * 1
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
resolver = NewScsiDevicePathResolver(sleepInterval, fs)
fs.SetGlob("/sys/bus/scsi/devices/*:0:0:0/block/*", []string{
"/sys/bus/scsi/devices/0:0:0:0/block/sr0",
"/sys/bus/scsi/devices/6:0:0:0/block/sdd",
"/sys/bus/scsi/devices/fake-host-id:0:0:0/block/sda",
})
开发者ID:viovanov,项目名称:bosh-agent,代码行数:30,代码来源:scsi_device_path_resolver_test.go
示例9: init
func init() {
Describe("renderedJobApplier", func() {
var (
jobsBc *fakebc.FakeBundleCollection
jobSupervisor *fakejobsuper.FakeJobSupervisor
packageApplierProvider *fakepackages.FakeApplierProvider
blobstore *fakeblob.FakeBlobstore
compressor *fakecmd.FakeCompressor
fs *fakesys.FakeFileSystem
applier Applier
)
BeforeEach(func() {
jobsBc = fakebc.NewFakeBundleCollection()
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
packageApplierProvider = fakepackages.NewFakeApplierProvider()
blobstore = fakeblob.NewFakeBlobstore()
fs = fakesys.NewFakeFileSystem()
compressor = fakecmd.NewFakeCompressor()
logger := boshlog.NewLogger(boshlog.LevelNone)
applier = NewRenderedJobApplier(
jobsBc,
jobSupervisor,
packageApplierProvider,
blobstore,
compressor,
fs,
logger,
)
})
Describe("Prepare & Apply", func() {
var (
job models.Job
bundle *fakebc.FakeBundle
)
BeforeEach(func() {
job, bundle = buildJob(jobsBc)
})
ItInstallsJob := func(act func() error) {
BeforeEach(func() {
fs.TempDirDir = "/fake-tmp-dir"
})
It("returns error when installing job fails", func() {
bundle.InstallError = errors.New("fake-install-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-install-error"))
})
It("downloads and later cleans up downloaded job template blob", func() {
blobstore.GetFileName = "/fake-blobstore-file-name"
err := act()
Expect(err).ToNot(HaveOccurred())
Expect(blobstore.GetBlobIDs[0]).To(Equal("fake-blobstore-id"))
Expect(blobstore.GetFingerprints[0]).To(Equal("fake-blob-sha1"))
// downloaded file is cleaned up
Expect(blobstore.CleanUpFileName).To(Equal("/fake-blobstore-file-name"))
})
It("returns error when downloading job template blob fails", func() {
blobstore.GetError = errors.New("fake-get-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-get-error"))
})
It("decompresses job template blob to tmp path and later cleans it up", func() {
blobstore.GetFileName = "/fake-blobstore-file-name"
var tmpDirExistsBeforeInstall bool
bundle.InstallCallBack = func() {
tmpDirExistsBeforeInstall = true
}
err := act()
Expect(err).ToNot(HaveOccurred())
Expect(compressor.DecompressFileToDirTarballPaths[0]).To(Equal("/fake-blobstore-file-name"))
Expect(compressor.DecompressFileToDirDirs[0]).To(Equal("/fake-tmp-dir"))
// tmp dir exists before bundle install
Expect(tmpDirExistsBeforeInstall).To(BeTrue())
// tmp dir is cleaned up after install
Expect(fs.FileExists(fs.TempDirDir)).To(BeFalse())
})
It("returns error when temporary directory creation fails", func() {
fs.TempDirError = errors.New("fake-filesystem-tempdir-error")
//.........这里部分代码省略.........
开发者ID:viovanov,项目名称:bosh-agent,代码行数:101,代码来源:rendered_job_applier_test.go
示例10: GetInterfaceName
)
type failingInterfaceAddress struct{}
func (ia failingInterfaceAddress) GetInterfaceName() string { return "eth0" }
func (ia failingInterfaceAddress) GetIP() (string, error) {
return "", errors.New("fake-get-ip-err")
}
var _ = Describe("arping", func() {
const arpingIterations = 6
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
arping AddressBroadcaster
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
logger := boshlog.NewLogger(boshlog.LevelNone)
arping = NewArping(cmdRunner, fs, logger, arpingIterations, 0, 0)
})
Describe("BroadcastMACAddresses", func() {
BeforeEach(func() {
fs.WriteFile("/sys/class/net/eth0", []byte{})
fs.WriteFile("/sys/class/net/eth1", []byte{})
})
开发者ID:viovanov,项目名称:bosh-agent,代码行数:31,代码来源:arping_test.go
示例11:
})
It("returns an empty slice for an empty string", func() {
result := cert.SplitCerts("")
Expect(len(result)).To(Equal(0))
})
It("returns an empty slice for an non-empty string that does not contain any certificates", func() {
result := cert.SplitCerts("abcdefghij")
Expect(len(result)).To(Equal(0))
})
})
Describe("DeleteFile()", func() {
var (
fakeFs *fakesys.FakeFileSystem
)
BeforeEach(func() {
fakeFs = fakesys.NewFakeFileSystem()
})
It("only deletes the files with the given prefix", func() {
fakeFs.WriteFileString("/path/to/delete/stuff/in/delete_me_1.foo", "goodbye")
fakeFs.WriteFileString("/path/to/delete/stuff/in/delete_me_2.foo", "goodbye")
fakeFs.WriteFileString("/path/to/delete/stuff/in/different_file_1.bar", "goodbye")
fakeFs.SetGlob("/path/to/delete/stuff/in/delete_me_*", []string{
"/path/to/delete/stuff/in/delete_me_1.foo",
"/path/to/delete/stuff/in/delete_me_2.foo",
})
count, err := cert.DeleteFiles(fakeFs, "/path/to/delete/stuff/in/", "delete_me_")
开发者ID:viovanov,项目名称:bosh-agent,代码行数:31,代码来源:cert_manager_test.go
示例12:
import (
"errors"
"os"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/agent/cmdrunner"
boshsys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system"
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
)
var _ = Describe("FileLoggingCmdRunner", func() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
cmd boshsys.Command
runner CmdRunner
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
runner = NewFileLoggingCmdRunner(fs, cmdRunner, "/fake-base-dir", 15)
cmd = boshsys.Command{
Name: "fake-cmd",
Args: []string{"fake-args"},
Env: map[string]string{"fake-env-key": "fake-env-var"},
WorkingDir: "/fake-working-dir",
}
})
开发者ID:viovanov,项目名称:bosh-agent,代码行数:32,代码来源:file_logging_cmd_runner_test.go
示例13:
package disk_test
import (
"errors"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/gomega"
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/cloudfoundry/bosh-agent/platform/disk"
)
var _ = Describe("procMountsSearcher", func() {
var (
fs *fakesys.FakeFileSystem
searcher MountsSearcher
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
searcher = NewProcMountsSearcher(fs)
})
Describe("SearchMounts", func() {
Context("when reading /proc/mounts succeeds", func() {
It("returns parsed mount information", func() {
fs.WriteFileString(
"/proc/mounts",
`none /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
none /run/shm tmpfs rw,nosuid,nodev,relatime 0 0
/dev/sda1 /boot ext2 rw,relatime,errors=continue 0 0
开发者ID:viovanov,项目名称:bosh-agent,代码行数:31,代码来源:proc_mounts_searcher_test.go
示例14:
package app
import (
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/gomega"
boshinf "github.com/cloudfoundry/bosh-agent/infrastructure"
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
boshplatform "github.com/cloudfoundry/bosh-agent/platform"
)
var _ = Describe("LoadConfigFromPath", func() {
var (
fs *fakesys.FakeFileSystem
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
})
It("returns populates config", func() {
fs.WriteFileString("/fake-config.conf", `{
"Platform": {
"Linux": {
"UseDefaultTmpDir": true,
"UsePreformattedPersistentDisk": true,
"BindMountPersistentDisk": true,
"DevicePathResolutionType": "virtio"
}
},
"Infrastructure": {
开发者ID:viovanov,项目名称:bosh-agent,代码行数:31,代码来源:config_test.go
示例15:
import (
"errors"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/blobstore"
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
fakeuuid "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/uuid/fakes"
)
var _ = Describe("localBlobstore", func() {
var (
fs *fakesys.FakeFileSystem
uuidGen *fakeuuid.FakeGenerator
fakeBlobstorePath = "/some/local/path"
blobstore Blobstore
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
uuidGen = &fakeuuid.FakeGenerator{}
options := map[string]interface{}{"blobstore_path": fakeBlobstorePath}
blobstore = NewLocalBlobstore(fs, uuidGen, options)
})
Describe("Validate", func() {
It("returns no error when blobstore_path is present", func() {
err := blobstore.Validate()
Expect(err).ToNot(HaveOccurred())
})
开发者ID:pivotal-nader-ziada,项目名称:bosh-agent,代码行数:32,代码来源:local_blobstore_test.go
示例16: init
func init() {
Describe("settingsService", func() {
var (
fs *fakesys.FakeFileSystem
fakeDefaultNetworkResolver *fakenet.FakeDefaultNetworkResolver
fakeSettingsSource *fakes.FakeSettingsSource
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
fakeDefaultNetworkResolver = &fakenet.FakeDefaultNetworkResolver{}
fakeSettingsSource = &fakes.FakeSettingsSource{}
})
buildService := func() (Service, *fakesys.FakeFileSystem) {
logger := boshlog.NewLogger(boshlog.LevelNone)
service := NewService(fs, "/setting/path.json", fakeSettingsSource, fakeDefaultNetworkResolver, logger)
return service, fs
}
Describe("LoadSettings", func() {
var (
fetchedSettings Settings
fetcherFuncErr error
service Service
)
BeforeEach(func() {
fetchedSettings = Settings{}
fetcherFuncErr = nil
})
JustBeforeEach(func() {
fakeSettingsSource.SettingsValue = fetchedSettings
fakeSettingsSource.SettingsErr = fetcherFuncErr
service, fs = buildService()
})
Context("when settings fetcher succeeds fetching settings", func() {
BeforeEach(func() {
fetchedSettings = Settings{AgentID: "some-new-agent-id"}
})
Context("when settings contain at most one dynamic network", func() {
BeforeEach(func() {
fetchedSettings.Networks = Networks{
"fake-net-1": Network{Type: NetworkTypeDynamic},
}
})
It("updates the service with settings from the fetcher", func() {
err := service.LoadSettings()
Expect(err).NotTo(HaveOccurred())
Expect(service.GetSettings().AgentID).To(Equal("some-new-agent-id"))
})
It("persists settings to the settings file", func() {
err := service.LoadSettings()
Expect(err).NotTo(HaveOccurred())
json, err := json.Marshal(fetchedSettings)
Expect(err).NotTo(HaveOccurred())
fileContent, err := fs.ReadFile("/setting/path.json")
Expect(err).NotTo(HaveOccurred())
Expect(fileContent).To(Equal(json))
})
It("returns any error from writing to the setting file", func() {
fs.WriteFileError = errors.New("fs-write-file-error")
err := service.LoadSettings()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fs-write-file-error"))
})
})
})
Context("when settings fetcher fails fetching settings", func() {
BeforeEach(func() {
fetcherFuncErr = errors.New("fake-fetch-error")
})
Context("when a settings file exists", func() {
Context("when settings contain at most one dynamic network", func() {
BeforeEach(func() {
fs.WriteFile("/setting/path.json", []byte(`{
"agent_id":"some-agent-id",
"networks": {"fake-net-1": {"type": "dynamic"}}
}`))
fakeDefaultNetworkResolver.GetDefaultNetworkNetwork = Network{
IP: "fake-resolved-ip",
Netmask: "fake-resolved-netmask",
Gateway: "fake-resolved-gateway",
}
})
It("returns settings from the settings file with resolved network", func() {
err := service.LoadSettings()
//.........这里部分代码省略.........
开发者ID:viovanov,项目名称:bosh-agent,代码行数:101,代码来源:service_test.go
示例17: describeUbuntuNetManager
func describeUbuntuNetManager() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
ipResolver *fakeip.FakeResolver
addressBroadcaster *fakearp.FakeAddressBroadcaster
netManager UbuntuNetManager
interfaceConfigurationCreator InterfaceConfigurationCreator
)
writeNetworkDevice := func(iface string, macAddress string, isPhysical bool) string {
interfacePath := fmt.Sprintf("/sys/class/net/%s", iface)
fs.WriteFile(interfacePath, []byte{})
if isPhysical {
fs.WriteFile(fmt.Sprintf("/sys/class/net/%s/device", iface), []byte{})
}
fs.WriteFileString(fmt.Sprintf("/sys/class/net/%s/address", iface), fmt.Sprintf("%s\n", macAddress))
return interfacePath
}
stubInterfacesWithVirtual := func(physicalInterfaces map[string]boshsettings.Network, virtualInterfaces []string) {
interfacePaths := []string{}
for iface, networkSettings := range physicalInterfaces {
interfacePaths = append(interfacePaths, writeNetworkDevice(iface, networkSettings.Mac, true))
}
for _, iface := range virtualInterfaces {
interfacePaths = append(interfacePaths, writeNetworkDevice(iface, "virtual", false))
}
fs.SetGlob("/sys/class/net/*", interfacePaths)
}
stubInterfaces := func(physicalInterfaces map[string]boshsettings.Network) {
stubInterfacesWithVirtual(physicalInterfaces, nil)
}
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
ipResolver = &fakeip.FakeResolver{}
logger := boshlog.NewLogger(boshlog.LevelNone)
interfaceConfigurationCreator = NewInterfaceConfigurationCreator(logger)
addressBroadcaster = &fakearp.FakeAddressBroadcaster{}
netManager = NewUbuntuNetManager(
fs,
cmdRunner,
ipResolver,
interfaceConfigurationCreator,
addressBroadcaster,
logger,
).(UbuntuNetManager)
})
Describe("ComputeNetworkConfig", func() {
Context("when there is one manual network and neither is marked as default for DNS", func() {
It("should use the manual network for DNS", func() {
networks := boshsettings.Networks{
"manual": factory.Network{DNS: &[]string{"8.8.8.8"}}.Build(),
}
stubInterfaces(networks)
_, _, dnsServers, err := netManager.ComputeNetworkConfig(networks)
Expect(err).ToNot(HaveOccurred())
Expect(dnsServers).To(Equal([]string{"8.8.8.8"}))
})
})
Context("when there is a vip network and a manual network and neither is marked as default for DNS", func() {
It("should use the manual network for DNS", func() {
networks := boshsettings.Networks{
"vip": boshsettings.Network{Type: "vip"},
"manual": factory.Network{Type: "manual", DNS: &[]string{"8.8.8.8"}}.Build(),
}
stubInterfaces(networks)
_, _, dnsServers, err := netManager.ComputeNetworkConfig(networks)
Expect(err).ToNot(HaveOccurred())
Expect(dnsServers).To(Equal([]string{"8.8.8.8"}))
})
})
Context("when there is a vip network and a manual network and the manual network is marked as default for DNS", func() {
It("should use the manual network for DNS", func() {
networks := boshsettings.Networks{
"vip": boshsettings.Network{Type: "vip"},
"manual": factory.Network{Type: "manual", DNS: &[]string{"8.8.8.8"}, Default: []string{"dns"}}.Build(),
}
stubInterfaces(networks)
_, _, dnsServers, err := netManager.ComputeNetworkConfig(networks)
Expect(err).ToNot(HaveOccurred())
Expect(dnsServers).To(Equal([]string{"8.8.8.8"}))
})
})
Context("when specified more than one DNS", func() {
It("extracts all DNS servers from the network configured as default DNS", func() {
networks := boshsettings.Networks{
"default": factory.Network{
IP: "10.10.0.32",
Netmask: "255.255.255.0",
//.........这里部分代码省略.........
开发者ID:viovanov,项目名称:bosh-agent,代码行数:101,代码来源:ubuntu_net_manager_test.go
示例18:
import (
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/gomega"
boshlog "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
boshcdrom "github.com/cloudfoundry/bosh-agent/platform/cdrom"
fakecdrom "github.com/cloudfoundry/bosh-agent/platform/cdrom/fakes"
boshdevutil "github.com/cloudfoundry/bosh-agent/platform/deviceutil"
)
var _ = Describe("Cdutil", func() {
var (
fs *fakesys.FakeFileSystem
cdrom *fakecdrom.FakeCdrom
cdutil boshdevutil.DeviceUtil
logger boshlog.Logger
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cdrom = fakecdrom.NewFakeCdrom(fs, "env", "fake env contents")
logger = boshlog.NewLogger(boshlog.LevelNone)
})
JustBeforeEach(func() {
cdutil = boshcdrom.NewCdUtil("/fake/settings/dir", fs, cdrom, logger)
})
It("gets file contents from CDROM", func() {
contents, err := cdutil.GetFilesContents([]string{"env"})
开发者ID:viovanov,项目名称:bosh-agent,代码行数:31,代码来源:cdutil_test.go
示例19: init
func init() {
Describe("concreteCompiler", func() {
var (
compiler Compiler
compressor *fakecmd.FakeCompressor
blobstore *fakeblobstore.FakeBlobstore
fs *fakesys.FakeFileSystem
runner *fakecmdrunner.FakeFileLoggingCmdRunner
packageApplier *fakepackages.FakeApplier
packagesBc *fakebc.FakeBundleCollection
)
BeforeEach(func() {
compressor = fakecmd.NewFakeCompressor()
blobstore = &fakeblobstore.FakeBlobstore{}
fs = fakesys.NewFakeFileSystem()
runner = fakecmdrunner.NewFakeFileLoggingCmdRunner()
packageApplier = fakepackages.NewFakeApplier()
packagesBc = fakebc.NewFakeBundleCollection()
compiler = NewConcreteCompiler(
compressor,
blobstore,
fs,
runner,
FakeCompileDirProvider{Dir: "/fake-compile-dir"},
packageApplier,
packagesBc,
)
})
BeforeEach(func() {
fs.MkdirAll("/fake-compile-dir", os.ModePerm)
})
Describe("Compile", func() {
var (
bundle *fakebc.FakeBundle
pkg Package
pkgDeps []boshmodels.Package
)
BeforeEach(func() {
bundle = packagesBc.FakeGet(boshmodels.Package{
Name: "pkg_name",
Version: "pkg_version",
})
bundle.InstallPath = "/fake-dir/data/packages/pkg_name/pkg_version"
bundle.EnablePath = "/fake-dir/packages/pkg_name"
compressor.CompressFilesInDirTarballPath = "/tmp/compressed-compiled-package"
pkg, pkgDeps = getCompileArgs()
})
It("returns blob id and sha1 of created compiled package", func() {
blobstore.CreateBlobID = "fake-blob-id"
blobstore.CreateFingerprint = "fake-blob-sha1"
blobID, sha1, err := compiler.Compile(pkg, pkgDeps)
Expect(err).ToNot(HaveOccurred())
Expect(blobID).To(Equal("fake-blob-id"))
Expect(sha1).To(Equal("fake-blob-sha1"))
})
It("cleans up all packages before and after applying dependent packages", func() {
_, _, err := compiler.Compile(pkg, pkgDeps)
Expect(err).ToNot(HaveOccurred())
Expect(packageApplier.ActionsCalled).To(Equal([]string{"KeepOnly", "Apply", "Apply", "KeepOnly"}))
Expect(packageApplier.KeptOnlyPackages).To(BeEmpty())
})
It("returns an error if cleaning up packages fails", func() {
packageApplier.KeepOnlyErr = errors.New("fake-keep-only-error")
_, _, err := compiler.Compile(pkg, pkgDeps)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-keep-only-error"))
})
It("fetches source package from blobstore without checking SHA1 by default because of Director bug", func() {
_, _, err := compiler.Compile(pkg, pkgDeps)
Expect(err).ToNot(HaveOccurred())
Expect(blobstore.GetBlobIDs[0]).To(Equal("blobstore_id"))
Expect(blobstore.GetFingerprints[0]).To(Equal(""))
})
PIt("(Pending Tracker Story: <https://www.pivotaltracker.com/story/show/94524232>) fetches source package from blobstore and checks SHA1 by default in future", func() {
_, _, err := compiler.Compile(pkg, pkgDeps)
Expect(err).ToNot(HaveOccurred())
Expect(blobstore.GetBlobIDs[0]).To(Equal("blobstore_id"))
Expect(blobstore.GetFingerprints[0]).To(Equal("sha1"))
})
It("returns an error if removing compile target directory during uncompression fails", func() {
fs.RegisterRemoveAllError("/fake-compile-dir/pkg_name", errors.New("fake-remove-error"))
//.........这里部分代码省略.........
开发者ID:viovanov,项目名称:bosh-agent,代码行数:101,代码来源:concrete_compiler_test.go
示例20: describeCentosNetManager
func describeCentosNetManager() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
ipResolver *fakeip.FakeResolver
addressBroadcaster *fakearp.FakeAddressBroadcaster
netManager Manager
interfaceConfigurationCreator InterfaceConfigurationCreator
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
ipResolver = &fakeip.FakeResolver{}
logger := boshlog.NewLogger(boshlog.LevelNone)
interfaceConfigurationCreator = NewInterfaceConfigurationCreator(logger)
addressBroadcaster = &fakearp.FakeAddressBroadcaster{}
netManager = NewCentosNetManager(
fs,
cmdRunner,
ipResolver,
interfaceConfigurationCreator,
addressBroadcaster,
logger,
)
})
writeNetworkDevice := func(iface string, macAddress string, isPhysical bool) string {
interfacePath := fmt.Sprintf("/sys/class/net/%s", iface)
fs.WriteFile(interfacePath, []byte{})
if isPhysical {
fs.WriteFile(fmt.Sprintf("/sys/class/net/%s/device", iface), []byte{})
}
fs.WriteFileString(fmt.Sprintf("/sys/class/net/%s/address", iface), fmt.Sprintf("%s\n", macAddres
|
请发表评论