本文整理汇总了Golang中github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem类的典型用法代码示例。如果您正苦于以下问题:Golang FakeFileSystem类的具体用法?Golang FakeFileSystem怎么用?Golang FakeFileSystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FakeFileSystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
package disk_test
import (
"errors"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-agent/platform/disk"
fakesys "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/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
示例2:
"errors"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-init/release"
fakecmd "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/fileutil/fakes"
fakesys "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
bireljob "github.com/cloudfoundry/bosh-init/release/job"
birelpkg "github.com/cloudfoundry/bosh-init/release/pkg"
)
var _ = Describe("tarReader", func() {
var (
reader Reader
fakeFs *fakesys.FakeFileSystem
compressor *fakecmd.FakeCompressor
)
BeforeEach(func() {
fakeFs = fakesys.NewFakeFileSystem()
compressor = fakecmd.NewFakeCompressor()
reader = NewReader("/some/release.tgz", "/extracted/release", fakeFs, compressor)
})
Describe("Read", func() {
Context("when the given release archive is a valid tar", func() {
Context("when the release manifest is valid", func() {
BeforeEach(func() {
fakeFs.WriteFileString(
"/extracted/release/release.MF",
示例3:
var (
fs *fakesys.FakeFileSystem
logger boshlog.Logger
releaseManager birel.Manager
mockCpiInstaller *mock_install.MockInstaller
mockCpiUninstaller *mock_install.MockUninstaller
mockInstallerFactory *mock_install.MockInstallerFactory
mockCloudFactory *mock_cloud.MockFactory
mockReleaseExtractor *mock_release.MockExtractor
fakeUUIDGenerator *fakeuuid.FakeGenerator
setupDeploymentStateService biconfig.DeploymentStateService
fakeInstallation *fakecmd.FakeInstallation
fakeUI *fakeui.FakeUI
mockBlobstoreFactory *mock_blobstore.MockFactory
mockBlobstore *mock_blobstore.MockBlobstore
mockDeploymentManagerFactory *mock_deployment.MockManagerFactory
mockDeploymentManager *mock_deployment.MockManager
mockDeployment *mock_deployment.MockDeployment
mockAgentClient *mock_agentclient.MockAgentClient
mockAgentClientFactory *mock_httpagent.MockAgentClientFactory
mockCloud *mock_cloud.MockCloud
fakeStage *fakebiui.FakeStage
directorID string
deploymentManifestPath = "/deployment-dir/fake-deployment-manifest.yml"
deploymentStatePath string
expectCPIExtractRelease *gomock.Call
expectCPIInstall *gomock.Call
expectNewCloud *gomock.Call
mbusURL = "http://fake-mbus-user:[email protected]"
)
示例4: 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",
//.........这里部分代码省略.........
示例5:
var (
fs *fakesys.FakeFileSystem
logger boshlog.Logger
registryServerManager biregistry.ServerManager
releaseManager birel.Manager
mockInstaller *mock_install.MockInstaller
mockInstallerFactory *mock_install.MockInstallerFactory
mockCloudFactory *mock_cloud.MockFactory
mockCloud *mock_cloud.MockCloud
mockAgentClient *mock_agentclient.MockAgentClient
mockAgentClientFactory *mock_httpagent.MockAgentClientFactory
mockReleaseExtractor *mock_release.MockExtractor
mockStateBuilderFactory *mock_instance_state.MockBuilderFactory
mockStateBuilder *mock_instance_state.MockBuilder
mockState *mock_instance_state.MockState
mockBlobstoreFactory *mock_blobstore.MockFactory
mockBlobstore *mock_blobstore.MockBlobstore
fakeStemcellExtractor *fakebistemcell.FakeExtractor
fakeUUIDGenerator *fakeuuid.FakeGenerator
fakeRegistryUUIDGenerator *fakeuuid.FakeGenerator
fakeRepoUUIDGenerator *fakeuuid.FakeGenerator
fakeAgentIDGenerator *fakeuuid.FakeGenerator
fakeSHA1Calculator *fakebicrypto.FakeSha1Calculator
legacyDeploymentStateMigrator biconfig.LegacyDeploymentStateMigrator
deploymentStateService biconfig.DeploymentStateService
vmRepo biconfig.VMRepo
diskRepo biconfig.DiskRepo
stemcellRepo biconfig.StemcellRepo
deploymentRepo biconfig.DeploymentRepo
releaseRepo biconfig.ReleaseRepo
sshTunnelFactory bisshtunnel.Factory
diskManagerFactory bidisk.ManagerFactory
diskDeployer bivm.DiskDeployer
stdOut *gbytes.Buffer
stdErr *gbytes.Buffer
fakeStage *fakebiui.FakeStage
stemcellManagerFactory bistemcell.ManagerFactory
vmManagerFactory bivm.ManagerFactory
applySpec bias.ApplySpec
directorID string
stemcellTarballPath = "/fake-stemcell-release.tgz"
deploymentManifestPath = "/deployment-dir/fake-deployment-manifest.yml"
deploymentStatePath = "/deployment-dir/fake-deployment-manifest-state.json"
stemcellImagePath = "fake-stemcell-image-path"
stemcellCID = "fake-stemcell-cid"
stemcellCloudProperties = biproperty.Map{}
vmCloudProperties = biproperty.Map{}
vmEnv = biproperty.Map{}
diskCloudProperties = biproperty.Map{}
networkInterfaces = map[string]biproperty.Map{
"network-1": biproperty.Map{
"type": "dynamic",
"default": []bideplmanifest.NetworkDefault{"dns", "gateway"},
"cloud_properties": biproperty.Map{},
},
}
agentRunningState = biagentclient.AgentState{JobState: "running"}
mbusURL = "http://fake-mbus-url"
expectHasVM1 *gomock.Call
expectDeleteVM1 *gomock.Call
sshConfig *SSHConfig
)
示例6:
package release_test
import (
fakesys "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/gomega"
bireljob "github.com/cloudfoundry/bosh-init/release/job"
birelpkg "github.com/cloudfoundry/bosh-init/release/pkg"
. "github.com/cloudfoundry/bosh-init/release"
)
var _ = Describe("Release", func() {
var (
release Release
expectedJob bireljob.Job
fakeFS *fakesys.FakeFileSystem
)
BeforeEach(func() {
expectedJob = bireljob.Job{
Name: "fake-job-name",
}
fakeFS = fakesys.NewFakeFileSystem()
release = NewRelease(
"fake-release-name",
"fake-release-version",
[]bireljob.Job{expectedJob},
[]*birelpkg.Package{},
"fake-extracted-path",
fakeFS,
示例7:
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/gomega"
bireljob "github.com/cloudfoundry/bosh-init/release/job"
bierbrenderer "github.com/cloudfoundry/bosh-init/templatescompiler/erbrenderer"
fakebirender "github.com/cloudfoundry/bosh-init/templatescompiler/erbrenderer/fakes"
. "github.com/cloudfoundry/bosh-init/templatescompiler"
)
var _ = Describe("JobRenderer", func() {
var (
jobRenderer JobRenderer
fakeERBRenderer *fakebirender.FakeERBRenderer
job bireljob.Job
context bierbrenderer.TemplateEvaluationContext
fs *fakesys.FakeFileSystem
jobProperties biproperty.Map
globalProperties biproperty.Map
srcPath string
dstPath string
)
BeforeEach(func() {
srcPath = "fake-src-path"
dstPath = "fake-dst-path"
jobProperties = biproperty.Map{
"fake-property-key": "fake-job-property-value",
}
globalProperties = biproperty.Map{
"fake-property-key": "fake-global-property-value",
示例8:
import (
"errors"
biindex "github.com/cloudfoundry/bosh-init/index"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/gomega"
birelpkg "github.com/cloudfoundry/bosh-init/release/pkg"
fakesys "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/cloudfoundry/bosh-init/state/pkg"
)
var _ = Describe("CompiledPackageRepo", func() {
var (
index biindex.Index
compiledPackageRepo CompiledPackageRepo
fakeFS *fakesys.FakeFileSystem
)
BeforeEach(func() {
fakeFS = fakesys.NewFakeFileSystem()
index = biindex.NewFileIndex("/index_file", fakeFS)
compiledPackageRepo = NewCompiledPackageRepo(index)
})
Context("Save and Find", func() {
var (
record CompiledPackageRecord
dependency birelpkg.Package
pkg birelpkg.Package
)
示例9:
import (
"encoding/json"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/gomega"
boshsettings "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-agent/settings"
fakesys "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/cloudfoundry/bosh-init/internal/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{
示例10:
package crypto_test
import (
"errors"
"os"
. "github.com/cloudfoundry/bosh-init/crypto"
fakesys "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/gomega"
)
var _ = Describe("Sha1Calculator", func() {
var (
fs *fakesys.FakeFileSystem
sha1Calculator SHA1Calculator
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
sha1Calculator = NewSha1Calculator(fs)
})
Describe("Calculate", func() {
Context("when path is directory", func() {
BeforeEach(func() {
fs.RegisterOpenFile("/fake-templates-dir", &fakesys.FakeFile{
Stats: &fakesys.FakeFileStats{FileType: fakesys.FakeFileTypeDir},
})
fs.RegisterOpenFile("/fake-templates-dir/file-1", &fakesys.FakeFile{
示例11:
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/gomega"
boshdevutil "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-agent/platform/deviceutil"
fakedisk "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-agent/platform/disk/fakes"
boshlog "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-agent/platform/disk"
)
var _ = Describe("Diskutil", func() {
var (
diskUtil boshdevutil.DeviceUtil
mounter *fakedisk.FakeMounter
fs *fakesys.FakeFileSystem
)
BeforeEach(func() {
mounter = &fakedisk.FakeMounter{}
fs = fakesys.NewFakeFileSystem()
logger := boshlog.NewLogger(boshlog.LevelNone)
diskUtil = NewDiskUtil("fake-disk-path", mounter, fs, logger)
})
Describe("GetFileContents", func() {
Context("when disk path does not exist", func() {
It("returns an error if diskpath does not exist", func() {
_, err := diskUtil.GetFilesContents([]string{"fake-file-path-1"})
Expect(err).To(HaveOccurred())
示例12:
import (
"errors"
boshlog "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system"
fakesys "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-init/templatescompiler/erbrenderer"
fakebierbrenderer "github.com/cloudfoundry/bosh-init/templatescompiler/erbrenderer/fakes"
)
var _ = Describe("ErbRenderer", func() {
var (
fs *fakesys.FakeFileSystem
runner *fakesys.FakeCmdRunner
erbRenderer ERBRenderer
context *fakebierbrenderer.FakeTemplateEvaluationContext
)
BeforeEach(func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
fs = fakesys.NewFakeFileSystem()
runner = fakesys.NewFakeCmdRunner()
context = &fakebierbrenderer.FakeTemplateEvaluationContext{}
erbRenderer = NewERBRenderer(fs, runner, logger)
fs.TempDirDir = "fake-temp-dir"
})
It("constructs ruby erb rendering command", func() {
err := erbRenderer.Render("fake-src-path", "fake-dst-path", context)
示例13:
boshlog "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/gomega"
birelmanifest "github.com/cloudfoundry/bosh-init/release/manifest"
"github.com/cloudfoundry/bosh-init/release/set/manifest"
"github.com/cloudfoundry/bosh-init/release/set/manifest/fakes"
)
var _ = Describe("Parser", func() {
comboManifestPath := "/path/to/manifest/fake-deployment-manifest"
var (
fakeFs *fakesys.FakeFileSystem
parser manifest.Parser
fakeValidator *fakes.FakeValidator
)
BeforeEach(func() {
fakeFs = fakesys.NewFakeFileSystem()
logger := boshlog.NewLogger(boshlog.LevelNone)
fakeValidator = fakes.NewFakeValidator()
fakeValidator.SetValidateBehavior([]fakes.ValidateOutput{
{Err: nil},
})
parser = manifest.NewParser(fakeFs, logger, fakeValidator)
fakeFs.WriteFileString(comboManifestPath, `
---
releases:
- name: fake-release-name-1
示例14:
})
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_")
示例15:
package infrastructure_test
import (
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-init/internal/github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-agent/infrastructure"
boshsettings "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-agent/settings"
boshlog "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
)
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() {