本文整理汇总了Golang中github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem类的典型用法代码示例。如果您正苦于以下问题:Golang FakeFileSystem类的具体用法?Golang FakeFileSystem怎么用?Golang FakeFileSystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FakeFileSystem类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1:
BeforeEach(func() {
mockCtrl = gomock.NewController(GinkgoT())
})
AfterEach(func() {
mockCtrl.Finish()
})
var (
outBuffer *bytes.Buffer
errBuffer *bytes.Buffer
logger boshlog.Logger
fs *fakeboshsys.FakeFileSystem
mockRenderedJobList *mock_template.MockRenderedJobList
renderedJobListArchivePath string
renderedJobListFingerprint string
renderedJobListArchiveSHA1 string
renderedJobListArchive RenderedJobListArchive
)
BeforeEach(func() {
outBuffer = bytes.NewBufferString("")
errBuffer = bytes.NewBufferString("")
logger = boshlog.NewWriterLogger(boshlog.LevelDebug, outBuffer, errBuffer)
fs = fakeboshsys.NewFakeFileSystem()
mockRenderedJobList = mock_template.NewMockRenderedJobList(mockCtrl)
开发者ID:mattcui,项目名称:bosh-init,代码行数:31,代码来源:rendered_job_list_archive_test.go
示例2:
import (
"errors"
. "github.com/cloudfoundry/bosh-agent/agent/action/state"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/cloudfoundry/bosh-utils/system/fakes"
)
var _ = Describe("SyncDNSState", func() {
var (
localDNSState LocalDNSState
syncDNSState SyncDNSState
fakeFileSystem *fakes.FakeFileSystem
path string
err error
)
BeforeEach(func() {
fakeFileSystem = fakes.NewFakeFileSystem()
path = "/blobstore-dns-records.json"
syncDNSState = NewSyncDNSState(fakeFileSystem, path)
err = nil
localDNSState = LocalDNSState{}
})
Describe("#LoadState", func() {
Context("when there is some failure loading", func() {
Context("when SyncDNSState file cannot be read", func() {
开发者ID:mattcui,项目名称:bosh-agent,代码行数:30,代码来源:sync_dns_state_test.go
示例3:
import (
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/infrastructure"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
fakesys "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() {
开发者ID:mattcui,项目名称:bosh-agent,代码行数:32,代码来源:file_metadata_service_test.go
示例4:
bidisk "github.com/cloudfoundry/bosh-init/deployment/disk"
bideplmanifest "github.com/cloudfoundry/bosh-init/deployment/manifest"
fakebiui "github.com/cloudfoundry/bosh-init/ui/fakes"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
biproperty "github.com/cloudfoundry/bosh-utils/property"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
fakeuuid "github.com/cloudfoundry/bosh-utils/uuid/fakes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Manager", func() {
var (
manager Manager
fakeCloud *fakebicloud.FakeCloud
fakeFs *fakesys.FakeFileSystem
fakeUUIDGenerator *fakeuuid.FakeGenerator
diskRepo biconfig.DiskRepo
)
BeforeEach(func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
fakeFs = fakesys.NewFakeFileSystem()
fakeUUIDGenerator = &fakeuuid.FakeGenerator{}
deploymentStateService := biconfig.NewFileSystemDeploymentStateService(fakeFs, fakeUUIDGenerator, logger, "/fake/path")
diskRepo = biconfig.NewDiskRepo(deploymentStateService, fakeUUIDGenerator)
managerFactory := NewManagerFactory(diskRepo, logger)
fakeCloud = fakebicloud.NewFakeCloud()
manager = managerFactory.NewManager(fakeCloud)
fakeUUIDGenerator.GeneratedUUID = "fake-uuid"
})
开发者ID:mattcui,项目名称:bosh-init,代码行数:31,代码来源:manager_test.go
示例5:
})
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:nimbus-cloud,项目名称:bosh-agent,代码行数:31,代码来源:cert_manager_test.go
示例6:
fakebicrypto "github.com/cloudfoundry/bosh-init/crypto/fakes"
. "github.com/cloudfoundry/bosh-init/installation/tarball"
fakebiui "github.com/cloudfoundry/bosh-init/ui/fakes"
fakebihttpclient "github.com/cloudfoundry/bosh-utils/httpclient/fakes"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Provider", func() {
var (
provider Provider
cache Cache
fs *fakesys.FakeFileSystem
httpClient *fakebihttpclient.FakeHTTPClient
sha1Calculator *fakebicrypto.FakeSha1Calculator
source *fakeSource
fakeStage *fakebiui.FakeStage
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
logger := boshlog.NewLogger(boshlog.LevelNone)
cache = NewCache("/fake-base-path", fs, logger)
sha1Calculator = fakebicrypto.NewFakeSha1Calculator()
httpClient = fakebihttpclient.NewFakeHTTPClient()
provider = NewProvider(cache, fs, httpClient, sha1Calculator, 3, 0, logger)
fakeStage = fakebiui.NewFakeStage()
})
开发者ID:mattcui,项目名称:bosh-init,代码行数:30,代码来源:provider_test.go
示例7:
package app
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
boshinf "github.com/cloudfoundry/bosh-agent/infrastructure"
boshplatform "github.com/cloudfoundry/bosh-agent/platform"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
)
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:EMC-CMD,项目名称:bosh-agent,代码行数:31,代码来源:config_test.go
示例8: rootDesc
func rootDesc() {
var mockCtrl *gomock.Controller
BeforeEach(func() {
mockCtrl = gomock.NewController(GinkgoT())
})
AfterEach(func() {
mockCtrl.Finish()
})
Describe("Run", func() {
var (
command bicmd.Cmd
fakeFs *fakesys.FakeFileSystem
stdOut *gbytes.Buffer
stdErr *gbytes.Buffer
userInterface biui.UI
sha1Calculator crypto.SHA1Calculator
manifestSHA1 string
mockDeployer *mock_deployment.MockDeployer
mockInstaller *mock_install.MockInstaller
mockInstallerFactory *mock_install.MockInstallerFactory
mockReleaseExtractor *mock_release.MockExtractor
releaseManager birel.Manager
mockRegistryServerManager *mock_registry.MockServerManager
mockRegistryServer *mock_registry.MockServer
mockAgentClient *mock_agentclient.MockAgentClient
mockAgentClientFactory *mock_httpagent.MockAgentClientFactory
mockCloudFactory *mock_cloud.MockFactory
fakeCPIRelease *fakebirel.FakeRelease
logger boshlog.Logger
mockBlobstoreFactory *mock_blobstore.MockFactory
mockBlobstore *mock_blobstore.MockBlobstore
mockVMManagerFactory *mock_vm.MockManagerFactory
fakeVMManager *fakebivm.FakeManager
fakeStemcellExtractor *fakebistemcell.FakeExtractor
mockStemcellManager *mock_stemcell.MockManager
fakeStemcellManagerFactory *fakebistemcell.FakeManagerFactory
fakeReleaseSetParser *fakebirelsetmanifest.FakeParser
fakeInstallationParser *fakebiinstallmanifest.FakeParser
fakeDeploymentParser *fakebideplmanifest.FakeParser
mockLegacyDeploymentStateMigrator *mock_config.MockLegacyDeploymentStateMigrator
setupDeploymentStateService biconfig.DeploymentStateService
fakeDeploymentValidator *fakebideplval.FakeValidator
directorID = "generated-director-uuid"
fakeUUIDGenerator *fakeuuid.FakeGenerator
configUUIDGenerator *fakeuuid.FakeGenerator
fakeStage *fakebiui.FakeStage
deploymentManifestPath string
deploymentStatePath string
cpiReleaseTarballPath string
stemcellTarballPath string
extractedStemcell bistemcell.ExtractedStemcell
expectDeploy *gomock.Call
mbusURL = "http://fake-mbus-user:[email protected]"
releaseSetManifest birelsetmanifest.Manifest
boshDeploymentManifest bideplmanifest.Manifest
installationManifest biinstallmanifest.Manifest
cloud bicloud.Cloud
cloudStemcell bistemcell.CloudStemcell
expectLegacyMigrate *gomock.Call
expectStemcellUpload *gomock.Call
expectStemcellDeleteUnused *gomock.Call
expectCPIReleaseExtract *gomock.Call
expectInstall *gomock.Call
expectNewCloud *gomock.Call
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LevelNone)
stdOut = gbytes.NewBuffer()
stdErr = gbytes.NewBuffer()
userInterface = biui.NewWriterUI(stdOut, stdErr, logger)
fakeFs = fakesys.NewFakeFileSystem()
fakeFs.EnableStrictTempRootBehavior()
deploymentManifestPath = "/path/to/manifest.yml"
deploymentStatePath = "/path/to/manifest-state.json"
fakeFs.RegisterOpenFile(deploymentManifestPath, &fakesys.FakeFile{
Stats: &fakesys.FakeFileStats{FileType: fakesys.FakeFileTypeFile},
})
fakeFs.WriteFileString(deploymentManifestPath, "")
mockDeployer = mock_deployment.NewMockDeployer(mockCtrl)
mockInstaller = mock_install.NewMockInstaller(mockCtrl)
mockInstallerFactory = mock_install.NewMockInstallerFactory(mockCtrl)
//.........这里部分代码省略.........
开发者ID:mattcui,项目名称:bosh-init,代码行数:101,代码来源:deploy_cmd_test.go
示例9:
import (
"errors"
"os"
. "github.com/cloudfoundry/bosh-utils/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-utils/internal/github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-utils/blobstore"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
fakeuuid "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:EMC-CMD,项目名称:bosh-agent,代码行数:32,代码来源:local_blobstore_test.go
示例10:
fakeaction "github.com/cloudfoundry/bosh-agent/agent/action/fakes"
"github.com/cloudfoundry/bosh-agent/agent/applier/applyspec"
. "github.com/cloudfoundry/bosh-agent/agent/script/drain"
"github.com/cloudfoundry/bosh-agent/agent/script/drain/fakes"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
)
var _ = Describe("ConcreteScript", func() {
var (
fs *fakesys.FakeFileSystem
runner *fakesys.FakeCmdRunner
params ScriptParams
fakeClock *fakeaction.FakeClock
script ConcreteScript
exampleSpec func() applyspec.V1ApplySpec
scriptCommandFactory boshsys.ScriptCommandFactory
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
runner = fakesys.NewFakeCmdRunner()
params = &fakes.FakeScriptParams{}
fakeClock = &fakeaction.FakeClock{}
scriptCommandFactory = boshsys.NewScriptCommandFactory("linux")
})
JustBeforeEach(func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
开发者ID:yingkitw,项目名称:bosh-agent,代码行数:30,代码来源:concrete_script_test.go
示例11:
bireljob "github.com/cloudfoundry/bosh-init/release/job"
birelpkg "github.com/cloudfoundry/bosh-init/release/pkg"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
fakecmd "github.com/cloudfoundry/bosh-utils/fileutil/fakes"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
fakebirel "github.com/cloudfoundry/bosh-init/release/fakes"
)
var _ = Describe("Extractor", func() {
var (
fakeFS *fakesys.FakeFileSystem
compressor *fakecmd.FakeCompressor
fakeReleaseValidator *fakebirel.FakeValidator
releaseExtractor Extractor
)
BeforeEach(func() {
fakeFS = fakesys.NewFakeFileSystem()
compressor = fakecmd.NewFakeCompressor()
fakeReleaseValidator = fakebirel.NewFakeValidator()
logger := boshlog.NewLogger(boshlog.LevelNone)
releaseExtractor = NewExtractor(fakeFS, compressor, fakeReleaseValidator, logger)
})
Describe("Extract", func() {
var (
releaseTarballPath string
)
开发者ID:mattcui,项目名称:bosh-init,代码行数:31,代码来源:extractor_test.go
示例12: describeCentosNetManager
func describeCentosNetManager() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
ipResolver *fakeip.FakeResolver
interfaceAddrsProvider *fakeip.FakeInterfaceAddressesProvider
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)
interfaceAddrsProvider = &fakeip.FakeInterfaceAddressesProvider{}
interfaceAddrsValidator := boship.NewInterfaceAddressesValidator(interfaceAddrsProvider)
dnsValidator := NewDNSValidator(fs)
addressBroadcaster = &fakearp.FakeAddressBroadcaster{}
netManager = NewCentosNetManager(
fs,
cmdRunner,
ipResolver,
interfaceConfigurationCreator,
interfaceAddrsValidator,
dnsValidator,
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", macAddress))
return interfacePath
}
Describe("SetupNetworking", func() {
var (
dhcpNetwork boshsettings.Network
staticNetwork boshsettings.Network
expectedNetworkConfigurationForStatic string
expectedNetworkConfigurationForDHCP string
expectedDhclientConfiguration string
)
BeforeEach(func() {
dhcpNetwork = boshsettings.Network{
Type: "dynamic",
Default: []string{"dns"},
DNS: []string{"8.8.8.8", "9.9.9.9"},
Mac: "fake-dhcp-mac-address",
}
staticNetwork = boshsettings.Network{
Type: "manual",
IP: "1.2.3.4",
Netmask: "255.255.255.0",
Gateway: "3.4.5.6",
Mac: "fake-static-mac-address",
}
interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("ethstatic", "1.2.3.4"),
}
fs.WriteFileString("/etc/resolv.conf", `
nameserver 8.8.8.8
nameserver 9.9.9.9
`)
expectedNetworkConfigurationForStatic = `DEVICE=ethstatic
BOOTPROTO=static
IPADDR=1.2.3.4
NETMASK=255.255.255.0
BROADCAST=1.2.3.255
GATEWAY=3.4.5.6
ONBOOT=yes
PEERDNS=no
DNS1=8.8.8.8
DNS2=9.9.9.9
`
expectedNetworkConfigurationForDHCP = `DEVICE=ethdhcp
BOOTPROTO=dhcp
ONBOOT=yes
PEERDNS=yes
`
expectedDhclientConfiguration = `# Generated by bosh-agent
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
send host-name "<hostname>";
request subnet-mask, broadcast-address, time-offset, routers,
//.........这里部分代码省略.........
开发者ID:nimbus-cloud,项目名称:bosh-agent,代码行数:101,代码来源:centos_net_manager_test.go
示例13:
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
biconfig "github.com/cloudfoundry/bosh-init/config"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
fakeuuid "github.com/cloudfoundry/bosh-utils/uuid/fakes"
)
var _ = Describe("TargetProvider", func() {
var (
fakeFS *fakesys.FakeFileSystem
fakeUUIDGenerator *fakeuuid.FakeGenerator
logger boshlog.Logger
deploymentStateService biconfig.DeploymentStateService
targetProvider TargetProvider
configPath = "/deployment.json"
installationsRootPath = "/.bosh_init/installations"
)
BeforeEach(func() {
fakeFS = fakesys.NewFakeFileSystem()
fakeUUIDGenerator = fakeuuid.NewFakeGenerator()
logger = boshlog.NewLogger(boshlog.LevelNone)
deploymentStateService = biconfig.NewFileSystemDeploymentStateService(
fakeFS,
fakeUUIDGenerator,
logger,
configPath,
开发者ID:mattcui,项目名称:bosh-init,代码行数:31,代码来源:target_provider_test.go
示例14:
fakenet "github.com/cloudfoundry/bosh-agent/platform/net/fakes"
fakestats "github.com/cloudfoundry/bosh-agent/platform/stats/fakes"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
boshdirs "github.com/cloudfoundry/bosh-agent/settings/directories"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
)
var _ = Describe("WindowsPlatform", func() {
var (
collector *fakestats.FakeCollector
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
dirProvider boshdirs.Provider
netManager *fakenet.FakeManager
devicePathResolver *fakedpresolv.FakeDevicePathResolver
platform Platform
fakeDefaultNetworkResolver *fakenet.FakeDefaultNetworkResolver
certManager *fakecert.FakeManager
logger boshlog.Logger
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LevelNone)
collector = &fakestats.FakeCollector{}
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
dirProvider = boshdirs.NewProvider("/fake-dir")
netManager = &fakenet.FakeManager{}
开发者ID:mattcui,项目名称:bosh-agent,代码行数:31,代码来源:windows_platform_test.go
示例15:
package platform_test
import (
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
platform "github.com/cloudfoundry/bosh-agent/platform"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
)
var _ = Describe("State", func() {
var (
fs *fakesys.FakeFileSystem
path string
s *platform.BootstrapState
err error
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
path = "/agent_state.json"
s, err = platform.NewBootstrapState(fs, path)
Expect(err).NotTo(HaveOccurred())
})
Describe("SaveState", func() {
It("saves the state file with the appropriate properties", func() {
s.Linux = platform.LinuxState{HostsConfigured: true}
s.SaveState()
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:31,代码来源:bootstrap_state_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:EMC-CMD,项目名称:bosh-agent,代码行数:101,代码来源:service_test.go
示例17:
fakeblobstore "github.com/cloudfoundry/bosh-utils/blobstore/fakes"
fakecmd "github.com/cloudfoundry/bosh-utils/fileutil/fakes"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Extractor", func() {
var (
extractor Extractor
blobstore *fakeblobstore.FakeBlobstore
targetDir string
compressor *fakecmd.FakeCompressor
logger boshlog.Logger
fs *fakesys.FakeFileSystem
blobID string
blobSHA1 string
fileName string
fakeError error
)
BeforeEach(func() {
blobstore = fakeblobstore.NewFakeBlobstore()
targetDir = "fake-target-dir"
compressor = fakecmd.NewFakeCompressor()
logger = boshlog.NewLogger(boshlog.LevelNone)
fs = fakesys.NewFakeFileSystem()
blobID = "fake-blob-id"
blobSHA1 = "fake-sha1"
开发者ID:mattcui,项目名称:bosh-init,代码行数:31,代码来源:extractor_test.go
示例18:
import (
"errors"
. "github.com/cloudfoundry/bosh-init/deployment/manifest"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
biproperty "github.com/cloudfoundry/bosh-utils/property"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
)
var _ = Describe("Parser", func() {
var (
comboManifestPath string
fakeFs *fakesys.FakeFileSystem
parser Parser
)
BeforeEach(func() {
comboManifestPath = "fake-deployment-path"
fakeFs = fakesys.NewFakeFileSystem()
logger := boshlog.NewLogger(boshlog.LevelNone)
parser = NewParser(fakeFs, logger)
})
Context("when combo manifest path does not exist", func() {
BeforeEach(func() {
err := fakeFs.RemoveAll(comboManifestPath)
Expect(err).ToNot(HaveOccurred())
})
开发者ID:mattcui,项目名称:bosh-init,代码行数:31,代码来源:parser_test.go
示例19:
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
boshassert "github.com/cloudfoundry/bosh-utils/assert"
. "github.com/cloudfoundry/bosh-utils/blobstore"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
fakeuuid "github.com/cloudfoundry/bosh-utils/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{}
configPath = filepath.Join("/etc/", "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() {
options := map[string]interface{}{"fake-key": "fake-value"}
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:31,代码来源:external_blobstore_test.go
示例20:
"errors"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/agent/applier/bundlecollection"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-utils/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)
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:32,代码来源:file_bundle_test.go
注:本文中的github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论