func TestApplyAppliesJobs(t *testing.T) {
	jobApplier, _, _, _, applier := buildApplier()
	job := buildJob()

	err := applier.Apply(&fakeas.FakeApplySpec{JobResults: []models.Job{job}})
	assert.NoError(t, err)
	assert.Equal(t, jobApplier.AppliedJobs, []models.Job{job})
}
func TestApplyErrsIfMonitorFailsReload(t *testing.T) {
	_, _, _, jobSupervisor, applier := buildApplier()
	jobs := []models.Job{}
	jobSupervisor.ReloadErr = errors.New("error reloading monit")

	err := applier.Apply(&fakeas.FakeApplySpec{JobResults: jobs})
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "error reloading monit")
}
func TestApplyErrsIfSetupLogrotateFails(t *testing.T) {
	_, _, platform, _, applier := buildApplier()

	platform.SetupLogrotateErr = errors.New("fake-msg")

	err := applier.Apply(&fakeas.FakeApplySpec{})
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "Logrotate setup failed: fake-msg")
}
func TestApplyErrsWhenApplyingPackagesErrs(t *testing.T) {
	_, packageApplier, _, _, applier := buildApplier()
	pkg := buildPackage()

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

	err := applier.Apply(&fakeas.FakeApplySpec{PackageResults: []models.Package{pkg}})
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "fake-apply-package-error")
}
func TestApplyAppliesPackages(t *testing.T) {
	_, packageApplier, _, _, applier := buildApplier()

	pkg1 := buildPackage()
	pkg2 := buildPackage()

	err := applier.Apply(&fakeas.FakeApplySpec{PackageResults: []models.Package{pkg1, pkg2}})
	assert.NoError(t, err)
	assert.Equal(t, packageApplier.AppliedPackages, []models.Package{pkg1, pkg2})
}
func TestApplyErrsWhenApplyingJobsErrs(t *testing.T) {
	jobApplier, _, _, _, applier := buildApplier()
	job := buildJob()

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

	err := applier.Apply(&fakeas.FakeApplySpec{JobResults: []models.Job{job}})
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "fake-apply-job-error")
}
func TestApplyErrsIfAJobFailsConfiguring(t *testing.T) {
	jobApplier, _, _, _, applier := buildApplier()
	jobApplier.ConfigureError = errors.New("error configuring job")

	job := models.Job{Name: "fake-job-name-1", Version: "fake-version-name-1"}

	err := applier.Apply(&fakeas.FakeApplySpec{JobResults: []models.Job{job}})
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "error configuring job")
}
func TestApplySetsUpLogrotation(t *testing.T) {
	_, _, platform, _, applier := buildApplier()

	err := applier.Apply(&fakeas.FakeApplySpec{MaxLogFileSizeResult: "fake-size"})
	assert.NoError(t, err)
	assert.Equal(t, platform.SetupLogrotateArgs, SetupLogrotateArgs{
		GroupName: boshsettings.VCAP_USERNAME,
		BasePath:  "/fake-base-dir",
		Size:      "fake-size",
	})
}
func TestApplyConfiguresJobs(t *testing.T) {
	jobApplier, _, _, jobSupervisor, applier := buildApplier()

	job1 := models.Job{Name: "fake-job-name-1", Version: "fake-version-name-1"}
	job2 := models.Job{Name: "fake-job-name-2", Version: "fake-version-name-2"}
	jobs := []models.Job{job1, job2}

	err := applier.Apply(&fakeas.FakeApplySpec{JobResults: jobs})
	assert.NoError(t, err)
	assert.Equal(t, jobApplier.ConfiguredJobs, []models.Job{job2, job1})
	assert.Equal(t, jobApplier.ConfiguredJobIndices, []int{0, 1})

	assert.True(t, jobSupervisor.Reloaded)
}
Exemple #10
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("apply applies jobs", func() {
			jobApplier, _, _, _, applier := buildApplier()
			job := buildJob()

			err := applier.Apply(&fakeas.FakeApplySpec{JobResults: []models.Job{job}})
			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), jobApplier.AppliedJobs, []models.Job{job})
		})
		It("apply errs when applying jobs errs", func() {

			jobApplier, _, _, _, applier := buildApplier()
			job := buildJob()

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

			err := applier.Apply(&fakeas.FakeApplySpec{JobResults: []models.Job{job}})
			assert.Error(GinkgoT(), err)
			assert.Contains(GinkgoT(), err.Error(), "fake-apply-job-error")
		})
		It("apply applies packages", func() {

			_, packageApplier, _, _, applier := buildApplier()

			pkg1 := buildPackage()
			pkg2 := buildPackage()

			err := applier.Apply(&fakeas.FakeApplySpec{PackageResults: []models.Package{pkg1, pkg2}})
			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), packageApplier.AppliedPackages, []models.Package{pkg1, pkg2})
		})
		It("apply errs when applying packages errs", func() {

			_, packageApplier, _, _, applier := buildApplier()
			pkg := buildPackage()

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

			err := applier.Apply(&fakeas.FakeApplySpec{PackageResults: []models.Package{pkg}})
			assert.Error(GinkgoT(), err)
			assert.Contains(GinkgoT(), err.Error(), "fake-apply-package-error")
		})
		It("apply configures jobs", func() {

			jobApplier, _, _, jobSupervisor, applier := buildApplier()

			job1 := models.Job{Name: "fake-job-name-1", Version: "fake-version-name-1"}
			job2 := models.Job{Name: "fake-job-name-2", Version: "fake-version-name-2"}
			jobs := []models.Job{job1, job2}

			err := applier.Apply(&fakeas.FakeApplySpec{JobResults: jobs})
			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), jobApplier.ConfiguredJobs, []models.Job{job2, job1})
			assert.Equal(GinkgoT(), jobApplier.ConfiguredJobIndices, []int{0, 1})

			assert.True(GinkgoT(), jobSupervisor.Reloaded)
		})
		It("apply errs if monitor fails reload", func() {

			_, _, _, jobSupervisor, applier := buildApplier()
			jobs := []models.Job{}
			jobSupervisor.ReloadErr = errors.New("error reloading monit")

			err := applier.Apply(&fakeas.FakeApplySpec{JobResults: jobs})
			assert.Error(GinkgoT(), err)
			assert.Contains(GinkgoT(), err.Error(), "error reloading monit")
		})
		It("apply errs if a job fails configuring", func() {

			jobApplier, _, _, _, applier := buildApplier()
			jobApplier.ConfigureError = errors.New("error configuring job")

			job := models.Job{Name: "fake-job-name-1", Version: "fake-version-name-1"}

			err := applier.Apply(&fakeas.FakeApplySpec{JobResults: []models.Job{job}})
			assert.Error(GinkgoT(), err)
			assert.Contains(GinkgoT(), err.Error(), "error configuring job")
		})
		It("apply sets up logrotation", func() {

			_, _, platform, _, applier := buildApplier()

			err := applier.Apply(&fakeas.FakeApplySpec{MaxLogFileSizeResult: "fake-size"})
			assert.NoError(GinkgoT(), err)
			assert.Equal(GinkgoT(), platform.SetupLogrotateArgs, SetupLogrotateArgs{
				GroupName: boshsettings.VCAP_USERNAME,
				BasePath:  "/fake-base-dir",
				Size:      "fake-size",
			})
		})
		It("apply errs if setup logrotate fails", func() {

			_, _, platform, _, applier := buildApplier()

			platform.SetupLogrotateErr = errors.New("fake-msg")

			err := applier.Apply(&fakeas.FakeApplySpec{})
			assert.Error(GinkgoT(), err)
			assert.Contains(GinkgoT(), err.Error(), "Logrotate setup failed: fake-msg")
		})
	})
}