當前位置: 首頁>>代碼示例>>Golang>>正文


Golang FakeFileSystem.WriteFile方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/bosh-agent/system/fakes.FakeFileSystem.WriteFile方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.WriteFile方法的具體用法?Golang FakeFileSystem.WriteFile怎麽用?Golang FakeFileSystem.WriteFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry/bosh-agent/system/fakes.FakeFileSystem的用法示例。


在下文中一共展示了FakeFileSystem.WriteFile方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: init


//.........這裏部分代碼省略.........
						"/fake-tmp-dir/fake-path-in-archive/bin/test",
					})

					fs.ChmodErr = errors.New("fake-chmod-error")

					err := act()
					Expect(err).To(HaveOccurred())
					Expect(err.Error()).To(ContainSubstring("fake-chmod-error"))
				})

				It("installs bundle from decompressed tmp path of a job template", func() {
					fs.TempDirDir = "/fake-tmp-dir"

					var installedBeforeDecompression bool

					compressor.DecompressFileToDirCallBack = func() {
						installedBeforeDecompression = bundle.Installed
					}

					err := act()
					Expect(err).ToNot(HaveOccurred())

					// bundle installation did not happen before decompression
					Expect(installedBeforeDecompression).To(BeFalse())

					// make sure that bundle install happened after decompression
					Expect(bundle.InstallSourcePath).To(Equal("/fake-tmp-dir/fake-path-in-archive"))
				})

				It("sets executable bit for files in bin", func() {
					fs.TempDirDir = "/fake-tmp-dir"

					compressor.DecompressFileToDirCallBack = func() {
						fs.WriteFile("/fake-tmp-dir/fake-path-in-archive/bin/test1", []byte{})
						fs.WriteFile("/fake-tmp-dir/fake-path-in-archive/bin/test2", []byte{})
						fs.WriteFile("/fake-tmp-dir/fake-path-in-archive/config/test", []byte{})
					}

					fs.SetGlob("/fake-tmp-dir/fake-path-in-archive/bin/*", []string{
						"/fake-tmp-dir/fake-path-in-archive/bin/test1",
						"/fake-tmp-dir/fake-path-in-archive/bin/test2",
					})

					var binTest1Stats, binTest2Stats, configTestStats *fakesys.FakeFileStats

					bundle.InstallCallBack = func() {
						binTest1Stats = fs.GetFileTestStat("/fake-tmp-dir/fake-path-in-archive/bin/test1")
						binTest2Stats = fs.GetFileTestStat("/fake-tmp-dir/fake-path-in-archive/bin/test2")
						configTestStats = fs.GetFileTestStat("/fake-tmp-dir/fake-path-in-archive/config/test")
					}

					err := act()
					Expect(err).ToNot(HaveOccurred())

					// bin files are executable
					Expect(int(binTest1Stats.FileMode)).To(Equal(0755))
					Expect(int(binTest2Stats.FileMode)).To(Equal(0755))

					// non-bin files are not made executable
					Expect(int(configTestStats.FileMode)).ToNot(Equal(0755))
				})
			}

			ItUpdatesPackages := func(act func() error) {
				var packageApplier *fakepa.FakePackageApplier
開發者ID:keaty,項目名稱:bosh-provisioner,代碼行數:66,代碼來源:rendered_job_applier_test.go

示例2:

nameserver 10.80.130.2
nameserver 10.80.130.1
`
		)

		var (
			errCh chan error
		)

		BeforeEach(func() {
			errCh = make(chan error)
		})

		BeforeEach(func() {
			// For mac addr to interface resolution
			fs.WriteFile("/sys/class/net/eth0", []byte{})
			fs.WriteFileString("/sys/class/net/eth0/address", "22:00:0a:1f:ac:2a\n")
			fs.SetGlob("/sys/class/net/*", []string{"/sys/class/net/eth0"})
		})

		networks := boshsettings.Networks{
			"bosh": boshsettings.Network{
				Default: []string{"dns", "gateway"},
				IP:      "192.168.195.6",
				Netmask: "255.255.255.0",
				Gateway: "192.168.195.1",
				Mac:     "22:00:0a:1f:ac:2a",
				DNS:     []string{"10.80.130.2", "10.80.130.1"},
			},
		}
開發者ID:keaty,項目名稱:bosh-provisioner,代碼行數:30,代碼來源:ubuntu_net_manager_test.go

示例3:

		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",
		}
	})

	Describe("RunCommand", func() {
		It("cleans logs directory", func() {
			err := fs.MkdirAll("/fake-base-dir/fake-log-dir-name/", os.FileMode(0750))
			Expect(err).ToNot(HaveOccurred())

			err = fs.WriteFile("/fake-base-dir/fake-log-dir-name/old-file", []byte("test-data"))
			Expect(err).ToNot(HaveOccurred())

			_, err = runner.RunCommand("fake-log-dir-name", "fake-log-file-name", cmd)
			Expect(err).ToNot(HaveOccurred())

			Expect(fs.FileExists("/fake-base-dir/fake-log-dir-name/old-file")).To(BeFalse())
		})

		It("returns an error if it fails to remove previous logs directory", func() {
			fs.RemoveAllError = errors.New("fake-remove-all-error")

			_, err := runner.RunCommand("fake-log-dir-name", "fake-log-file-name", cmd)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-remove-all-error"))
		})
開發者ID:keaty,項目名稱:bosh-provisioner,代碼行數:31,代碼來源:file_logging_cmd_runner_test.go

示例4: init

func init() {
	Describe("prepareNetworkChange", func() {
		var (
			action          PrepareNetworkChangeAction
			fs              *fakesys.FakeFileSystem
			settingsService *fakesettings.FakeSettingsService
		)

		BeforeEach(func() {
			fs = fakesys.NewFakeFileSystem()
			settingsService = &fakesettings.FakeSettingsService{}
			action = NewPrepareNetworkChange(fs, settingsService)
		})

		It("is synchronous", func() {
			Expect(action.IsAsynchronous()).To(BeFalse())
		})

		It("is not persistent", func() {
			Expect(action.IsPersistent()).To(BeFalse())
		})

		It("invalidates settings so that load settings cannot fall back on old settings", func() {
			resp, err := action.Run()
			Expect(err).NotTo(HaveOccurred())
			Expect(resp).To(Equal("ok"))

			Expect(settingsService.SettingsWereInvalidated).To(BeTrue())
		})

		Context("when settings invalidation succeeds", func() {
			Context("when the network rules file can be removed", func() {
				It("removes the network rules file", func() {
					fs.WriteFile("/etc/udev/rules.d/70-persistent-net.rules", []byte{})

					resp, err := action.Run()
					Expect(err).NotTo(HaveOccurred())
					Expect(resp).To(Equal("ok"))

					Expect(fs.FileExists("/etc/udev/rules.d/70-persistent-net.rules")).To(BeFalse())
				})
			})

			Context("when the network rules file cannot be removed", func() {
				BeforeEach(func() {
					fs.RemoveAllError = errors.New("fake-remove-all-error")
				})

				It("returns error from removing the network rules file", func() {
					resp, err := action.Run()
					Expect(err).To(HaveOccurred())
					Expect(err.Error()).To(ContainSubstring("fake-remove-all-error"))

					Expect(resp).To(BeNil())
				})
			})
		})

		Context("when settings invalidation fails", func() {
			BeforeEach(func() {
				settingsService.InvalidateSettingsError = errors.New("fake-invalidate-error")
			})

			It("returns error early if settings err invalidating", func() {
				resp, err := action.Run()
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-invalidate-error"))

				Expect(resp).To(BeNil())
			})

			It("does not remove the network rules file", func() {
				fs.WriteFile("/etc/udev/rules.d/70-persistent-net.rules", []byte{})

				action.Run()
				Expect(fs.FileExists("/etc/udev/rules.d/70-persistent-net.rules")).To(BeTrue())
			})
		})
	})
}
開發者ID:keaty,項目名稱:bosh-provisioner,代碼行數:80,代碼來源:prepare_network_change_test.go

示例5:

				Expect(err).To(HaveOccurred())

				Expect(len(runner.RunComplexCommands)).To(Equal(1))
				Expect(runner.RunComplexCommands[0].Env).ToNot(HaveKey("BOSH_JOB_NEXT_STATE"))
			})

			It("returns error when cannot get the job next state and does not run drain script", func() {
				params.jobNextStateErr = errors.New("fake-job-next-state-err")

				_, err := drainScript.Run(params)
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-job-next-state-err"))

				Expect(len(runner.RunComplexCommands)).To(Equal(0))
			})
		})
	})

	Describe("Exists", func() {
		It("returns bool", func() {
			commandResult := fakesys.FakeCmdResult{Stdout: "1"}
			runner.AddCmdResult("/fake/script job_shutdown hash_unchanged foo bar", commandResult)

			Expect(drainScript.Exists()).To(BeFalse())

			fs.WriteFile("/fake/script", []byte{})
			Expect(drainScript.Exists()).To(BeTrue())
		})
	})
})
開發者ID:keaty,項目名稱:bosh-provisioner,代碼行數:30,代碼來源:concrete_drain_script_test.go

示例6:

			expectedNetwork := boshsettings.Network{
				Default: []string{"fake-default"},
				DNS:     []string{"fake-dns-name"},
				IP:      "fake-ip-address",
				Netmask: "fake-netmask",
				Gateway: "fake-gateway",
				Mac:     "fake-mac-address",
			}

			BeforeEach(func() {
				settingsPath := filepath.Join(dirProvider.BoshDir(), "dummy-default-network-settings.json")

				expectedNetworkBytes, err := json.Marshal(expectedNetwork)
				Expect(err).ToNot(HaveOccurred())

				fs.WriteFile(settingsPath, expectedNetworkBytes)
			})

			It("returns network", func() {
				network, err := platform.GetDefaultNetwork()
				Expect(err).ToNot(HaveOccurred())
				Expect(network).To(Equal(expectedNetwork))
			})
		})

		Context("when default networks settings file is not found", func() {
			It("does not return error because dummy configuration allows no dynamic IP", func() {
				_, err := platform.GetDefaultNetwork()
				Expect(err).ToNot(HaveOccurred())
			})
		})
開發者ID:keaty,項目名稱:bosh-provisioner,代碼行數:31,代碼來源:dummy_platform_test.go


注:本文中的github.com/cloudfoundry/bosh-agent/system/fakes.FakeFileSystem.WriteFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。