本文整理匯總了Golang中github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.WriteFileString方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.WriteFileString方法的具體用法?Golang FakeFileSystem.WriteFileString怎麽用?Golang FakeFileSystem.WriteFileString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.WriteFileString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
Expect(readErr).ToNot(HaveOccurred())
Expect(httpBody).To(Equal([]byte(`{"value":"expected value"}`)))
})
Context("when incorrect http method is used", func() {
It("returns a 404", func() {
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.WriteFileString("/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")))
})
It("closes the underlying file", func() {
示例2: init
//.........這裏部分代碼省略.........
})
It("setups up monit user", func() {
err := bootstrap()
Expect(err).NotTo(HaveOccurred())
Expect(platform.SetupMonitUserSetup).To(BeTrue())
})
It("starts monit", func() {
err := bootstrap()
Expect(err).NotTo(HaveOccurred())
Expect(platform.StartMonitStarted).To(BeTrue())
})
})
Describe("Network setup exercised by Run", func() {
var (
settingsJSON string
fs *fakesys.FakeFileSystem
platform boshplatform.Platform
boot Bootstrap
defaultNetworkResolver boshsettings.DefaultNetworkResolver
logger boshlog.Logger
dirProvider boshdirs.Provider
)
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
}
stubInterfaces := func(interfaces [][]string) {
var interfacePaths []string
for _, iface := range interfaces {
interfaceName := iface[0]
interfaceMAC := iface[1]
interfaceType := iface[2]
isPhysical := interfaceType == "physical"
interfacePaths = append(interfacePaths, writeNetworkDevice(interfaceName, interfaceMAC, isPhysical))
}
fs.SetGlob("/sys/class/net/*", interfacePaths)
}
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
runner := fakesys.NewFakeCmdRunner()
dirProvider = boshdirs.NewProvider("/var/vcap/bosh")
linuxOptions := boshplatform.LinuxOptions{
CreatePartitionIfNoEphemeralDisk: true,
}
logger = boshlog.NewLogger(boshlog.LevelNone)
diskManager := fakedisk.NewFakeDiskManager()
diskManager.FakeMountsSearcher.SearchMountsMounts = []boshdisk.Mount{
{MountPoint: "/", PartitionPath: "rootfs"},
示例3:
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() {
Context("when metadata service file exists", func() {
BeforeEach(func() {
metadataContents := `{"instance-id":"fake-instance-id"}`
fs.WriteFileString("fake-metadata-file-path", metadataContents)
})
It("returns instance id", func() {
instanceID, err := metadataService.GetInstanceID()
Expect(err).NotTo(HaveOccurred())
Expect(instanceID).To(Equal("fake-instance-id"))
})
})
Context("when metadata service file does not exist", func() {
It("returns an error", func() {
_, err := metadataService.GetInstanceID()
Expect(err).To(HaveOccurred())
})
})
示例4: describeLinuxPlatform
//.........這裏部分代碼省略.........
err := platform.CreateUser("foo-user", "", "/some/path/to/home")
Expect(err).NotTo(HaveOccurred())
basePathStat := fs.GetFileTestStat("/some/path/to/home")
Expect(basePathStat.FileType).To(Equal(fakesys.FakeFileTypeDir))
Expect(basePathStat.FileMode).To(Equal(os.FileMode(0755)))
Expect(cmdRunner.RunCommands).To(Equal([][]string{expectedUseradd}))
})
})
Describe("AddUserToGroups", func() {
It("adds user to groups", func() {
err := platform.AddUserToGroups("foo-user", []string{"group1", "group2", "group3"})
Expect(err).NotTo(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(1))
usermod := []string{"usermod", "-G", "group1,group2,group3", "foo-user"}
Expect(cmdRunner.RunCommands[0]).To(Equal(usermod))
})
})
Describe("DeleteEphemeralUsersMatching", func() {
It("deletes users with prefix and regex", func() {
passwdFile := `bosh_foo:...
bosh_bar:...
foo:...
bar:...
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"))
Expect(authKeysStat).NotTo(BeNil())
Expect(fakesys.FakeFileTypeFile).To(Equal(authKeysStat.FileType))
Expect(os.FileMode(0600)).To(Equal(authKeysStat.FileMode))
Expect("vcap").To(Equal(authKeysStat.Username))
Expect("some public key").To(Equal(authKeysStat.StringContents()))
示例5:
failureHandler := func(alert boshalert.MonitAlert) (err error) {
didHandleAlert = true
return
}
go monit.MonitorJobFailures(failureHandler)
err := doJobFailureEmail(`fake-other-email`, jobFailuresServerPort)
Expect(err).ToNot(HaveOccurred())
Expect(didHandleAlert).To(BeFalse())
})
})
Describe("AddJob", func() {
BeforeEach(func() {
fs.WriteFileString("/some/config/path", "fake-config")
})
Context("when reading configuration from config path succeeds", func() {
Context("when writing job configuration succeeds", func() {
It("returns no error because monit can track added job in jobs directory", func() {
err := monit.AddJob("router", 0, "/some/config/path")
Expect(err).ToNot(HaveOccurred())
writtenConfig, err := fs.ReadFileString(
dirProvider.MonitJobsDir() + "/0000_router.monitrc")
Expect(err).ToNot(HaveOccurred())
Expect(writtenConfig).To(Equal("fake-config"))
})
})
示例6: init
//.........這裏部分代碼省略.........
pkg.BlobstoreID = ""
_, _, err := compiler.Compile(pkg, pkgDeps)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Blobstore ID for package '%s' is empty", pkg.Name))
})
It("installs dependent packages", func() {
_, _, err := compiler.Compile(pkg, pkgDeps)
Expect(err).ToNot(HaveOccurred())
Expect(packageApplier.AppliedPackages).To(Equal(pkgDeps))
})
It("cleans up the compile directory", func() {
_, _, err := compiler.Compile(pkg, pkgDeps)
Expect(err).ToNot(HaveOccurred())
Expect(fs.FileExists("/fake-compile-dir/pkg_name")).To(BeFalse())
})
It("installs, enables and later cleans up bundle", func() {
_, _, err := compiler.Compile(pkg, pkgDeps)
Expect(err).ToNot(HaveOccurred())
Expect(bundle.ActionsCalled).To(Equal([]string{
"InstallWithoutContents",
"Enable",
"Disable",
"Uninstall",
}))
})
Context("when packaging script exists", func() {
BeforeEach(func() {
compressor.DecompressFileToDirCallBack = func() {
fs.WriteFileString("/fake-compile-dir/pkg_name/packaging", "hi")
}
})
It("runs packaging script ", func() {
_, _, err := compiler.Compile(pkg, pkgDeps)
Expect(err).ToNot(HaveOccurred())
expectedCmd := boshsys.Command{
Name: "bash",
Args: []string{"-x", "packaging"},
Env: map[string]string{
"BOSH_COMPILE_TARGET": "/fake-compile-dir/pkg_name",
"BOSH_INSTALL_TARGET": "/fake-dir/packages/pkg_name",
"BOSH_PACKAGE_NAME": "pkg_name",
"BOSH_PACKAGE_VERSION": "pkg_version",
},
WorkingDir: "/fake-compile-dir/pkg_name",
}
Expect(len(runner.RunCommands)).To(Equal(1))
Expect(runner.RunCommands[0]).To(Equal(expectedCmd))
Expect(runner.RunCommandJobName).To(Equal("compilation"))
Expect(runner.RunCommandTaskName).To(Equal("packaging"))
})
It("propagates the error from packaging script", func() {
runner.RunCommandErr = errors.New("fake-packaging-error")
_, _, err := compiler.Compile(pkg, pkgDeps)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-packaging-error"))
})
示例7:
Expect(err.Error()).To(ContainSubstring("missing blobstore_path"))
})
It("returns error when blobstore path is not a string", func() {
options := map[string]interface{}{"blobstore_path": 443}
blobstore = NewLocalBlobstore(fs, uuidGen, options)
err := blobstore.Validate()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("blobstore_path must be a string"))
})
})
Describe("Get", func() {
It("fetches the local blob contents", func() {
fs.WriteFileString(fakeBlobstorePath+"/fake-blob-id", "fake contents")
tempFile, err := fs.TempFile("bosh-blobstore-local-TestLocalGet")
Expect(err).ToNot(HaveOccurred())
fs.ReturnTempFile = tempFile
defer fs.RemoveAll(tempFile.Name())
_, err = blobstore.Get("fake-blob-id", "")
Expect(err).ToNot(HaveOccurred())
fileStats := fs.GetFileTestStat(tempFile.Name())
Expect(fileStats).ToNot(BeNil())
Expect("fake contents").To(Equal(fileStats.StringContents()))
})
示例8: describeUbuntuNetManager
func describeUbuntuNetManager() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
ipResolver *fakeip.FakeResolver
addressBroadcaster *fakearp.FakeAddressBroadcaster
netManager UbuntuNetManager
interfaceConfigurationCreator InterfaceConfigurationCreator
)
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
}
stubInterfacesWithVirtual := func(physicalInterfaces map[string]boshsettings.Network, virtualInterfaces []string) {
interfacePaths := []string{}
for iface, networkSettings := range physicalInterfaces {
interfacePaths = append(interfacePaths, writeNetworkDevice(iface, networkSettings.Mac, true))
}
for _, iface := range virtualInterfaces {
interfacePaths = append(interfacePaths, writeNetworkDevice(iface, "virtual", false))
}
fs.SetGlob("/sys/class/net/*", interfacePaths)
}
stubInterfaces := func(physicalInterfaces map[string]boshsettings.Network) {
stubInterfacesWithVirtual(physicalInterfaces, nil)
}
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
ipResolver = &fakeip.FakeResolver{}
logger := boshlog.NewLogger(boshlog.LevelNone)
interfaceConfigurationCreator = NewInterfaceConfigurationCreator(logger)
addressBroadcaster = &fakearp.FakeAddressBroadcaster{}
netManager = NewUbuntuNetManager(
fs,
cmdRunner,
ipResolver,
interfaceConfigurationCreator,
addressBroadcaster,
logger,
).(UbuntuNetManager)
})
Describe("ComputeNetworkConfig", func() {
Context("when there is one manual network and neither is marked as default for DNS", func() {
It("should use the manual network for DNS", func() {
networks := boshsettings.Networks{
"manual": factory.Network{DNS: &[]string{"8.8.8.8"}}.Build(),
}
stubInterfaces(networks)
_, _, dnsServers, err := netManager.ComputeNetworkConfig(networks)
Expect(err).ToNot(HaveOccurred())
Expect(dnsServers).To(Equal([]string{"8.8.8.8"}))
})
})
Context("when there is a vip network and a manual network and neither is marked as default for DNS", func() {
It("should use the manual network for DNS", func() {
networks := boshsettings.Networks{
"vip": boshsettings.Network{Type: "vip"},
"manual": factory.Network{Type: "manual", DNS: &[]string{"8.8.8.8"}}.Build(),
}
stubInterfaces(networks)
_, _, dnsServers, err := netManager.ComputeNetworkConfig(networks)
Expect(err).ToNot(HaveOccurred())
Expect(dnsServers).To(Equal([]string{"8.8.8.8"}))
})
})
Context("when there is a vip network and a manual network and the manual network is marked as default for DNS", func() {
It("should use the manual network for DNS", func() {
networks := boshsettings.Networks{
"vip": boshsettings.Network{Type: "vip"},
"manual": factory.Network{Type: "manual", DNS: &[]string{"8.8.8.8"}, Default: []string{"dns"}}.Build(),
}
stubInterfaces(networks)
_, _, dnsServers, err := netManager.ComputeNetworkConfig(networks)
Expect(err).ToNot(HaveOccurred())
Expect(dnsServers).To(Equal([]string{"8.8.8.8"}))
})
})
Context("when specified more than one DNS", func() {
It("extracts all DNS servers from the network configured as default DNS", func() {
networks := boshsettings.Networks{
"default": factory.Network{
IP: "10.10.0.32",
Netmask: "255.255.255.0",
//.........這裏部分代碼省略.........
示例9: 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",
//.........這裏部分代碼省略.........
示例10:
})
Describe("GetFileContents", func() {
Context("when disk path does not exist", func() {
It("returns an error if diskpath does not exist", func() {
_, err := diskUtil.GetFilesContents([]string{"fake-file-path-1"})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("disk path 'fake-disk-path' does not exist"))
})
})
Context("when disk path does not exist", func() {
BeforeEach(func() {
fs.MkdirAll("fake-disk-path", 0700)
fs.TempDirDir = "fake-tempdir"
fs.WriteFileString("fake-tempdir/fake-file-path-1", "fake-contents-1")
fs.WriteFileString("fake-tempdir/fake-file-path-2", "fake-contents-2")
})
It("mounts disk path to temporary directory", func() {
_, err := diskUtil.GetFilesContents([]string{"fake-file-path-1"})
Expect(err).ToNot(HaveOccurred())
Expect(mounter.MountPartitionPaths).To(ContainElement("fake-disk-path"))
Expect(mounter.MountMountPoints).To(ContainElement("fake-tempdir"))
})
It("returns contents of files on a disk", func() {
contents, err := diskUtil.GetFilesContents([]string{"fake-file-path-1", "fake-file-path-2"})
Expect(err).ToNot(HaveOccurred())
Expect(len(contents)).To(Equal(2))
示例11: describeCentosNetManager
func describeCentosNetManager() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
ipResolver *fakeip.FakeResolver
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)
addressBroadcaster = &fakearp.FakeAddressBroadcaster{}
netManager = NewCentosNetManager(
fs,
cmdRunner,
ipResolver,
interfaceConfigurationCreator,
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",
}
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,
domain-name, domain-name-servers, domain-search, host-name,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;
prepend domain-name-servers 8.8.8.8, 9.9.9.9;
`
})
stubInterfacesWithVirtual := func(physicalInterfaces map[string]boshsettings.Network, virtualInterfaces []string) {
interfacePaths := []string{}
for iface, networkSettings := range physicalInterfaces {
interfacePaths = append(interfacePaths, writeNetworkDevice(iface, networkSettings.Mac, true))
//.........這裏部分代碼省略.........
示例12: init
//.........這裏部分代碼省略.........
})
Context("when job is not installed", func() {
BeforeEach(func() {
bundle.Installed = false
})
It("installs and enables job", func() {
err := act()
Expect(err).ToNot(HaveOccurred())
Expect(bundle.ActionsCalled).To(Equal([]string{"Install", "Enable"}))
})
It("returns error when job enable fails", func() {
bundle.EnableError = errors.New("fake-enable-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-enable-error"))
})
ItInstallsJob(act)
ItUpdatesPackages(act)
})
})
})
Describe("Configure", func() {
It("adds job to the job supervisor", func() {
job, bundle := buildJob(jobsBc)
fs := fakesys.NewFakeFileSystem()
fs.WriteFileString("/path/to/job/monit", "some conf")
fs.SetGlob("/path/to/job/*.monit", []string{"/path/to/job/subjob.monit"})
bundle.GetDirPath = "/path/to/job"
bundle.GetDirFs = fs
err := applier.Configure(job, 0)
Expect(err).ToNot(HaveOccurred())
Expect(len(jobSupervisor.AddJobArgs)).To(Equal(2))
Expect(jobSupervisor.AddJobArgs[0]).To(Equal(fakejobsuper.AddJobArgs{
Name: job.Name,
Index: 0,
ConfigPath: "/path/to/job/monit",
}))
Expect(jobSupervisor.AddJobArgs[1]).To(Equal(fakejobsuper.AddJobArgs{
Name: job.Name + "_subjob",
Index: 0,
ConfigPath: "/path/to/job/subjob.monit",
}))
})
It("does not require monit script", func() {
job, bundle := buildJob(jobsBc)
fs := fakesys.NewFakeFileSystem()
bundle.GetDirFs = fs
err := applier.Configure(job, 0)
Expect(err).ToNot(HaveOccurred())
Expect(len(jobSupervisor.AddJobArgs)).To(Equal(0))
示例13:
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_")
Expect(err).ToNot(HaveOccurred())
Expect(count).To(Equal(2))
Expect(countFiles(fakeFs, "/path/to/delete/stuff/in/")).To(Equal(1))
})
It("only deletes the files in the given path", 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")
示例14:
fs *fakesys.FakeFileSystem
searcher MountsSearcher
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
searcher = NewProcMountsSearcher(fs)
})
Describe("SearchMounts", func() {
Context("when reading /proc/mounts succeeds", func() {
It("returns parsed mount information", func() {
fs.WriteFileString(
"/proc/mounts",
`none /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
none /run/shm tmpfs rw,nosuid,nodev,relatime 0 0
/dev/sda1 /boot ext2 rw,relatime,errors=continue 0 0
none /tmp/warden/cgroup tmpfs rw,relatime 0 0`,
)
mounts, err := searcher.SearchMounts()
Expect(err).ToNot(HaveOccurred())
Expect(mounts).To(Equal([]Mount{
Mount{PartitionPath: "none", MountPoint: "/run/lock"},
Mount{PartitionPath: "none", MountPoint: "/run/shm"},
Mount{PartitionPath: "/dev/sda1", MountPoint: "/boot"},
Mount{PartitionPath: "none", MountPoint: "/tmp/warden/cgroup"},
}))
})
It("ignores empty lines", func() {
示例15:
fs.WriteFileString("/fake-config.conf", `{
"Platform": {
"Linux": {
"UseDefaultTmpDir": true,
"UsePreformattedPersistentDisk": true,
"BindMountPersistentDisk": true,
"DevicePathResolutionType": "virtio"
}
},
"Infrastructure": {
"Settings": {
"Sources": [
{
"Type": "HTTP",
"URI": "http://fake-uri"
},
{
"Type": "ConfigDrive",
"DiskPaths": ["/fake-disk-path1", "/fake-disk-path2"],
"MetaDataPath": "/fake-metadata-path",
"UserDataPath": "/fake-userdata-path",
"SettingsPath": "/fake-settings-path"
},
{
"Type": "File",
"MetaDataPath": "/fake-metadata-path",
"UserDataPath": "/fake-userdata-path",
"SettingsPath": "/fake-settings-path"
},
{
"Type": "CDROM",
"FileName": "/fake-file-name"
}
],
"UseServerName": true,
"UseRegistry": true
}
}
}`)