本文整理匯總了Golang中github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.ReadFileError方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.ReadFileError方法的具體用法?Golang FakeFileSystem.ReadFileError怎麽用?Golang FakeFileSystem.ReadFileError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.ReadFileError方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
Context("when combo manifest path does not exist", func() {
BeforeEach(func() {
err := fakeFs.RemoveAll(comboManifestPath)
Expect(err).ToNot(HaveOccurred())
})
It("returns an error", func() {
_, err := parser.Parse(comboManifestPath)
Expect(err).To(HaveOccurred())
})
})
Context("when parser fails to read the combo manifest file", func() {
BeforeEach(func() {
fakeFs.ReadFileError = errors.New("fake-read-file-error")
})
It("returns an error", func() {
_, err := parser.Parse(comboManifestPath)
Expect(err).To(HaveOccurred())
})
})
BeforeEach(func() {
contents := `
---
name: fake-deployment-name
update:
update_watch_time: 2000-7000
resource_pools:
示例2:
})
It("returns error if file contains invalid json", func() {
err := fs.WriteFileString("/config.json", "-")
Expect(err).ToNot(HaveOccurred())
_, err = NewConfigFromPath("/config.json", fs)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Unmarshalling config"))
})
It("returns error if file cannot be read", func() {
err := fs.WriteFileString("/config.json", "{}")
Expect(err).ToNot(HaveOccurred())
fs.ReadFileError = errors.New("fake-read-err")
_, err = NewConfigFromPath("/config.json", fs)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-read-err"))
})
})
var _ = Describe("Config", func() {
var (
config Config
)
Describe("Validate", func() {
BeforeEach(func() {
config = validConfig
示例3: rootDesc
func rootDesc() {
var (
repo ReleaseRepo
deploymentStateService DeploymentStateService
fs *fakesys.FakeFileSystem
fakeUUIDGenerator *fakeuuid.FakeGenerator
)
BeforeEach(func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
fs = fakesys.NewFakeFileSystem()
fakeUUIDGenerator = &fakeuuid.FakeGenerator{}
fakeUUIDGenerator.GeneratedUUID = "fake-uuid"
deploymentStateService = NewFileSystemDeploymentStateService(fs, fakeUUIDGenerator, logger, "/fake/path")
deploymentStateService.Load()
repo = NewReleaseRepo(deploymentStateService, fakeUUIDGenerator)
})
Describe("List", func() {
Context("when a current release exists", func() {
BeforeEach(func() {
conf, err := deploymentStateService.Load()
Expect(err).ToNot(HaveOccurred())
conf.Releases = []ReleaseRecord{
ReleaseRecord{ID: "fake-guid-a", Name: "fake-name-a", Version: "fake-version-a"},
ReleaseRecord{ID: "fake-guid-b", Name: "fake-name-b", Version: "fake-version-b"},
}
err = deploymentStateService.Save(conf)
Expect(err).ToNot(HaveOccurred())
})
It("returns existing release", func() {
records, err := repo.List()
Expect(err).ToNot(HaveOccurred())
Expect(records).To(Equal([]ReleaseRecord{
{
ID: "fake-guid-a",
Name: "fake-name-a",
Version: "fake-version-a",
},
{
ID: "fake-guid-b",
Name: "fake-name-b",
Version: "fake-version-b",
},
}))
})
})
Context("when there are no releases recorded", func() {
It("returns not found", func() {
records, err := repo.List()
Expect(err).ToNot(HaveOccurred())
Expect(records).To(HaveLen(0))
})
})
Context("when the config service fails to load", func() {
BeforeEach(func() {
fs.ReadFileError = errors.New("kaboom")
})
It("returns an error", func() {
_, err := repo.List()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Loading existing config"))
})
})
})
Describe("Update", func() {
Context("when there are no existing releases", func() {
It("saves the provided releases to the config file", func() {
err := repo.Update([]release.Release{
fakerelease.New("name1", "1"),
fakerelease.New("name2", "2"),
})
Expect(err).ToNot(HaveOccurred())
conf, err := deploymentStateService.Load()
Expect(err).ToNot(HaveOccurred())
Expect(conf.Releases).To(ConsistOf(
ReleaseRecord{ID: "fake-uuid", Name: "name1", Version: "1"},
ReleaseRecord{ID: "fake-uuid", Name: "name2", Version: "2"},
))
})
})
Context("when the existing releases exactly match the provided releases", func() {
BeforeEach(func() {
conf, err := deploymentStateService.Load()
Expect(err).ToNot(HaveOccurred())
conf.Releases = []ReleaseRecord{
ReleaseRecord{ID: "old-uuid", Name: "name1", Version: "1"},
ReleaseRecord{ID: "old-uuid", Name: "name2", Version: "2"},
}
err = deploymentStateService.Save(conf)
Expect(err).ToNot(HaveOccurred())
})
})
//.........這裏部分代碼省略.........
示例4:
_, _ = action.Run("fake-blobstore-id", "fake-fingerprint", 2)
tag, message, _ := logger.ErrorArgsForCall(0)
Expect(tag).To(Equal("Sync DNS action"))
Expect(message).To(Equal("Failed to remove dns blob file at path 'fake-blobstore-file-path'"))
})
})
})
})
})
Context("when local DNS state could not be read", func() {
BeforeEach(func() {
err := fakeFileSystem.WriteFileString(stateFilePath, `{"version": 2}`)
Expect(err).ToNot(HaveOccurred())
fakeFileSystem.ReadFileError = errors.New("fake-read-error")
fakeFileSystem.RegisterReadFileError(stateFilePath, fakeFileSystem.ReadFileError)
})
It("returns error", func() {
_, err := action.Run("fake-blobstore-id", "fake-fingerprint", 2)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("reading local DNS state"))
})
})
Context("when there is no local DNS state", func() {
It("runs successfully and creates a new state file", func() {
Expect(fakeFileSystem.FileExists(stateFilePath)).To(BeFalse())
response, err := action.Run("fake-blobstore-id", "fake-fingerprint", 1)
示例5: init
func init() {
Describe("concreteManagerProvider", func() {
Describe("NewManager", func() {
It("returns manager with tasks.json as its tasks path", func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
fs := fakesys.NewFakeFileSystem()
taskInfo := boshtask.Info{
TaskID: "fake-task-id",
Method: "fake-method",
Payload: []byte("fake-payload"),
}
manager := boshtask.NewManagerProvider().NewManager(logger, fs, "/dir/path")
err := manager.AddInfo(taskInfo)
Expect(err).ToNot(HaveOccurred())
// Check expected file location with another manager
otherManager := boshtask.NewManager(logger, fs, "/dir/path/tasks.json")
taskInfos, err := otherManager.GetInfos()
Expect(err).ToNot(HaveOccurred())
Expect(taskInfos).To(Equal([]boshtask.Info{taskInfo}))
})
})
})
Describe("concreteManager", func() {
var (
logger boshlog.Logger
fs *fakesys.FakeFileSystem
manager boshtask.Manager
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LevelNone)
fs = fakesys.NewFakeFileSystem()
manager = boshtask.NewManager(logger, fs, "/dir/path")
})
Describe("GetInfos", func() {
It("can load multiple tasks", func() {
err := manager.AddInfo(boshtask.Info{
TaskID: "fake-task-id-1",
Method: "fake-method-1",
Payload: []byte("fake-payload-1"),
})
Expect(err).ToNot(HaveOccurred())
err = manager.AddInfo(boshtask.Info{
TaskID: "fake-task-id-2",
Method: "fake-method-2",
Payload: []byte("fake-payload-2"),
})
Expect(err).ToNot(HaveOccurred())
// Make sure we are not getting cached copy of taskInfos
reloadedManager := boshtask.NewManager(logger, fs, "/dir/path")
taskInfos, err := reloadedManager.GetInfos()
Expect(err).ToNot(HaveOccurred())
Expect(taskInfos).To(ConsistOf([]boshtask.Info{
boshtask.Info{
TaskID: "fake-task-id-1",
Method: "fake-method-1",
Payload: []byte("fake-payload-1"),
},
boshtask.Info{
TaskID: "fake-task-id-2",
Method: "fake-method-2",
Payload: []byte("fake-payload-2"),
},
}))
})
It("succeeds when there is no tasks (file is not present)", func() {
taskInfos, err := manager.GetInfos()
Expect(err).ToNot(HaveOccurred())
Expect(len(taskInfos)).To(Equal(0))
})
It("returns an error when failing to load tasks from the file that exists", func() {
err := manager.AddInfo(boshtask.Info{
TaskID: "fake-task-id-2",
Method: "fake-method-2",
Payload: []byte("fake-payload-2"),
})
Expect(err).ToNot(HaveOccurred())
fs.ReadFileError = errors.New("fake-read-error")
_, err = manager.GetInfos()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-read-error"))
})
})
Describe("AddInfo", func() {
It("can add multiple tasks", func() {
err := manager.AddInfo(boshtask.Info{
//.........這裏部分代碼省略.........
示例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.WriteFileError = errors.New("fake-write-error")
err := service.Set(newSpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-write-error"))
})
})
Describe("PopulateDHCPNetworks", func() {
var settings boshsettings.Settings
var unresolvedSpec V1ApplySpec
var staticSpec NetworkSpec
var dhcpSpec NetworkSpec
var manualSetting boshsettings.Network
var dynamicSetting boshsettings.Network
BeforeEach(func() {
settings = boshsettings.Settings{
Networks: boshsettings.Networks{},
}
manualSetting = boshsettings.Network{
Type: "manual",
IP: "fake-manual-ip",
Netmask: "fake-manual-netmask",
Gateway: "fake-manual-gateway",
Mac: "fake-manual-mac",
}
dynamicSetting = boshsettings.Network{
Type: "dynamic",
IP: "fake-dynamic-ip",
Netmask: "fake-dynamic-netmask",
Gateway: "fake-dynamic-gateway",
}
unresolvedSpec = V1ApplySpec{
Deployment: "fake-deployment",
NetworkSpecs: map[string]NetworkSpec{},
}
staticSpec = NetworkSpec{
Fields: map[string]interface{}{
"ip": "fake-net1-ip",
"netmask": "fake-net1-netmask",
"gateway": "fake-net1-gateway",
//.........這裏部分代碼省略.........
示例7:
Context("when saving to index fails", func() {
It("returns error", func() {
fakeFS.WriteFileError = errors.New("Could not save")
record := CompiledPackageRecord{
BlobID: "fake-blob-id",
BlobSHA1: "fake-sha1",
}
pkg := birelpkg.Package{
Name: "fake-package-name",
}
err := compiledPackageRepo.Save(pkg, record)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Saving compiled package"))
})
})
Context("when reading from index fails", func() {
It("returns error", func() {
err := compiledPackageRepo.Save(pkg, record)
fakeFS.ReadFileError = errors.New("fake-error")
_, _, err = compiledPackageRepo.Find(pkg)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Finding compiled package"))
})
})
})
})