dirProvider := boshdirs.NewProvider(basePath) runner = boshsys.NewExecCmdRunner(logger) jobSupervisor = NewWindowsJobSupervisor(runner, dirProvider, fs, logger, jobFailuresServerPort, make(chan bool), DefaultMachineIP) if err := jobSupervisor.RemoveAllJobs(); err != nil { return "", err } processConfigContents, err := json.Marshal(configContents) if err != nil { return "", err } jobDir, err = fs.TempDir("testWindowsJobSupervisor") processConfigPath = filepath.Join(jobDir, "monit") err = fs.WriteFile(processConfigPath, processConfigContents) return processConfigPath, err } AddJob := func(jobName string) (WindowsProcessConfig, error) { conf, ok := testWindowsConfigs(jobName) if !ok { return conf, fmt.Errorf("Invalid Windows Config Process name: %s", jobName) } confPath, err := WriteJobConfig(conf) if err != nil { return conf, err } return conf, jobSupervisor.AddJob(jobName, 0, confPath) }
fs boshsys.FileSystem diskSettings boshsettings.DiskSettings resolver DevicePathResolver ) BeforeEach(func() { fs = fakesys.NewFakeFileSystem() resolver = NewMappedDevicePathResolver(time.Second, fs) diskSettings = boshsettings.DiskSettings{ Path: "/dev/sda", } }) Context("when a matching /dev/xvdX device is found", func() { BeforeEach(func() { fs.WriteFile("/dev/xvda", []byte{}) fs.WriteFile("/dev/vda", []byte{}) fs.WriteFile("/dev/sda", []byte{}) }) It("returns the match", func() { realPath, timedOut, err := resolver.GetRealDevicePath(diskSettings) Expect(err).NotTo(HaveOccurred()) Expect(timedOut).To(BeFalse()) Expect(realPath).To(Equal("/dev/xvda")) }) }) Context("when a matching /dev/vdX device is found", func() { BeforeEach(func() { fs.WriteFile("/dev/vda", []byte{})
func describeDummyPlatform() { var ( platform Platform collector boshstats.Collector fs boshsys.FileSystem cmdRunner boshsys.CmdRunner dirProvider boshdirs.Provider devicePathResolver boshdpresolv.DevicePathResolver logger boshlog.Logger ) BeforeEach(func() { collector = &fakestats.FakeCollector{} fs = fakesys.NewFakeFileSystem() cmdRunner = fakesys.NewFakeCmdRunner() dirProvider = boshdirs.NewProvider("/fake-dir") devicePathResolver = fakedpresolv.NewFakeDevicePathResolver() logger = boshlog.NewLogger(boshlog.LevelNone) }) JustBeforeEach(func() { platform = NewDummyPlatform( collector, fs, cmdRunner, dirProvider, devicePathResolver, logger, ) }) Describe("GetDefaultNetwork", func() { It("returns the contents of dummy-defaults-network-settings.json since that's what the dummy cpi writes", func() { settingsFilePath := "/fake-dir/bosh/dummy-default-network-settings.json" fs.WriteFileString(settingsFilePath, `{"IP": "1.2.3.4"}`) network, err := platform.GetDefaultNetwork() Expect(err).NotTo(HaveOccurred()) Expect(network.IP).To(Equal("1.2.3.4")) }) }) Describe("GetCertManager", func() { It("returs a dummy cert manager", func() { certManager := platform.GetCertManager() Expect(certManager.UpdateCertificates("")).Should(BeNil()) }) }) Describe("UnmountPersistentDisk", func() { Context("when there are two mounted persistent disks in the mounts json", func() { BeforeEach(func() { var mounts []mount mounts = append(mounts, mount{MountDir: "dir1", DiskCid: "cid1"}) mounts = append(mounts, mount{MountDir: "dir2", DiskCid: "cid2"}) mountsJSON, _ := json.Marshal(mounts) mountsPath := path.Join(dirProvider.BoshDir(), "mounts.json") fs.WriteFile(mountsPath, mountsJSON) }) It("removes one of the disks from the mounts json", func() { unmounted, err := platform.UnmountPersistentDisk(settings.DiskSettings{ID: "cid1"}) Expect(err).NotTo(HaveOccurred()) Expect(unmounted).To(Equal(true)) Expect(platform.IsMountPoint("dir1")).To(Equal(false)) Expect(platform.IsMountPoint("dir2")).To(Equal(true)) }) }) }) }