作者: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",
})
})
})
}
作者: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"))
})
})
}
作者:velankanisy
项目:bos
func testSshSetupWithGivenPassword(t assert.TestingT, expectedPwd string) {
settings := &fakesettings.FakeSettingsService{}
settings.DefaultIp = "ww.xx.yy.zz"
platform, action := buildSshAction(settings)
expectedUser := "some-user"
expectedKey := "some public key content"
params := SshParams{
User: expectedUser,
PublicKey: expectedKey,
Password: expectedPwd,
}
response, err := action.Run("setup", params)
assert.NoError(t, err)
assert.Equal(t, expectedUser, platform.CreateUserUsername)
assert.Equal(t, expectedPwd, platform.CreateUserPassword)
assert.Equal(t, "/foo/bosh_ssh", platform.CreateUserBasePath)
assert.Equal(t, []string{boshsettings.VCAP_USERNAME, boshsettings.ADMIN_GROUP}, platform.AddUserToGroupsGroups[expectedUser])
assert.Equal(t, expectedKey, platform.SetupSshPublicKeys[expectedUser])
expectedJson := map[string]interface{}{
"command": "setup",
"status": "success",
"ip": "ww.xx.yy.zz",
}
boshassert.MatchesJsonMap(t, response, expectedJson)
}
作者:amulya
项目:bosh-cloudstack-cp
func testSSHSetupWithGivenPassword(expectedPwd string) {
settingsService := &fakesettings.FakeSettingsService{}
settingsService.Settings.Networks = boshsettings.Networks{
"fake-net": boshsettings.Network{IP: "ww.xx.yy.zz"},
}
platform, action := buildSSHAction(settingsService)
params := SSHParams{
User: "fake-user",
PublicKey: "fake-public-key",
Password: expectedPwd,
}
response, err := action.Run("setup", params)
Expect(err).ToNot(HaveOccurred())
Expect(response).To(Equal(SSHResult{
Command: "setup",
Status: "success",
IP: "ww.xx.yy.zz",
}))
Expect(platform.CreateUserUsername).To(Equal("fake-user"))
Expect(platform.CreateUserPassword).To(Equal(expectedPwd))
Expect(platform.CreateUserBasePath).To(Equal("/foo/bosh_ssh"))
Expect(platform.AddUserToGroupsGroups["fake-user"]).To(Equal(
[]string{boshsettings.VCAPUsername, boshsettings.AdminGroup},
))
Expect(platform.SetupSSHPublicKeys["fake-user"]).To(Equal("fake-public-key"))
}
作者: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"]`)
})
})
}
作者:reneed
项目:bos
func TestStartRunReturnsStarted(t *testing.T) {
_, action := buildStartAction()
started, err := action.Run()
assert.NoError(t, err)
assert.Equal(t, "started", started)
}
作者:velankanisy
项目:bos
func testLogs(t assert.TestingT, logType string, filters []string, expectedFilters []string) {
deps, action := buildLogsAction()
deps.copier.FilteredCopyToTempTempDir = "/fake-temp-dir"
deps.compressor.CompressFilesInDirTarballPath = "logs_test.go"
deps.blobstore.CreateBlobId = "my-blob-id"
logs, err := action.Run(logType, filters)
assert.NoError(t, err)
var expectedPath string
switch logType {
case "job":
expectedPath = filepath.Join("/fake", "dir", "sys", "log")
case "agent":
expectedPath = filepath.Join("/fake", "dir", "bosh", "log")
}
assert.Equal(t, expectedPath, deps.copier.FilteredCopyToTempDir)
assert.Equal(t, expectedFilters, deps.copier.FilteredCopyToTempFilters)
assert.Equal(t, deps.copier.FilteredCopyToTempTempDir, deps.compressor.CompressFilesInDirDir)
assert.Equal(t, deps.copier.CleanUpTempDir, deps.compressor.CompressFilesInDirDir)
assert.Equal(t, deps.compressor.CompressFilesInDirTarballPath, deps.blobstore.CreateFileName)
boshassert.MatchesJsonString(t, logs, `{"blobstore_id":"my-blob-id"}`)
}
作者:reneed
项目:bos
func TestStartRunStartsMonitorServices(t *testing.T) {
jobSupervisor, action := buildStartAction()
_, err := action.Run()
assert.NoError(t, err)
assert.True(t, jobSupervisor.Started)
}
作者:reneed
项目:bos
func TestStopRunStopsJobSupervisorServices(t *testing.T) {
jobSupervisor, action := buildStopAction()
_, err := action.Run()
assert.NoError(t, err)
assert.True(t, jobSupervisor.Stopped)
}
作者:reneed
项目:bos
func TestDrainRunStatusErrsWhenWithoutDrainScript(t *testing.T) {
_, fakeDrainProvider, action := buildDrain()
fakeDrainProvider.NewDrainScriptDrainScript.ExistsBool = false
_, err := action.Run(DrainTypeStatus)
assert.Error(t, err)
}
作者:reneed
项目:bos
func TestGetTaskRunWhenTaskIsNotFound(t *testing.T) {
taskService, action := buildGetTaskAction()
taskService.Tasks = map[string]boshtask.Task{}
_, err := action.Run("57")
assert.Error(t, err)
assert.Equal(t, "Task with id 57 could not be found", err.Error())
}
作者:reneed
项目:bos
func TestApplyRunErrsWhenApplierFails(t *testing.T) {
applier, _, action := buildApplyAction()
applier.ApplyError = errors.New("fake-apply-error")
_, err := action.Run(boshas.V1ApplySpec{ConfigurationHash: "fake-config-hash"})
assert.Error(t, err)
assert.Contains(t, err.Error(), "fake-apply-error")
}
作者:reneed
项目:bos
func TestDrainErrsWhenDrainScriptExitsWithError(t *testing.T) {
_, fakeDrainScriptProvider, action := buildDrain()
fakeDrainScriptProvider.NewDrainScriptDrainScript.RunExitStatus = 0
fakeDrainScriptProvider.NewDrainScriptDrainScript.RunError = errors.New("Fake error")
value, err := action.Run(DrainTypeStatus)
assert.Equal(t, value, 0)
assert.Error(t, err)
}
作者:reneed
项目:bos
func TestMigrateDiskActionRun(t *testing.T) {
platform, action := buildMigrateDiskAction()
value, err := action.Run()
assert.NoError(t, err)
boshassert.MatchesJsonString(t, value, "{}")
assert.Equal(t, platform.MigratePersistentDiskFromMountPoint, "/foo/store")
assert.Equal(t, platform.MigratePersistentDiskToMountPoint, "/foo/store_migration_target")
}
作者:reneed
项目:bos
func TestPrepareNetworkChange(t *testing.T) {
action, fs := buildPrepareAction()
fs.WriteToFile("/etc/udev/rules.d/70-persistent-net.rules", "")
resp, err := action.Run()
assert.NoError(t, err)
assert.Equal(t, "ok", resp)
assert.False(t, fs.FileExists("/etc/udev/rules.d/70-persistent-net.rules"))
}
作者:reneed
项目:bos
func TestRun(t *testing.T) {
platform := fakeplatform.NewFakePlatform()
_, err := platform.GetFs().WriteToFile("/var/vcap/micro/apply_spec.json", `{"json":["objects"]}`)
assert.NoError(t, err)
action := NewReleaseApplySpec(platform)
value, err := action.Run()
assert.NoError(t, err)
assert.Equal(t, value, map[string]interface{}{"json": []interface{}{"objects"}})
}
作者:reneed
项目:bos
func TestCompilePackageErrsWhenCompileFails(t *testing.T) {
compiler, action := buildCompilePackageAction()
compiler.CompileErr = errors.New("Oops")
blobId, sha1, name, version, deps := getCompileActionArguments()
_, err := action.Run(blobId, sha1, name, version, deps)
assert.Error(t, err)
assert.Contains(t, err.Error(), compiler.CompileErr.Error())
}
作者:reneed
项目:bos
func TestRunWithStatus(t *testing.T) {
_, fakeDrainScriptProvider, action := buildDrain()
drainStatus, err := action.Run(DrainTypeStatus)
assert.NoError(t, err)
assert.Equal(t, 1, drainStatus)
assert.Equal(t, fakeDrainScriptProvider.NewDrainScriptTemplateName, "foo")
assert.True(t, fakeDrainScriptProvider.NewDrainScriptDrainScript.DidRun)
assert.Equal(t, fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.JobChange(), "job_check_status")
assert.Equal(t, fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.HashChange(), "hash_unchanged")
assert.Equal(t, fakeDrainScriptProvider.NewDrainScriptDrainScript.RunParams.UpdatedPackages(), []string{})
}
作者:reneed
项目:bos
func TestApplyRunSavesTheFirstArgumentToSpecJson(t *testing.T) {
_, specService, action := buildApplyAction()
applySpec := boshas.V1ApplySpec{
JobSpec: boshas.JobSpec{
Name: "router",
},
}
_, err := action.Run(applySpec)
assert.NoError(t, err)
assert.Equal(t, applySpec, specService.Spec)
}
作者:reneed
项目:bos
func TestApplyRunSkipsApplierWhenApplySpecDoesNotHaveConfigurationHash(t *testing.T) {
applier, _, action := buildApplyAction()
applySpec := boshas.V1ApplySpec{
JobSpec: boshas.JobSpec{
Template: "fake-job-template",
},
}
_, err := action.Run(applySpec)
assert.NoError(t, err)
assert.False(t, applier.Applied)
}