本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/system/fakes.FakeFileSystem类的典型用法代码示例。如果您正苦于以下问题:Golang FakeFileSystem类的具体用法?Golang FakeFileSystem怎么用?Golang FakeFileSystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FakeFileSystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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{})
})
示例2: init
func init() {
Describe("concretePackageApplier", func() {
var (
packagesBc *fakebc.FakeBundleCollection
blobstore *fakeblob.FakeBlobstore
compressor *fakecmd.FakeCompressor
fs *fakesys.FakeFileSystem
logger boshlog.Logger
applier PackageApplier
)
BeforeEach(func() {
packagesBc = fakebc.NewFakeBundleCollection()
blobstore = fakeblob.NewFakeBlobstore()
compressor = fakecmd.NewFakeCompressor()
fs = fakesys.NewFakeFileSystem()
logger = boshlog.NewLogger(boshlog.LevelNone)
applier = NewConcretePackageApplier(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"
//.........这里部分代码省略.........
示例3:
boshalert "github.com/cloudfoundry/bosh-agent/agent/alert"
. "github.com/cloudfoundry/bosh-agent/jobsupervisor"
boshmonit "github.com/cloudfoundry/bosh-agent/jobsupervisor/monit"
fakemonit "github.com/cloudfoundry/bosh-agent/jobsupervisor/monit/fakes"
boshlog "github.com/cloudfoundry/bosh-agent/logger"
boshdir "github.com/cloudfoundry/bosh-agent/settings/directories"
fakesys "github.com/cloudfoundry/bosh-agent/system/fakes"
)
var _ = Describe("monitJobSupervisor", func() {
var (
fs *fakesys.FakeFileSystem
runner *fakesys.FakeCmdRunner
client *fakemonit.FakeMonitClient
logger boshlog.Logger
dirProvider boshdir.DirectoriesProvider
jobFailuresServerPort int
monit JobSupervisor
)
var jobFailureServerPort = 5000
getJobFailureServerPort := func() int {
jobFailureServerPort++
return jobFailureServerPort
}
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
runner = fakesys.NewFakeCmdRunner()
示例4:
import (
"errors"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/agent/cmdrunner"
boshsys "github.com/cloudfoundry/bosh-agent/system"
fakesys "github.com/cloudfoundry/bosh-agent/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",
}
})
示例5:
package devicepathresolver_test
import (
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/infrastructure/devicepathresolver"
fakesys "github.com/cloudfoundry/bosh-agent/system/fakes"
)
var _ = Describe("VSphere Path Resolver", func() {
var (
fs *fakesys.FakeFileSystem
resolver DevicePathResolver
)
const sleepInterval = time.Millisecond * 1
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
resolver = NewVsphereDevicePathResolver(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",
})
fs.SetGlob("/sys/bus/scsi/devices/fake-host-id:0:fake-disk-id:0/block/*", []string{
示例6: init
func init() {
Describe("concreteV1Service", func() {
var (
fs *fakesys.FakeFileSystem
specPath = "/spec.json"
service V1Service
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
service = NewConcreteV1Service(fs, specPath)
})
Describe("Get", func() {
Context("when filesystem has a spec file", func() {
BeforeEach(func() {
fs.WriteFileString(specPath, `{"deployment":"fake-deployment-name"}`)
})
It("reads spec from filesystem", func() {
spec, err := service.Get()
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{Deployment: "fake-deployment-name"}))
})
It("returns error if reading spec from filesystem errs", func() {
fs.ReadFileError = errors.New("fake-read-error")
spec, err := service.Get()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-read-error"))
Expect(spec).To(Equal(V1ApplySpec{}))
})
})
Context("when filesystem does not have a spec file", func() {
It("reads spec from filesystem", func() {
spec, err := service.Get()
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{}))
})
})
})
Describe("Set", func() {
newSpec := V1ApplySpec{Deployment: "fake-deployment-name"}
It("writes spec to filesystem", func() {
err := service.Set(newSpec)
Expect(err).ToNot(HaveOccurred())
specPathStats := fs.GetFileTestStat(specPath)
Expect(specPathStats).ToNot(BeNil())
boshassert.MatchesJSONBytes(GinkgoT(), newSpec, specPathStats.Content)
})
It("returns error if writing spec to filesystem errs", func() {
fs.WriteToFileError = errors.New("fake-write-error")
err := service.Set(newSpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-write-error"))
})
})
Describe("PopulateDynamicNetworks", func() {
Context("when there are no dynamic networks", func() {
unresolvedSpec := V1ApplySpec{
Deployment: "fake-deployment",
NetworkSpecs: map[string]NetworkSpec{
"fake-net": NetworkSpec{
Fields: map[string]interface{}{"ip": "fake-net-ip"},
},
},
}
It("returns spec without modifying any networks", func() {
spec, err := service.PopulateDynamicNetworks(unresolvedSpec, boshsettings.Settings{})
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{
Deployment: "fake-deployment",
NetworkSpecs: map[string]NetworkSpec{
"fake-net": NetworkSpec{
Fields: map[string]interface{}{"ip": "fake-net-ip"},
},
},
}))
})
})
Context("when there are dynamic networks", func() {
unresolvedSpec := V1ApplySpec{
Deployment: "fake-deployment",
NetworkSpecs: map[string]NetworkSpec{
"fake-net1": NetworkSpec{
Fields: map[string]interface{}{
"ip": "fake-net1-ip",
"netmask": "fake-net1-netmask",
"gateway": "fake-net1-gateway",
},
//.........这里部分代码省略.........
示例7:
package disk_test
import (
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/platform/disk"
fakesys "github.com/cloudfoundry/bosh-agent/system/fakes"
)
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
示例8: JobChange
jobNextState string
jobNextStateErr error
}
func (p fakeDrainParams) JobChange() (change string) { return p.jobChange }
func (p fakeDrainParams) HashChange() (change string) { return p.hashChange }
func (p fakeDrainParams) UpdatedPackages() (pkgs []string) { return p.updatedPackages }
func (p fakeDrainParams) JobState() (string, error) { return p.jobState, p.jobStateErr }
func (p fakeDrainParams) JobNextState() (string, error) { return p.jobNextState, p.jobNextStateErr }
var _ = Describe("ConcreteDrainScript", func() {
var (
runner *fakesys.FakeCmdRunner
fs *fakesys.FakeFileSystem
drainScript ConcreteDrainScript
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
runner = fakesys.NewFakeCmdRunner()
drainScript = NewConcreteDrainScript(fs, runner, "/fake/script")
})
Describe("Run", func() {
var (
params fakeDrainParams
)
BeforeEach(func() {
示例9:
boshlog "github.com/cloudfoundry/bosh-agent/logger"
. "github.com/cloudfoundry/bosh-agent/platform/net"
fakearp "github.com/cloudfoundry/bosh-agent/platform/net/arp/fakes"
fakenet "github.com/cloudfoundry/bosh-agent/platform/net/fakes"
boship "github.com/cloudfoundry/bosh-agent/platform/net/ip"
fakeip "github.com/cloudfoundry/bosh-agent/platform/net/ip/fakes"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
fakesys "github.com/cloudfoundry/bosh-agent/system/fakes"
)
var _ = Describe("centosNetManager", func() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
defaultNetworkResolver *fakenet.FakeDefaultNetworkResolver
ipResolver *fakeip.FakeIPResolver
addressBroadcaster *fakearp.FakeAddressBroadcaster
netManager NetManager
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
defaultNetworkResolver = &fakenet.FakeDefaultNetworkResolver{}
ipResolver = &fakeip.FakeIPResolver{}
addressBroadcaster = &fakearp.FakeAddressBroadcaster{}
logger := boshlog.NewLogger(boshlog.LevelNone)
netManager = NewCentosNetManager(
fs,
cmdRunner,
defaultNetworkResolver,
示例10:
package cdutil_test
import (
fakecdrom "github.com/cloudfoundry/bosh-agent/platform/cdrom/fakes"
. "github.com/cloudfoundry/bosh-agent/platform/cdutil"
fakesys "github.com/cloudfoundry/bosh-agent/system/fakes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Cdutil", func() {
var (
fs *fakesys.FakeFileSystem
cdrom *fakecdrom.FakeCdrom
cdutil CdUtil
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cdrom = fakecdrom.NewFakeCdrom(fs, "env", "fake env contents")
})
JustBeforeEach(func() {
cdutil = NewCdUtil("/fake/settings/dir", fs, cdrom)
})
It("gets file contents from CDROM", func() {
contents, err := cdutil.GetFileContents("env")
Expect(err).NotTo(HaveOccurred())
Expect(cdrom.Mounted).To(Equal(false))
示例11:
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
boshassert "github.com/cloudfoundry/bosh-agent/assert"
. "github.com/cloudfoundry/bosh-agent/blobstore"
boshdir "github.com/cloudfoundry/bosh-agent/settings/directories"
fakesys "github.com/cloudfoundry/bosh-agent/system/fakes"
fakeuuid "github.com/cloudfoundry/bosh-agent/uuid/fakes"
)
var _ = Describe("externalBlobstore", func() {
var (
fs *fakesys.FakeFileSystem
runner *fakesys.FakeCmdRunner
uuidGen *fakeuuid.FakeGenerator
configPath string
blobstore Blobstore
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
runner = fakesys.NewFakeCmdRunner()
uuidGen = &fakeuuid.FakeGenerator{}
dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")
configPath = filepath.Join(dirProvider.EtcDir(), "blobstore-fake-provider.json")
blobstore = NewExternalBlobstore("fake-provider", map[string]interface{}{}, fs, runner, uuidGen, configPath)
})
Describe("Validate", func() {
It("external validate writes config file", func() {
示例12:
import (
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/blobstore"
fakesys "github.com/cloudfoundry/bosh-agent/system/fakes"
fakeuuid "github.com/cloudfoundry/bosh-agent/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())
})
示例13:
"errors"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/agent/applier/bundlecollection"
boshlog "github.com/cloudfoundry/bosh-agent/logger"
fakesys "github.com/cloudfoundry/bosh-agent/system/fakes"
)
var _ = Describe("FileBundle", func() {
var (
fs *fakesys.FakeFileSystem
logger boshlog.Logger
sourcePath string
installPath string
enablePath string
fileBundle FileBundle
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
installPath = "/install-path"
enablePath = "/enable-path"
logger = boshlog.NewLogger(boshlog.LevelNone)
fileBundle = NewFileBundle(installPath, enablePath, fs, logger)
})
createSourcePath := func() string {
path := "/source-path"
err := fs.MkdirAll(path, os.ModePerm)
示例14: BundleName
boshlog "github.com/cloudfoundry/bosh-agent/logger"
fakesys "github.com/cloudfoundry/bosh-agent/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,
)
})
示例15:
boshlog "github.com/cloudfoundry/bosh-agent/logger"
. "github.com/cloudfoundry/bosh-agent/platform/net"
fakearp "github.com/cloudfoundry/bosh-agent/platform/net/arp/fakes"
fakenet "github.com/cloudfoundry/bosh-agent/platform/net/fakes"
boship "github.com/cloudfoundry/bosh-agent/platform/net/ip"
fakeip "github.com/cloudfoundry/bosh-agent/platform/net/ip/fakes"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
fakesys "github.com/cloudfoundry/bosh-agent/system/fakes"
)
var _ = Describe("ubuntuNetManager", func() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
defaultNetworkResolver *fakenet.FakeDefaultNetworkResolver
ipResolver *fakeip.FakeIPResolver
addressBroadcaster *fakearp.FakeAddressBroadcaster
netManager NetManager
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
defaultNetworkResolver = &fakenet.FakeDefaultNetworkResolver{}
ipResolver = &fakeip.FakeIPResolver{}
addressBroadcaster = &fakearp.FakeAddressBroadcaster{}
logger := boshlog.NewLogger(boshlog.LevelNone)
netManager = NewUbuntuNetManager(
fs,
cmdRunner,
defaultNetworkResolver,