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


Golang FakeFileSystem.WriteToFile方法代碼示例

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


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

示例1:

		Context("when incorrect http method is used", func() {
			It("returns a 404", func() {
				waitForServerToStart(serverURL, "agent", httpClient)

				httpResponse, err := httpClient.Get(serverURL + "/agent")

				Expect(err).ToNot(HaveOccurred())
				Expect(httpResponse.StatusCode).To(Equal(404))
			})
		})
	})

	Describe("GET /blobs", func() {
		It("returns data from file system", func() {
			fs.WriteToFile("/var/vcap/micro_bosh/data/cache/123-456-789", "Some data")

			httpResponse, err := httpClient.Get(serverURL + "/blobs/a5/123-456-789")
			for err != nil {
				httpResponse, err = httpClient.Get(serverURL + "/blobs/a5/123-456-789")
			}
			defer httpResponse.Body.Close()

			httpBody, readErr := ioutil.ReadAll(httpResponse.Body)
			Expect(readErr).ToNot(HaveOccurred())
			Expect(httpResponse.StatusCode).To(Equal(200))
			Expect(httpBody).To(Equal([]byte("Some data")))
		})

		Context("when incorrect http method is used", func() {
			It("returns a 404", func() {
開發者ID:nkuacac,項目名稱:bosh,代碼行數:30,代碼來源:https_handler_test.go

示例2: init


//.........這裏部分代碼省略.........
			password := ""

			err := platform.CreateUser("foo-user", password, "/some/path/to/home")
			assert.NoError(GinkgoT(), err)

			basePathStat := fs.GetFileTestStat("/some/path/to/home")
			assert.Equal(GinkgoT(), fakesys.FakeFileTypeDir, basePathStat.FileType)
			assert.Equal(GinkgoT(), os.FileMode(0755), basePathStat.FileMode)

			assert.Equal(GinkgoT(), 1, len(cmdRunner.RunCommands))
			assert.Equal(GinkgoT(), expectedUseradd, cmdRunner.RunCommands[0])
		})

		It("ubuntu add user to groups", func() {
			err := platform.AddUserToGroups("foo-user", []string{"group1", "group2", "group3"})
			assert.NoError(GinkgoT(), err)

			assert.Equal(GinkgoT(), 1, len(cmdRunner.RunCommands))

			usermod := []string{"usermod", "-G", "group1,group2,group3", "foo-user"}
			assert.Equal(GinkgoT(), usermod, cmdRunner.RunCommands[0])
		})

		It("ubuntu delete users with prefix and regex", func() {
			passwdFile := fmt.Sprintf(`%sfoo:...
%sbar:...
foo:...
bar:...
foobar:...
%sfoobar:...`,
				boshsettings.EPHEMERAL_USER_PREFIX, boshsettings.EPHEMERAL_USER_PREFIX, boshsettings.EPHEMERAL_USER_PREFIX,
			)

			fs.WriteToFile("/etc/passwd", passwdFile)

			err := platform.DeleteEphemeralUsersMatching("bar$")
			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), 2, len(cmdRunner.RunCommands))
			assert.Equal(GinkgoT(), []string{"userdel", "-r", "bosh_bar"}, cmdRunner.RunCommands[0])
			assert.Equal(GinkgoT(), []string{"userdel", "-r", "bosh_foobar"}, cmdRunner.RunCommands[1])
		})

		It("ubuntu setup ssh", func() {
			fs.HomeDirHomePath = "/some/home/dir"

			platform.SetupSsh("some public key", "vcap")

			sshDirPath := "/some/home/dir/.ssh"
			sshDirStat := fs.GetFileTestStat(sshDirPath)

			assert.Equal(GinkgoT(), fs.HomeDirUsername, "vcap")

			assert.NotNil(GinkgoT(), sshDirStat)
			assert.Equal(GinkgoT(), fakesys.FakeFileTypeDir, sshDirStat.FileType)
			assert.Equal(GinkgoT(), sshDirStat.FileMode, os.FileMode(0700))
			assert.Equal(GinkgoT(), sshDirStat.Username, "vcap")

			authKeysStat := fs.GetFileTestStat(filepath.Join(sshDirPath, "authorized_keys"))

			assert.NotNil(GinkgoT(), authKeysStat)
			assert.Equal(GinkgoT(), authKeysStat.FileType, fakesys.FakeFileTypeFile)
			assert.Equal(GinkgoT(), authKeysStat.FileMode, os.FileMode(0600))
			assert.Equal(GinkgoT(), authKeysStat.Username, "vcap")
			assert.Equal(GinkgoT(), authKeysStat.Content, "some public key")
		})
開發者ID:nkuacac,項目名稱:bosh,代碼行數:66,代碼來源:ubuntu_test.go


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