本文整理匯總了Golang中bosh/system/fakes.FakeFileSystem.HomeDirHomePath方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.HomeDirHomePath方法的具體用法?Golang FakeFileSystem.HomeDirHomePath怎麽用?Golang FakeFileSystem.HomeDirHomePath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bosh/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.HomeDirHomePath方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
foobar:...
bosh_foobar:...`
fs.WriteFileString("/etc/passwd", passwdFile)
err := platform.DeleteEphemeralUsersMatching("bar$")
Expect(err).NotTo(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(2))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"userdel", "-r", "bosh_bar"}))
Expect(cmdRunner.RunCommands[1]).To(Equal([]string{"userdel", "-r", "bosh_foobar"}))
})
})
Describe("SetupSsh", func() {
It("setup ssh", func() {
fs.HomeDirHomePath = "/some/home/dir"
platform.SetupSsh("some public key", "vcap")
sshDirPath := "/some/home/dir/.ssh"
sshDirStat := fs.GetFileTestStat(sshDirPath)
Expect("vcap").To(Equal(fs.HomeDirUsername))
Expect(sshDirStat).NotTo(BeNil())
Expect(sshDirStat.FileType).To(Equal(fakesys.FakeFileTypeDir))
Expect(os.FileMode(0700)).To(Equal(sshDirStat.FileMode))
Expect("vcap").To(Equal(sshDirStat.Username))
authKeysStat := fs.GetFileTestStat(filepath.Join(sshDirPath, "authorized_keys"))
示例2: init
//.........這裏部分代碼省略.........
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")
})
It("ubuntu set user password", func() {
platform.SetUserPassword("my-user", "my-encrypted-password")
assert.Equal(GinkgoT(), 1, len(cmdRunner.RunCommands))
assert.Equal(GinkgoT(), []string{"usermod", "-p", "my-encrypted-password", "my-user"}, cmdRunner.RunCommands[0])
})
It("ubuntu setup hostname", func() {
platform.SetupHostname("foobar.local")
assert.Equal(GinkgoT(), 1, len(cmdRunner.RunCommands))
assert.Equal(GinkgoT(), []string{"hostname", "foobar.local"}, cmdRunner.RunCommands[0])