Golang bosh-agent-action.IsAsynchronous类(方法)实例源码

下面列出了Golang bosh-agent-action.IsAsynchronous 类(方法)源码代码实例,从而了解它的用法。

作者:nkuaca    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("list disk should be synchronous", func() {

			settings := &fakesettings.FakeSettingsService{}
			platform := fakeplatform.NewFakePlatform()
			action := NewListDisk(settings, platform)
			assert.False(GinkgoT(), action.IsAsynchronous())
		})
		It("list disk run", func() {

			settings := &fakesettings.FakeSettingsService{
				Disks: boshsettings.Disks{
					Persistent: map[string]string{
						"volume-1": "/dev/sda",
						"volume-2": "/dev/sdb",
						"volume-3": "/dev/sdc",
					},
				},
			}
			platform := fakeplatform.NewFakePlatform()
			platform.MountedDevicePaths = []string{"/dev/sdb", "/dev/sdc"}

			action := NewListDisk(settings, platform)
			value, err := action.Run()
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), value, `["volume-2","volume-3"]`)
		})
	})
}

作者:Bosh-for-Cp    项目:bosh-260   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("migrate disk should be asynchronous", func() {
			_, action := buildMigrateDiskAction()
			Expect(action.IsAsynchronous()).To(BeTrue())
		})

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

		It("migrate disk action run", func() {

			platform, action := buildMigrateDiskAction()

			value, err := action.Run()
			Expect(err).ToNot(HaveOccurred())
			boshassert.MatchesJSONString(GinkgoT(), value, "{}")

			Expect(platform.MigratePersistentDiskFromMountPoint).To(Equal("/foo/store"))
			Expect(platform.MigratePersistentDiskToMountPoint).To(Equal("/foo/store_migration_target"))
		})
	})
}

作者:punalpate    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("mount disk should be asynchronous", func() {
			settings := &fakesettings.FakeSettingsService{}
			_, action := buildMountDiskAction(settings)
			Expect(action.IsAsynchronous()).To(BeTrue())
		})

		It("is not persistent", func() {
			settings := &fakesettings.FakeSettingsService{}
			_, action := buildMountDiskAction(settings)
			Expect(action.IsPersistent()).To(BeFalse())
		})

		It("mount disk", func() {
			settings := &fakesettings.FakeSettingsService{}
			settings.Disks.Persistent = map[string]string{"vol-123": "/dev/sdf"}
			platform, mountDisk := buildMountDiskAction(settings)

			result, err := mountDisk.Run("vol-123")
			Expect(err).NotTo(HaveOccurred())
			boshassert.MatchesJSONString(GinkgoT(), result, "{}")

			Expect(settings.SettingsWereLoaded).To(BeTrue())

			Expect(platform.MountPersistentDiskDevicePath).To(Equal("/dev/sdf"))
			Expect(platform.MountPersistentDiskMountPoint).To(Equal("/foo/store"))
		})

		It("mount disk when store already mounted", func() {
			settings := &fakesettings.FakeSettingsService{}
			settings.Disks.Persistent = map[string]string{"vol-123": "/dev/sdf"}
			platform, mountDisk := buildMountDiskAction(settings)

			platform.IsMountPointResult = true

			result, err := mountDisk.Run("vol-123")
			Expect(err).NotTo(HaveOccurred())
			boshassert.MatchesJSONString(GinkgoT(), result, "{}")

			Expect(platform.IsMountPointPath).To(Equal("/foo/store"))

			Expect(platform.MountPersistentDiskDevicePath).To(Equal("/dev/sdf"))
			Expect(platform.MountPersistentDiskMountPoint).To(Equal("/foo/store_migration_target"))
		})

		It("mount disk when device path not found", func() {
			settings := &fakesettings.FakeSettingsService{}
			settings.Disks.Persistent = map[string]string{"vol-123": "/dev/sdf"}
			_, mountDisk := buildMountDiskAction(settings)

			_, err := mountDisk.Run("vol-456")
			Expect(err).To(HaveOccurred())
		})
	})
}

作者:velankanisy    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("ssh should be synchronous", func() {
			settings := &fakesettings.FakeSettingsService{}
			_, action := buildSshAction(settings)
			Expect(action.IsAsynchronous()).To(BeFalse())
		})

		It("is not persistent", func() {
			settings := &fakesettings.FakeSettingsService{}
			_, action := buildSshAction(settings)
			Expect(action.IsPersistent()).To(BeFalse())
		})

		It("ssh setup without default ip", func() {

			settings := &fakesettings.FakeSettingsService{}
			_, action := buildSshAction(settings)

			params := SshParams{
				User:      "some-user",
				Password:  "some-pwd",
				PublicKey: "some-key",
			}
			_, err := action.Run("setup", params)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("No default ip"))
		})
		It("ssh setup with username and password", func() {

			testSshSetupWithGivenPassword(GinkgoT(), "some-password")
		})
		It("ssh setup without password", func() {

			testSshSetupWithGivenPassword(GinkgoT(), "")
		})
		It("ssh run cleanup deletes ephemeral user", func() {

			settings := &fakesettings.FakeSettingsService{}
			platform, action := buildSshAction(settings)

			params := SshParams{UserRegex: "^foobar.*"}
			response, err := action.Run("cleanup", params)
			Expect(err).ToNot(HaveOccurred())
			Expect("^foobar.*").To(Equal(platform.DeleteEphemeralUsersMatchingRegex))

			boshassert.MatchesJsonMap(GinkgoT(), response, map[string]interface{}{
				"command": "cleanup",
				"status":  "success",
			})
		})
	})
}

作者:nkuaca    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("mount disk should be asynchronous", func() {
			settings := &fakesettings.FakeSettingsService{}
			_, action := buildMountDiskAction(settings)
			assert.True(GinkgoT(), action.IsAsynchronous())
		})
		It("mount disk", func() {

			settings := &fakesettings.FakeSettingsService{}
			settings.Disks.Persistent = map[string]string{"vol-123": "/dev/sdf"}
			platform, mountDisk := buildMountDiskAction(settings)

			result, err := mountDisk.Run("vol-123")
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), result, "{}")

			assert.True(GinkgoT(), settings.SettingsWereRefreshed)

			assert.Equal(GinkgoT(), platform.MountPersistentDiskDevicePath, "/dev/sdf")
			assert.Equal(GinkgoT(), platform.MountPersistentDiskMountPoint, "/foo/store")
		})
		It("mount disk when store already mounted", func() {

			settings := &fakesettings.FakeSettingsService{}
			settings.Disks.Persistent = map[string]string{"vol-123": "/dev/sdf"}
			platform, mountDisk := buildMountDiskAction(settings)

			platform.IsMountPointResult = true

			result, err := mountDisk.Run("vol-123")
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), result, "{}")

			assert.Equal(GinkgoT(), platform.IsMountPointPath, "/foo/store")

			assert.Equal(GinkgoT(), platform.MountPersistentDiskDevicePath, "/dev/sdf")
			assert.Equal(GinkgoT(), platform.MountPersistentDiskMountPoint, "/foo/store_migration_target")
		})
		It("mount disk when device path not found", func() {

			settings := &fakesettings.FakeSettingsService{}
			settings.Disks.Persistent = map[string]string{"vol-123": "/dev/sdf"}
			_, mountDisk := buildMountDiskAction(settings)

			_, err := mountDisk.Run("vol-456")
			assert.Error(GinkgoT(), err)
		})
	})
}

作者:Jane4PK    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("unmount disk should be asynchronous", func() {
			platform := fakeplatform.NewFakePlatform()
			action := buildUnmountDiskAction(platform)
			Expect(action.IsAsynchronous()).To(BeTrue())
		})

		It("is not persistent", func() {
			platform := fakeplatform.NewFakePlatform()
			action := buildUnmountDiskAction(platform)
			Expect(action.IsPersistent()).To(BeFalse())
		})

		It("unmount disk when the disk is mounted", func() {

			platform := fakeplatform.NewFakePlatform()
			platform.UnmountPersistentDiskDidUnmount = true

			unmountDisk := buildUnmountDiskAction(platform)

			result, err := unmountDisk.Run("vol-123")
			Expect(err).ToNot(HaveOccurred())
			boshassert.MatchesJSONString(GinkgoT(), result, `{"message":"Unmounted partition of /dev/sdf"}`)

			Expect(platform.UnmountPersistentDiskDevicePath).To(Equal("/dev/sdf"))
		})
		It("unmount disk when the disk is not mounted", func() {

			platform := fakeplatform.NewFakePlatform()
			platform.UnmountPersistentDiskDidUnmount = false

			mountDisk := buildUnmountDiskAction(platform)

			result, err := mountDisk.Run("vol-123")
			Expect(err).ToNot(HaveOccurred())
			boshassert.MatchesJSONString(GinkgoT(), result, `{"message":"Partition of /dev/sdf is not mounted"}`)

			Expect(platform.UnmountPersistentDiskDevicePath).To(Equal("/dev/sdf"))
		})
		It("unmount disk when device path not found", func() {

			platform := fakeplatform.NewFakePlatform()
			mountDisk := buildUnmountDiskAction(platform)

			_, err := mountDisk.Run("vol-456")
			Expect(err).To(HaveOccurred())
		})
	})
}

作者:nkuaca    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("ping should be synchronous", func() {

			action := NewPing()
			assert.False(GinkgoT(), action.IsAsynchronous())
		})
		It("ping run returns pong", func() {

			action := NewPing()
			pong, err := action.Run()
			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), "pong", pong)
		})
	})
}

作者:velankanisy    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("logs should be asynchronous", func() {
			_, action := buildLogsAction()
			Expect(action.IsAsynchronous()).To(BeTrue())
		})

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

		It("logs errs if given invalid log type", func() {

			_, action := buildLogsAction()
			_, err := action.Run("other-logs", []string{})
			Expect(err).To(HaveOccurred())
		})
		It("agent logs with filters", func() {

			filters := []string{"**/*.stdout.log", "**/*.stderr.log"}

			expectedFilters := []string{"**/*.stdout.log", "**/*.stderr.log"}
			testLogs(GinkgoT(), "agent", filters, expectedFilters)
		})
		It("agent logs without filters", func() {

			filters := []string{}
			expectedFilters := []string{"**/*"}
			testLogs(GinkgoT(), "agent", filters, expectedFilters)
		})
		It("job logs without filters", func() {

			filters := []string{}
			expectedFilters := []string{"**/*.log"}
			testLogs(GinkgoT(), "job", filters, expectedFilters)
		})
		It("job logs with filters", func() {

			filters := []string{"**/*.stdout.log", "**/*.stderr.log"}

			expectedFilters := []string{"**/*.stdout.log", "**/*.stderr.log"}
			testLogs(GinkgoT(), "job", filters, expectedFilters)
		})
	})
}

作者:nkuaca    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("unmount disk should be asynchronous", func() {
			platform := fakeplatform.NewFakePlatform()
			action := buildUnmountDiskAction(platform)
			assert.True(GinkgoT(), action.IsAsynchronous())
		})
		It("unmount disk when the disk is mounted", func() {

			platform := fakeplatform.NewFakePlatform()
			platform.UnmountPersistentDiskDidUnmount = true

			unmountDisk := buildUnmountDiskAction(platform)

			result, err := unmountDisk.Run("vol-123")
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), result, `{"message":"Unmounted partition of /dev/sdf"}`)

			assert.Equal(GinkgoT(), platform.UnmountPersistentDiskDevicePath, "/dev/sdf")
		})
		It("unmount disk when the disk is not mounted", func() {

			platform := fakeplatform.NewFakePlatform()
			platform.UnmountPersistentDiskDidUnmount = false

			mountDisk := buildUnmountDiskAction(platform)

			result, err := mountDisk.Run("vol-123")
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), result, `{"message":"Partition of /dev/sdf is not mounted"}`)

			assert.Equal(GinkgoT(), platform.UnmountPersistentDiskDevicePath, "/dev/sdf")
		})
		It("unmount disk when device path not found", func() {

			platform := fakeplatform.NewFakePlatform()
			mountDisk := buildUnmountDiskAction(platform)

			_, err := mountDisk.Run("vol-456")
			assert.Error(GinkgoT(), err)
		})
	})
}

作者:nkuaca    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("migrate disk should be asynchronous", func() {
			_, action := buildMigrateDiskAction()
			assert.True(GinkgoT(), action.IsAsynchronous())
		})
		It("migrate disk action run", func() {

			platform, action := buildMigrateDiskAction()

			value, err := action.Run()
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonString(GinkgoT(), value, "{}")

			assert.Equal(GinkgoT(), platform.MigratePersistentDiskFromMountPoint, "/foo/store")
			assert.Equal(GinkgoT(), platform.MigratePersistentDiskToMountPoint, "/foo/store_migration_target")
		})
	})
}

作者:nkuaca    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("prepare network change should be synchronous", func() {
			action, _ := buildPrepareAction()
			assert.False(GinkgoT(), action.IsAsynchronous())
		})
		It("prepare network change", func() {

			action, fs := buildPrepareAction()
			fs.WriteToFile("/etc/udev/rules.d/70-persistent-net.rules", "")

			resp, err := action.Run()

			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), "ok", resp)
			assert.False(GinkgoT(), fs.FileExists("/etc/udev/rules.d/70-persistent-net.rules"))
		})
	})
}

作者:velankanisy    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		var (
			logger   boshlog.Logger
			platform *fakeplatform.FakePlatform
		)

		BeforeEach(func() {
			platform = fakeplatform.NewFakePlatform()
			logger = boshlog.NewLogger(boshlog.LEVEL_NONE)
		})

		It("list disk should be synchronous", func() {
			settings := &fakesettings.FakeSettingsService{}
			action := NewListDisk(settings, platform, logger)
			Expect(action.IsAsynchronous()).To(BeFalse())
		})

		It("is not persistent", func() {
			settings := &fakesettings.FakeSettingsService{}
			action := NewListDisk(settings, platform, logger)
			Expect(action.IsPersistent()).To(BeFalse())
		})

		It("list disk run", func() {
			settings := &fakesettings.FakeSettingsService{
				Disks: boshsettings.Disks{
					Persistent: map[string]string{
						"volume-1": "/dev/sda",
						"volume-2": "/dev/sdb",
						"volume-3": "/dev/sdc",
					},
				},
			}
			platform.MountedDevicePaths = []string{"/dev/sdb", "/dev/sdc"}

			action := NewListDisk(settings, platform, logger)
			value, err := action.Run()
			Expect(err).ToNot(HaveOccurred())
			boshassert.MatchesJsonString(GinkgoT(), value, `["volume-2","volume-3"]`)
		})
	})
}

作者:Bosh-for-Cp    项目:bosh-260   
func init() {
	Describe("Ping", func() {
		It("is synchronous", func() {
			action := NewPing()
			Expect(action.IsAsynchronous()).To(BeFalse())
		})

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

		It("ping run returns pong", func() {
			action := NewPing()
			pong, err := action.Run()
			Expect(err).ToNot(HaveOccurred())
			Expect(pong).To(Equal("pong"))
		})
	})
}

作者:nkuaca    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("logs should be asynchronous", func() {
			_, action := buildLogsAction()
			assert.True(GinkgoT(), action.IsAsynchronous())
		})
		It("logs errs if given invalid log type", func() {

			_, action := buildLogsAction()
			_, err := action.Run("other-logs", []string{})
			assert.Error(GinkgoT(), err)
		})
		It("agent logs with filters", func() {

			filters := []string{"**/*.stdout.log", "**/*.stderr.log"}

			expectedFilters := []string{"**/*.stdout.log", "**/*.stderr.log"}
			testLogs(GinkgoT(), "agent", filters, expectedFilters)
		})
		It("agent logs without filters", func() {

			filters := []string{}
			expectedFilters := []string{"**/*"}
			testLogs(GinkgoT(), "agent", filters, expectedFilters)
		})
		It("job logs without filters", func() {

			filters := []string{}
			expectedFilters := []string{"**/*.log"}
			testLogs(GinkgoT(), "job", filters, expectedFilters)
		})
		It("job logs with filters", func() {

			filters := []string{"**/*.stdout.log", "**/*.stderr.log"}

			expectedFilters := []string{"**/*.stdout.log", "**/*.stderr.log"}
			testLogs(GinkgoT(), "job", filters, expectedFilters)
		})
	})
}

作者:nkuaca    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("stop should be asynchronous", func() {
			_, action := buildStopAction()
			assert.True(GinkgoT(), action.IsAsynchronous())
		})
		It("stop run returns stopped", func() {

			_, action := buildStopAction()
			stopped, err := action.Run()
			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), "stopped", stopped)
		})
		It("stop run stops job supervisor services", func() {

			jobSupervisor, action := buildStopAction()

			_, err := action.Run()
			assert.NoError(GinkgoT(), err)

			assert.True(GinkgoT(), jobSupervisor.Stopped)
		})
	})
}

作者:nkuaca    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("get state should be synchronous", func() {
			settings := &fakesettings.FakeSettingsService{}
			_, _, _, action := buildGetStateAction(settings)
			assert.False(GinkgoT(), action.IsAsynchronous())
		})
		It("get state run", func() {

			settings := &fakesettings.FakeSettingsService{}
			settings.AgentId = "my-agent-id"
			settings.Vm.Name = "vm-abc-def"

			specService, jobSupervisor, _, action := buildGetStateAction(settings)
			jobSupervisor.StatusStatus = "running"

			specService.Spec = boshas.V1ApplySpec{
				Deployment: "fake-deployment",
			}

			expectedSpec := GetStateV1ApplySpec{
				AgentId:      "my-agent-id",
				JobState:     "running",
				BoshProtocol: "1",
				Vm:           boshsettings.Vm{Name: "vm-abc-def"},
				Ntp: boshntp.NTPInfo{
					Offset:    "0.34958",
					Timestamp: "12 Oct 17:37:58",
				},
			}
			expectedSpec.Deployment = "fake-deployment"

			state, err := action.Run()
			assert.NoError(GinkgoT(), err)

			assert.Equal(GinkgoT(), state.AgentId, expectedSpec.AgentId)
			assert.Equal(GinkgoT(), state.JobState, expectedSpec.JobState)
			assert.Equal(GinkgoT(), state.Deployment, expectedSpec.Deployment)
			boshassert.LacksJsonKey(GinkgoT(), state, "vitals")

			assert.Equal(GinkgoT(), state, expectedSpec)
		})
		It("get state run without current spec", func() {

			settings := &fakesettings.FakeSettingsService{}
			settings.AgentId = "my-agent-id"
			settings.Vm.Name = "vm-abc-def"

			specService, jobSupervisor, _, action := buildGetStateAction(settings)
			jobSupervisor.StatusStatus = "running"

			specService.GetErr = errors.New("some error")
			specService.Spec = boshas.V1ApplySpec{
				Deployment: "fake-deployment",
			}

			expectedSpec := GetStateV1ApplySpec{
				AgentId:      "my-agent-id",
				JobState:     "running",
				BoshProtocol: "1",
				Vm:           boshsettings.Vm{Name: "vm-abc-def"},
				Ntp: boshntp.NTPInfo{
					Offset:    "0.34958",
					Timestamp: "12 Oct 17:37:58",
				},
			}

			state, err := action.Run()
			assert.NoError(GinkgoT(), err)
			boshassert.MatchesJsonMap(GinkgoT(), expectedSpec.Ntp, map[string]interface{}{
				"offset":    "0.34958",
				"timestamp": "12 Oct 17:37:58",
			})
			assert.Equal(GinkgoT(), state, expectedSpec)
		})
		It("get state run with full format option", func() {

			settings := &fakesettings.FakeSettingsService{}
			settings.AgentId = "my-agent-id"
			settings.Vm.Name = "vm-abc-def"

			specService, jobSupervisor, fakeVitals, action := buildGetStateAction(settings)
			jobSupervisor.StatusStatus = "running"

			specService.Spec = boshas.V1ApplySpec{
				Deployment: "fake-deployment",
			}

			expectedVitals := boshvitals.Vitals{
				Load: []string{"foo", "bar", "baz"},
			}
			fakeVitals.GetVitals = expectedVitals
			expectedVm := map[string]interface{}{"name": "vm-abc-def"}

			state, err := action.Run("full")
			assert.NoError(GinkgoT(), err)

			boshassert.MatchesJsonString(GinkgoT(), state.AgentId, `"my-agent-id"`)
			boshassert.MatchesJsonString(GinkgoT(), state.JobState, `"running"`)
			boshassert.MatchesJsonString(GinkgoT(), state.Deployment, `"fake-deployment"`)
//.........这里部分代码省略.........

作者:velankanisy    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("apply should be asynchronous", func() {
			_, _, action := buildApplyAction()
			Expect(action.IsAsynchronous()).To(BeTrue())
		})

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

		It("apply returns applied", func() {
			_, _, action := buildApplyAction()

			applySpec := boshas.V1ApplySpec{
				ConfigurationHash: "fake-config-hash",
			}

			value, err := action.Run(applySpec)
			Expect(err).ToNot(HaveOccurred())

			boshassert.MatchesJsonString(GinkgoT(), value, `"applied"`)
		})

		It("apply run saves the first argument to spec json", func() {
			_, specService, action := buildApplyAction()

			applySpec := boshas.V1ApplySpec{
				ConfigurationHash: "fake-config-hash",
			}

			_, err := action.Run(applySpec)
			Expect(err).ToNot(HaveOccurred())
			Expect(applySpec).To(Equal(specService.Spec))
		})

		It("apply run skips applier when apply spec does not have configuration hash", func() {
			applier, _, action := buildApplyAction()

			applySpec := boshas.V1ApplySpec{
				JobSpec: boshas.JobSpec{
					Template: "fake-job-template",
				},
			}

			_, err := action.Run(applySpec)
			Expect(err).ToNot(HaveOccurred())
			Expect(applier.Applied).To(BeFalse())
		})

		It("apply run runs applier with apply spec when apply spec has configuration hash", func() {
			applier, _, action := buildApplyAction()

			expectedApplySpec := boshas.V1ApplySpec{
				JobSpec: boshas.JobSpec{
					Template: "fake-job-template",
				},
				ConfigurationHash: "fake-config-hash",
			}

			_, err := action.Run(expectedApplySpec)
			Expect(err).ToNot(HaveOccurred())
			Expect(applier.Applied).To(BeTrue())
			Expect(expectedApplySpec).To(Equal(applier.ApplyApplySpec))
		})

		It("apply run errs when applier fails", func() {
			applier, _, action := buildApplyAction()

			applier.ApplyError = errors.New("fake-apply-error")

			_, err := action.Run(boshas.V1ApplySpec{ConfigurationHash: "fake-config-hash"})
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-apply-error"))
		})
	})
}

作者:reneed    项目:bos   
func TestListDiskShouldBeSynchronous(t *testing.T) {
	settings := &fakesettings.FakeSettingsService{}
	platform := fakeplatform.NewFakePlatform()
	action := NewListDisk(settings, platform)
	assert.False(t, action.IsAsynchronous())
}

作者:nkuaca    项目:bos   
func init() {
	Describe("Testing with Ginkgo", func() {
		It("drain should be asynchronous", func() {
			_, _, action := buildDrain()
			assert.True(GinkgoT(), action.IsAsynchronous())
		})
		It("drain run update skips drain script when without drain script", func() {

			_, fakeDrainProvider, action := buildDrain()

			newSpec := boshas.V1ApplySpec{
				PackageSpecs: map[string]boshas.PackageSpec{
					"foo": boshas.PackageSpec{
						Name: "foo",
						Sha1: "foo-sha1-new",
					},
				},
			}

			fakeDrainProvider.NewDrainScriptDrainScript.ExistsBool = false

			_, err := action.Run(DrainTypeUpdate, newSpec)
			assert.NoError(GinkgoT(), err)
			assert.False(GinkgoT(), fakeDrainProvider.NewDrainScriptDrainScript.DidRun)
		})
		It("drain run shutdown skips drain script when without drain script", func() {

			_, fakeDrainProvider, action := buildDrain()

			newSpec := boshas.V1ApplySpec{
				PackageSpecs: map[string]boshas.PackageSpec{
					"foo": boshas.PackageSpec{
						Name: "foo",
						Sha1: "foo-sha1-new",
					},
				},
			}

			fakeDrainProvider.NewDrainScriptDrainScript.ExistsBool = false

			_, err := action.Run(DrainTypeShutdown, newSpec)
			assert.NoError(GinkgoT(), err)
			assert.False(GinkgoT(), fakeDrainProvider.NewDrainScriptDrainScript.DidRun)
		})
		It("drain run status errs when without drain script", func() {

			_, fakeDrainProvider, action := buildDrain()

			fakeDrainProvider.NewDrainScriptDrainScript.ExistsBool = false

			_, err := action.Run(DrainTypeStatus)
			assert.Error(GinkgoT(), err)
		})
		It("drain errs when drain script exits with error", func() {

			_, fakeDrainScriptProvider, action := buildDrain()

			fakeDrainScriptProvider.NewDrainScriptDrainScript.RunExitStatus = 0
			fakeDrainScriptProvider.NewDrainScriptDrainScript.RunError = errors.New("Fake error")

			value, err := action.Run(DrainTypeStatus)
			assert.Equal(GinkgoT(), value, 0)
			assert.Error(GinkgoT(), err)
		})
		It("run with update errs if not given new spec", func() {

			_, _, action := buildDrain()
			_, err := action.Run(DrainTypeUpdate)
			assert.Error(GinkgoT(), err)
		})
		It("run with update runs drain with updated packages", func() {

			_, fakeDrainScriptProvider, action := buildDrain()

			newSpec := boshas.V1ApplySpec{
				PackageSpecs: map[string]boshas.PackageSpec{
					"foo": boshas.PackageSpec{
						Name: "foo",
						Sha1: "foo-sha1-new",
					},
				},
			}

			drainStatus, err := action.Run(DrainTypeUpdate, newSpec)
			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), 1, drainStatus)
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptTemplateName, "foo")
			assert.True(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.DidRun)
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.JobChange(), "job_new")
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.HashChange(), "hash_new")
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.UpdatedPackages(), []string{"foo"})
		})
		It("run with shutdown", func() {

			fakeNotifier, fakeDrainScriptProvider, action := buildDrain()

			drainStatus, err := action.Run(DrainTypeShutdown)
			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), 1, drainStatus)
			assert.Equal(GinkgoT(), fakeDrainScriptProvider.NewDrainScriptTemplateName, "foo")
//.........这里部分代码省略.........

作者:reneed    项目:bos   
func TestGetTaskShouldBeSynchronous(t *testing.T) {
	_, action := buildGetTaskAction()
	assert.False(t, action.IsAsynchronous())
}


问题


面经


文章

微信
公众号

扫码关注公众号