From 5c6cc6bd504bcc8ef1b46972636654a615fb1d51 Mon Sep 17 00:00:00 2001 From: Onsi Fakhouri Date: Wed, 7 May 2014 10:12:21 -0700 Subject: [PATCH] remove pivotal-cf-experimental/cf-test-helpers and bump deps --- Godeps/Godeps.json | 6 +- .../internal/leafnodes/shared_runner_test.go | 5 + .../ginkgo/internal/remote/aggregator_test.go | 50 +++---- .../ginkgo/internal/specrunner/spec_runner.go | 3 +- .../internal/specrunner/spec_runner_test.go | 20 ++- .../ginkgo/reporters/default_reporter_test.go | 74 +++++----- .../stenographer/fake_stenographer.go | 31 ++++- .../onsi/gomega/gbytes/say_matcher.go | 11 +- .../onsi/gomega/gbytes/say_matcher_test.go | 19 ++- .../onsi/gomega/gexec/exit_matcher_test.go | 4 +- .../onsi/gomega/gexec/session_test.go | 15 +- .../github.com/onsi/gomega/ghttp/handlers.go | 87 +++++++++--- .../onsi/gomega/ghttp/test_server_test.go | 80 ++++++++--- .../cf-test-helpers/cf/api.go | 35 ----- .../cf-test-helpers/cf/api_test.go | 28 ---- .../cf-test-helpers/cf/as_user.go | 60 -------- .../cf-test-helpers/cf/as_user_test.go | 131 ------------------ .../cf-test-helpers/cf/cf.go | 10 -- .../cf-test-helpers/cf/cf_suite_test.go | 23 --- .../cf-test-helpers/cf/cf_test.go | 24 ---- .../cf-test-helpers/cf/user_context.go | 22 --- .../cf-test-helpers/cf/user_context_test.go | 39 ------ .../cf-test-helpers/generator/random_name.go | 14 -- .../cf-test-helpers/runner/run.go | 43 ------ .../cf-test-helpers/runner/run_test.go | 26 ---- .../runner/runner_suite_test.go | 13 -- apps/delete_route_test.go | 4 +- 27 files changed, 278 insertions(+), 599 deletions(-) delete mode 100644 Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/api.go delete mode 100644 Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/api_test.go delete mode 100644 Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/as_user.go delete mode 100644 Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/as_user_test.go delete mode 100644 Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/cf.go delete mode 100644 Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/cf_suite_test.go delete mode 100644 Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/cf_test.go delete mode 100644 Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/user_context.go delete mode 100644 Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/user_context_test.go delete mode 100644 Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/generator/random_name.go delete mode 100644 Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/runner/run.go delete mode 100644 Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/runner/run_test.go delete mode 100644 Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/runner/runner_suite_test.go diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index a2718b3c0..ce2b84e0f 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -23,15 +23,15 @@ }, { "ImportPath": "github.com/onsi/ginkgo", - "Rev": "2a0c5c3f92805fd1f431dfbe22625e811b6b3f18" + "Rev": "51ddbbc2ace9f9ad4cf06ba63442ea2ef2019837" }, { "ImportPath": "github.com/onsi/gomega", - "Rev": "660b70079010c9eeeffdc381fcb3a8cde45ce495" + "Rev": "f5533d435ebfcf4fa0463202dc0e966b983618b8" }, { "ImportPath": "github.com/pivotal-golang/archiver/extractor/test_helper", - "Rev": "338bf2b31d42f9ff6f57e0944cf5628bdfee546c" + "Rev": "e46831b67d1f71fe27f85b6b4224e2cf55efea8a" } ] } diff --git a/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/leafnodes/shared_runner_test.go b/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/leafnodes/shared_runner_test.go index 350f2579f..1293d240a 100644 --- a/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/leafnodes/shared_runner_test.go +++ b/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/leafnodes/shared_runner_test.go @@ -193,16 +193,21 @@ func AsynchronousSharedRunnerBehaviors(build func(body interface{}, timeout time }) Context("when the function times out", func() { + var guard chan struct{} + BeforeEach(func() { + guard = make(chan struct{}) outcome, failure = build(func(done Done) { didRun = true time.Sleep(20 * time.Millisecond) + close(guard) panic("doesn't matter") close(done) }, 10*time.Millisecond, failer, componentCodeLocation).Run() }) It("should return the timeout", func() { + <-guard Ω(didRun).Should(BeTrue()) Ω(outcome).Should(Equal(types.SpecStateTimedOut)) diff --git a/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/remote/aggregator_test.go b/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/remote/aggregator_test.go index 96c5e55c7..0fcfb388d 100644 --- a/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/remote/aggregator_test.go +++ b/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/remote/aggregator_test.go @@ -4,11 +4,11 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "time" "github.com/onsi/ginkgo/config" . "github.com/onsi/ginkgo/internal/remote" st "github.com/onsi/ginkgo/reporters/stenographer" "github.com/onsi/ginkgo/types" - "time" ) var _ = Describe("Aggregator", func() { @@ -108,7 +108,7 @@ var _ = Describe("Aggregator", func() { aggregator.SpecSuiteWillBegin(ginkgoConfig2, suiteSummary2) aggregator.SpecSuiteWillBegin(ginkgoConfig1, suiteSummary1) Eventually(func() interface{} { - return len(stenographer.Calls) + return len(stenographer.Calls()) }).Should(BeNumerically(">=", 3)) } @@ -119,7 +119,7 @@ var _ = Describe("Aggregator", func() { }) It("should be silent", func() { - Consistently(func() interface{} { return stenographer.Calls }).Should(BeEmpty()) + Consistently(func() interface{} { return stenographer.Calls() }).Should(BeEmpty()) }) }) @@ -128,15 +128,15 @@ var _ = Describe("Aggregator", func() { aggregator.SpecSuiteWillBegin(ginkgoConfig2, suiteSummary2) aggregator.SpecSuiteWillBegin(ginkgoConfig1, suiteSummary1) Eventually(func() interface{} { - return stenographer.Calls + return stenographer.Calls() }).Should(HaveLen(3)) }) It("should announce the beginning of the suite", func() { - Ω(stenographer.Calls).Should(HaveLen(3)) - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSuite", suiteDescription, ginkgoConfig1.RandomSeed, true, false))) - Ω(stenographer.Calls[1]).Should(Equal(call("AnnounceNumberOfSpecs", 23, 30, false))) - Ω(stenographer.Calls[2]).Should(Equal(call("AnnounceAggregatedParallelRun", 2, false))) + Ω(stenographer.Calls()).Should(HaveLen(3)) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuite", suiteDescription, ginkgoConfig1.RandomSeed, true, false))) + Ω(stenographer.Calls()[1]).Should(Equal(call("AnnounceNumberOfSpecs", 23, 30, false))) + Ω(stenographer.Calls()[2]).Should(Equal(call("AnnounceAggregatedParallelRun", 2, false))) }) }) }) @@ -150,7 +150,7 @@ var _ = Describe("Aggregator", func() { }) It("should not announce any specs", func() { - Consistently(func() interface{} { return stenographer.Calls }).Should(BeEmpty()) + Consistently(func() interface{} { return stenographer.Calls() }).Should(BeEmpty()) }) Context("when the parallel-suites subsequently start", func() { @@ -160,11 +160,11 @@ var _ = Describe("Aggregator", func() { It("should announce the specs, the before suites and the after suites", func() { Eventually(func() interface{} { - return stenographer.Calls + return stenographer.Calls() }).Should(ContainElement(call("AnnounceSuccesfulSpec", specSummary))) - Ω(stenographer.Calls).Should(ContainElement(call("AnnounceCapturedOutput", beforeSummary.CapturedOutput))) - Ω(stenographer.Calls).Should(ContainElement(call("AnnounceCapturedOutput", afterSummary.CapturedOutput))) + Ω(stenographer.Calls()).Should(ContainElement(call("AnnounceCapturedOutput", beforeSummary.CapturedOutput))) + Ω(stenographer.Calls()).Should(ContainElement(call("AnnounceCapturedOutput", afterSummary.CapturedOutput))) }) }) }) @@ -181,28 +181,28 @@ var _ = Describe("Aggregator", func() { aggregator.SpecDidComplete(specSummary) aggregator.AfterSuiteDidRun(afterSummary) Eventually(func() interface{} { - return stenographer.Calls + return stenographer.Calls() }).Should(HaveLen(5)) }) It("should announce the captured output of the BeforeSuite", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceCapturedOutput", beforeSummary.CapturedOutput))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceCapturedOutput", beforeSummary.CapturedOutput))) }) It("should announce that the spec will run (when in verbose mode)", func() { - Ω(stenographer.Calls[1]).Should(Equal(call("AnnounceSpecWillRun", specSummary))) + Ω(stenographer.Calls()[1]).Should(Equal(call("AnnounceSpecWillRun", specSummary))) }) It("should announce the captured stdout of the spec", func() { - Ω(stenographer.Calls[2]).Should(Equal(call("AnnounceCapturedOutput", specSummary.CapturedOutput))) + Ω(stenographer.Calls()[2]).Should(Equal(call("AnnounceCapturedOutput", specSummary.CapturedOutput))) }) It("should announce completion", func() { - Ω(stenographer.Calls[3]).Should(Equal(call("AnnounceSuccesfulSpec", specSummary))) + Ω(stenographer.Calls()[3]).Should(Equal(call("AnnounceSuccesfulSpec", specSummary))) }) It("should announce the captured output of the AfterSuite", func() { - Ω(stenographer.Calls[4]).Should(Equal(call("AnnounceCapturedOutput", afterSummary.CapturedOutput))) + Ω(stenographer.Calls()[4]).Should(Equal(call("AnnounceCapturedOutput", afterSummary.CapturedOutput))) }) }) }) @@ -220,7 +220,7 @@ var _ = Describe("Aggregator", func() { }) It("should be silent", func() { - Consistently(func() interface{} { return stenographer.Calls }).Should(BeEmpty()) + Consistently(func() interface{} { return stenographer.Calls() }).Should(BeEmpty()) }) It("should not notify the channel", func() { @@ -242,12 +242,12 @@ var _ = Describe("Aggregator", func() { aggregator.SpecSuiteDidEnd(suiteSummary2) aggregator.SpecSuiteDidEnd(suiteSummary1) Eventually(func() interface{} { - return stenographer.Calls + return stenographer.Calls() }).Should(HaveLen(1)) }) It("should announce the end of the suite", func() { - compositeSummary := stenographer.Calls[0].Args[0].(*types.SuiteSummary) + compositeSummary := stenographer.Calls()[0].Args[0].(*types.SuiteSummary) Ω(compositeSummary.SuiteSucceeded).Should(BeFalse()) Ω(compositeSummary.NumberOfSpecsThatWillBeRun).Should(Equal(23)) @@ -268,12 +268,12 @@ var _ = Describe("Aggregator", func() { aggregator.SpecSuiteDidEnd(suiteSummary2) aggregator.SpecSuiteDidEnd(suiteSummary1) Eventually(func() interface{} { - return stenographer.Calls + return stenographer.Calls() }).Should(HaveLen(1)) }) It("should report success", func() { - compositeSummary := stenographer.Calls[0].Args[0].(*types.SuiteSummary) + compositeSummary := stenographer.Calls()[0].Args[0].(*types.SuiteSummary) Ω(compositeSummary.SuiteSucceeded).Should(BeTrue()) }) @@ -292,12 +292,12 @@ var _ = Describe("Aggregator", func() { aggregator.SpecSuiteDidEnd(suiteSummary2) aggregator.SpecSuiteDidEnd(suiteSummary1) Eventually(func() interface{} { - return stenographer.Calls + return stenographer.Calls() }).Should(HaveLen(1)) }) It("should report failure", func() { - compositeSummary := stenographer.Calls[0].Args[0].(*types.SuiteSummary) + compositeSummary := stenographer.Calls()[0].Args[0].(*types.SuiteSummary) Ω(compositeSummary.SuiteSucceeded).Should(BeFalse()) }) diff --git a/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/specrunner/spec_runner.go b/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/specrunner/spec_runner.go index 0ec358181..fb84e0141 100644 --- a/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/specrunner/spec_runner.go +++ b/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/specrunner/spec_runner.go @@ -5,6 +5,7 @@ import ( "os" "os/signal" "sync" + "syscall" "github.com/onsi/ginkgo/config" "github.com/onsi/ginkgo/internal/leafnodes" "github.com/onsi/ginkgo/internal/spec" @@ -147,7 +148,7 @@ func (runner *SpecRunner) registerForInterrupts() { func (runner *SpecRunner) registerForHardInterrupts() { c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) <-c fmt.Fprintln(os.Stderr, "\nReceived second interrupt. Shutting down.") diff --git a/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/specrunner/spec_runner_test.go b/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/specrunner/spec_runner_test.go index 6e9efe8fe..e3d326085 100644 --- a/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/specrunner/spec_runner_test.go +++ b/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/specrunner/spec_runner_test.go @@ -140,8 +140,12 @@ var _ = Describe("Spec Collection", func() { Describe("reporting on specs", func() { var proceed chan bool + var ready chan bool + var finished chan bool BeforeEach(func() { + ready = make(chan bool) proceed = make(chan bool) + finished = make(chan bool) skippedSpec := newSpec("SKIP", noneFlag, false) skippedSpec.Skip() @@ -152,16 +156,19 @@ var _ = Describe("Spec Collection", func() { skippedSpec, newSpec("PENDING", pendingFlag, false), newSpecWithBody("RUN", func() { + close(ready) <-proceed }), ) - go runner.Run() + go func() { + runner.Run() + close(finished) + }() }) It("should report about pending/skipped specs", func() { - Eventually(func() interface{} { - return reporter1.SpecWillRunSummaries - }).Should(HaveLen(3)) + <-ready + Ω(reporter1.SpecWillRunSummaries).Should(HaveLen(3)) Ω(reporter1.SpecWillRunSummaries[0].ComponentTexts[0]).Should(Equal("SKIP")) Ω(reporter1.SpecWillRunSummaries[1].ComponentTexts[0]).Should(Equal("PENDING")) @@ -172,10 +179,9 @@ var _ = Describe("Spec Collection", func() { Ω(reporter1.SpecSummaries).Should(HaveLen(2)) close(proceed) + <-finished - Eventually(func() interface{} { - return reporter1.SpecSummaries - }).Should(HaveLen(3)) + Ω(reporter1.SpecSummaries).Should(HaveLen(3)) Ω(reporter1.SpecSummaries[2].ComponentTexts[0]).Should(Equal("RUN")) }) }) diff --git a/Godeps/_workspace/src/github.com/onsi/ginkgo/reporters/default_reporter_test.go b/Godeps/_workspace/src/github.com/onsi/ginkgo/reporters/default_reporter_test.go index fe3d8de5f..c8e9c81cb 100644 --- a/Godeps/_workspace/src/github.com/onsi/ginkgo/reporters/default_reporter_test.go +++ b/Godeps/_workspace/src/github.com/onsi/ginkgo/reporters/default_reporter_test.go @@ -1,13 +1,13 @@ package reporters_test import ( + "time" . "github.com/onsi/ginkgo" "github.com/onsi/ginkgo/config" "github.com/onsi/ginkgo/reporters" st "github.com/onsi/ginkgo/reporters/stenographer" "github.com/onsi/ginkgo/types" . "github.com/onsi/gomega" - "time" ) var _ = Describe("DefaultReporter", func() { @@ -60,9 +60,9 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce the suite, then announce the number of specs", func() { - Ω(stenographer.Calls).Should(HaveLen(2)) - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSuite", "A Sweet Suite", ginkgoConfig.RandomSeed, true, false))) - Ω(stenographer.Calls[1]).Should(Equal(call("AnnounceNumberOfSpecs", 8, 10, false))) + Ω(stenographer.Calls()).Should(HaveLen(2)) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuite", "A Sweet Suite", ginkgoConfig.RandomSeed, true, false))) + Ω(stenographer.Calls()[1]).Should(Equal(call("AnnounceNumberOfSpecs", 8, 10, false))) }) }) @@ -76,10 +76,10 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce the suite, announce that it's a parallel run, then announce the number of specs", func() { - Ω(stenographer.Calls).Should(HaveLen(3)) - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSuite", "A Sweet Suite", ginkgoConfig.RandomSeed, true, false))) - Ω(stenographer.Calls[1]).Should(Equal(call("AnnounceParallelRun", 1, 2, 10, 20, false))) - Ω(stenographer.Calls[2]).Should(Equal(call("AnnounceNumberOfSpecs", 8, 10, false))) + Ω(stenographer.Calls()).Should(HaveLen(3)) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuite", "A Sweet Suite", ginkgoConfig.RandomSeed, true, false))) + Ω(stenographer.Calls()[1]).Should(Equal(call("AnnounceParallelRun", 1, 2, 10, 20, false))) + Ω(stenographer.Calls()[2]).Should(Equal(call("AnnounceNumberOfSpecs", 8, 10, false))) }) }) }) @@ -91,7 +91,7 @@ var _ = Describe("DefaultReporter", func() { State: types.SpecStatePassed, }) - Ω(stenographer.Calls).Should(BeEmpty()) + Ω(stenographer.Calls()).Should(BeEmpty()) }) }) @@ -102,8 +102,8 @@ var _ = Describe("DefaultReporter", func() { } reporter.BeforeSuiteDidRun(summary) - Ω(stenographer.Calls).Should(HaveLen(1)) - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceBeforeSuiteFailure", summary, false, true))) + Ω(stenographer.Calls()).Should(HaveLen(1)) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceBeforeSuiteFailure", summary, false, true))) }) }) }) @@ -115,7 +115,7 @@ var _ = Describe("DefaultReporter", func() { State: types.SpecStatePassed, }) - Ω(stenographer.Calls).Should(BeEmpty()) + Ω(stenographer.Calls()).Should(BeEmpty()) }) }) @@ -126,8 +126,8 @@ var _ = Describe("DefaultReporter", func() { } reporter.AfterSuiteDidRun(summary) - Ω(stenographer.Calls).Should(HaveLen(1)) - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceAfterSuiteFailure", summary, false, true))) + Ω(stenographer.Calls()).Should(HaveLen(1)) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceAfterSuiteFailure", summary, false, true))) }) }) }) @@ -141,8 +141,8 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce that the spec will run", func() { - Ω(stenographer.Calls).Should(HaveLen(1)) - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSpecWillRun", spec))) + Ω(stenographer.Calls()).Should(HaveLen(1)) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSpecWillRun", spec))) }) }) @@ -156,7 +156,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce nothing", func() { - Ω(stenographer.Calls).Should(BeEmpty()) + Ω(stenographer.Calls()).Should(BeEmpty()) }) }) @@ -169,7 +169,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce nothing", func() { - Ω(stenographer.Calls).Should(BeEmpty()) + Ω(stenographer.Calls()).Should(BeEmpty()) }) }) }) @@ -184,7 +184,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce nothing", func() { - Ω(stenographer.Calls).Should(BeEmpty()) + Ω(stenographer.Calls()).Should(BeEmpty()) }) }) @@ -197,7 +197,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce nothing", func() { - Ω(stenographer.Calls).Should(BeEmpty()) + Ω(stenographer.Calls()).Should(BeEmpty()) }) }) }) @@ -222,7 +222,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce the measurement", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSuccesfulMeasurement", spec, false))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuccesfulMeasurement", spec, false))) }) }) @@ -232,13 +232,13 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce that it was slow", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSuccesfulSlowSpec", spec, false))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuccesfulSlowSpec", spec, false))) }) }) Context("Otherwise", func() { It("should announce the succesful spec", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSuccesfulSpec", spec))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuccesfulSpec", spec))) }) }) }) @@ -249,7 +249,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce the pending spec", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnouncePendingSpec", spec, true))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnouncePendingSpec", spec, true))) }) }) @@ -259,7 +259,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce the skipped spec", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSkippedSpec", spec))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSkippedSpec", spec))) }) }) @@ -269,7 +269,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce the timedout spec", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSpecTimedOut", spec, false, true))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSpecTimedOut", spec, false, true))) }) }) @@ -279,7 +279,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce the panicked spec", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSpecPanicked", spec, false, true))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSpecPanicked", spec, false, true))) }) }) @@ -289,7 +289,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce the failed spec", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSpecFailed", spec, false, true))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSpecFailed", spec, false, true))) }) }) @@ -310,7 +310,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce the measurement", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSuccesfulMeasurement", spec, true))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuccesfulMeasurement", spec, true))) }) }) @@ -320,13 +320,13 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce that it was slow", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSuccesfulSlowSpec", spec, true))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuccesfulSlowSpec", spec, true))) }) }) Context("Otherwise", func() { It("should announce the succesful spec", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSuccesfulSpec", spec))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuccesfulSpec", spec))) }) }) }) @@ -337,7 +337,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce the pending spec, but never noisily", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnouncePendingSpec", spec, false))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnouncePendingSpec", spec, false))) }) }) @@ -347,7 +347,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce the skipped spec", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSkippedSpec", spec))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSkippedSpec", spec))) }) }) @@ -357,7 +357,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce the timedout spec", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSpecTimedOut", spec, true, true))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSpecTimedOut", spec, true, true))) }) }) @@ -367,7 +367,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce the panicked spec", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSpecPanicked", spec, true, true))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSpecPanicked", spec, true, true))) }) }) @@ -377,7 +377,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce the failed spec", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSpecFailed", spec, true, true))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSpecFailed", spec, true, true))) }) }) }) @@ -390,7 +390,7 @@ var _ = Describe("DefaultReporter", func() { }) It("should announce the spec run's completion", func() { - Ω(stenographer.Calls[0]).Should(Equal(call("AnnounceSpecRunCompletion", suite, false))) + Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSpecRunCompletion", suite, false))) }) }) }) diff --git a/Godeps/_workspace/src/github.com/onsi/ginkgo/reporters/stenographer/fake_stenographer.go b/Godeps/_workspace/src/github.com/onsi/ginkgo/reporters/stenographer/fake_stenographer.go index ffee08af5..a43d6c279 100644 --- a/Godeps/_workspace/src/github.com/onsi/ginkgo/reporters/stenographer/fake_stenographer.go +++ b/Godeps/_workspace/src/github.com/onsi/ginkgo/reporters/stenographer/fake_stenographer.go @@ -1,6 +1,8 @@ package stenographer import ( + "sync" + "github.com/onsi/ginkgo/types" ) @@ -12,7 +14,8 @@ func NewFakeStenographerCall(method string, args ...interface{}) FakeStenographe } type FakeStenographer struct { - Calls []FakeStenographerCall + calls []FakeStenographerCall + lock *sync.Mutex } type FakeStenographerCall struct { @@ -21,18 +24,33 @@ type FakeStenographerCall struct { } func NewFakeStenographer() *FakeStenographer { - stenographer := &FakeStenographer{} + stenographer := &FakeStenographer{ + lock: &sync.Mutex{}, + } stenographer.Reset() return stenographer } +func (stenographer *FakeStenographer) Calls() []FakeStenographerCall { + stenographer.lock.Lock() + defer stenographer.lock.Unlock() + + return stenographer.calls +} + func (stenographer *FakeStenographer) Reset() { - stenographer.Calls = make([]FakeStenographerCall, 0) + stenographer.lock.Lock() + defer stenographer.lock.Unlock() + + stenographer.calls = make([]FakeStenographerCall, 0) } func (stenographer *FakeStenographer) CallsTo(method string) []FakeStenographerCall { + stenographer.lock.Lock() + defer stenographer.lock.Unlock() + results := make([]FakeStenographerCall, 0) - for _, call := range stenographer.Calls { + for _, call := range stenographer.calls { if call.Method == method { results = append(results, call) } @@ -42,7 +60,10 @@ func (stenographer *FakeStenographer) CallsTo(method string) []FakeStenographerC } func (stenographer *FakeStenographer) registerCall(method string, args ...interface{}) { - stenographer.Calls = append(stenographer.Calls, NewFakeStenographerCall(method, args...)) + stenographer.lock.Lock() + defer stenographer.lock.Unlock() + + stenographer.calls = append(stenographer.calls, NewFakeStenographerCall(method, args...)) } func (stenographer *FakeStenographer) AnnounceSuite(description string, randomSeed int64, randomizingAll bool, succinct bool) { diff --git a/Godeps/_workspace/src/github.com/onsi/gomega/gbytes/say_matcher.go b/Godeps/_workspace/src/github.com/onsi/gomega/gbytes/say_matcher.go index c48fb80b6..ce5ebcbfa 100644 --- a/Godeps/_workspace/src/github.com/onsi/gomega/gbytes/say_matcher.go +++ b/Godeps/_workspace/src/github.com/onsi/gomega/gbytes/say_matcher.go @@ -94,9 +94,12 @@ func (m *sayMatcher) NegatedFailureMessage(actual interface{}) (message string) } func (m *sayMatcher) MatchMayChangeInTheFuture(actual interface{}) bool { - buffer, ok := m.buffer(actual) - if ok { - return !buffer.Closed() + switch x := actual.(type) { + case *Buffer: + return !x.Closed() + case BufferProvider: + return !x.Buffer().Closed() + default: + return true } - return true } diff --git a/Godeps/_workspace/src/github.com/onsi/gomega/gbytes/say_matcher_test.go b/Godeps/_workspace/src/github.com/onsi/gomega/gbytes/say_matcher_test.go index c16c202a3..ee2c2d324 100644 --- a/Godeps/_workspace/src/github.com/onsi/gomega/gbytes/say_matcher_test.go +++ b/Godeps/_workspace/src/github.com/onsi/gomega/gbytes/say_matcher_test.go @@ -1,8 +1,8 @@ package gbytes_test import ( - . "github.com/onsi/gomega/gbytes" "time" + . "github.com/onsi/gomega/gbytes" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -24,7 +24,7 @@ var _ = Describe("SayMatcher", func() { buffer.Write([]byte("abc")) }) - Context("when actual is not a gexec Buffer, or a speaker", func() { + Context("when actual is not a gexec Buffer, or a BufferProvider", func() { It("should error", func() { failures := interceptFailures(func() { Ω("foo").Should(Say("foo")) @@ -144,5 +144,20 @@ var _ = Describe("SayMatcher", func() { s.Buffer().Write([]byte("abc")) Ω(s).Should(Say("abc")) }) + + It("should abort an eventually", func() { + s := &speaker{ + buffer: NewBuffer(), + } + + s.buffer.Close() + + t := time.Now() + failures := interceptFailures(func() { + Eventually(s).Should(Say("def")) + }) + Ω(failures).Should(HaveLen(1)) + Ω(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond)) + }) }) }) diff --git a/Godeps/_workspace/src/github.com/onsi/gomega/gexec/exit_matcher_test.go b/Godeps/_workspace/src/github.com/onsi/gomega/gexec/exit_matcher_test.go index 2fc69c079..1839f5925 100644 --- a/Godeps/_workspace/src/github.com/onsi/gomega/gexec/exit_matcher_test.go +++ b/Godeps/_workspace/src/github.com/onsi/gomega/gexec/exit_matcher_test.go @@ -1,9 +1,9 @@ package gexec_test import ( - . "github.com/onsi/gomega/gexec" "os/exec" "time" + . "github.com/onsi/gomega/gexec" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -23,7 +23,7 @@ var _ = Describe("ExitMatcher", func() { Describe("when passed something that is not a session", func() { It("should error", func() { failures := interceptFailures(func() { - Ω(command).Should(Exit()) + Ω("aardvark").Should(Exit()) }) Ω(failures[0]).Should(ContainSubstring("Exit must be passed a gexit session")) diff --git a/Godeps/_workspace/src/github.com/onsi/gomega/gexec/session_test.go b/Godeps/_workspace/src/github.com/onsi/gomega/gexec/session_test.go index 5140312e2..fbfaf6c3f 100644 --- a/Godeps/_workspace/src/github.com/onsi/gomega/gexec/session_test.go +++ b/Godeps/_workspace/src/github.com/onsi/gomega/gexec/session_test.go @@ -1,7 +1,6 @@ package gexec_test import ( - "bytes" "os/exec" "syscall" "time" @@ -16,7 +15,7 @@ var _ = Describe("Session", func() { var command *exec.Cmd var session *Session - var outWriter, errWriter *bytes.Buffer + var outWriter, errWriter *Buffer BeforeEach(func() { outWriter = nil @@ -144,21 +143,21 @@ var _ = Describe("Session", func() { Context("when wrapping out and err", func() { BeforeEach(func() { - outWriter = &bytes.Buffer{} - errWriter = &bytes.Buffer{} + outWriter = NewBuffer() + errWriter = NewBuffer() }) It("should route to both the provided writers and the gbytes buffers", func() { Eventually(session.Out).Should(Say("We've done the impossible, and that makes us mighty")) Eventually(session.Err).Should(Say("Ah, curse your sudden but inevitable betrayal!")) - Ω(outWriter.String()).Should(ContainSubstring("We've done the impossible, and that makes us mighty")) - Ω(errWriter.String()).Should(ContainSubstring("Ah, curse your sudden but inevitable betrayal!")) + Ω(outWriter.Contents()).Should(ContainSubstring("We've done the impossible, and that makes us mighty")) + Ω(errWriter.Contents()).Should(ContainSubstring("Ah, curse your sudden but inevitable betrayal!")) Eventually(session).Should(Exit()) - Ω(outWriter.Bytes()).Should(Equal(session.Out.Contents())) - Ω(errWriter.Bytes()).Should(Equal(session.Err.Contents())) + Ω(outWriter.Contents()).Should(Equal(session.Out.Contents())) + Ω(errWriter.Contents()).Should(Equal(session.Err.Contents())) }) }) diff --git a/Godeps/_workspace/src/github.com/onsi/gomega/ghttp/handlers.go b/Godeps/_workspace/src/github.com/onsi/gomega/ghttp/handlers.go index f7188cd6a..80675871f 100644 --- a/Godeps/_workspace/src/github.com/onsi/gomega/ghttp/handlers.go +++ b/Godeps/_workspace/src/github.com/onsi/gomega/ghttp/handlers.go @@ -93,44 +93,93 @@ func VerifyJSONRepresenting(object interface{}) http.HandlerFunc { ) } -//RespondWith returns a handler that responds to a request with the specified status code and body -func RespondWith(statusCode int, body string) http.HandlerFunc { +func copyHeader(src http.Header, dst http.Header) { + for key, value := range src { + dst[key] = value + } +} + +/* +RespondWith returns a handler that responds to a request with the specified status code and body + +Body may be a string or []byte + +Also, RespondWith can be given an optional http.Header. The headers defined therein will be added to the response headers. +*/ +func RespondWith(statusCode int, body interface{}, optionalHeader ...http.Header) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { + if len(optionalHeader) == 1 { + copyHeader(optionalHeader[0], w.Header()) + } w.WriteHeader(statusCode) - w.Write([]byte(body)) + switch x := body.(type) { + case string: + w.Write([]byte(x)) + case []byte: + w.Write(x) + default: + Ω(body).Should(BeNil(), "Invalid type for body. Should be string or []byte.") + } } } -//RespondWithPtr returns a handler that responds to a request with the specified status code and body -// -//Unlike RespondWith, you pass RepondWithPtr a pointer to the status code and body allowing different tests -//to share the same setup but specify different status codes and bodies. -func RespondWithPtr(statusCode *int, body *string) http.HandlerFunc { +/* +RespondWithPtr returns a handler that responds to a request with the specified status code and body + +Unlike RespondWith, you pass RepondWithPtr a pointer to the status code and body allowing different tests +to share the same setup but specify different status codes and bodies. + +Also, RespondWithPtr can be given an optional http.Header. The headers defined therein will be added to the response headers. +Since the http.Header can be mutated after the fact you don't need to pass in a pointer. +*/ +func RespondWithPtr(statusCode *int, body interface{}, optionalHeader ...http.Header) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { + if len(optionalHeader) == 1 { + copyHeader(optionalHeader[0], w.Header()) + } w.WriteHeader(*statusCode) if body != nil { - w.Write([]byte(*body)) + switch x := (body).(type) { + case *string: + w.Write([]byte(*x)) + case *[]byte: + w.Write(*x) + default: + Ω(body).Should(BeNil(), "Invalid type for body. Should be string or []byte.") + } } } } -//RespondWithJSONEncoded returns a handler that responds to a request with the specified status code and a body -//containing the JSON-encoding of the passed in object -func RespondWithJSONEncoded(statusCode int, object interface{}) http.HandlerFunc { +/* +RespondWithJSONEncoded returns a handler that responds to a request with the specified status code and a body +containing the JSON-encoding of the passed in object + +Also, RespondWithJSONEncoded can be given an optional http.Header. The headers defined therein will be added to the response headers. +*/ +func RespondWithJSONEncoded(statusCode int, object interface{}, optionalHeader ...http.Header) http.HandlerFunc { data, err := json.Marshal(object) Ω(err).ShouldNot(HaveOccurred()) - return RespondWith(statusCode, string(data)) + return RespondWith(statusCode, string(data), optionalHeader...) } -//RespondWithJSONEncodedPtr behaves like RespondWithJSONEncoded but takes a pointer -//to a status code and object. -// -//This allows different tests to share the same setup but specify different status codes and JSON-encoded -//objects. -func RespondWithJSONEncodedPtr(statusCode *int, object *interface{}) http.HandlerFunc { +/* +RespondWithJSONEncodedPtr behaves like RespondWithJSONEncoded but takes a pointer +to a status code and object. + +This allows different tests to share the same setup but specify different status codes and JSON-encoded +objects. + +Also, RespondWithJSONEncodedPtr can be given an optional http.Header. The headers defined therein will be added to the response headers. +Since the http.Header can be mutated after the fact you don't need to pass in a pointer. +*/ +func RespondWithJSONEncodedPtr(statusCode *int, object *interface{}, optionalHeader ...http.Header) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { data, err := json.Marshal(*object) Ω(err).ShouldNot(HaveOccurred()) + if len(optionalHeader) == 1 { + copyHeader(optionalHeader[0], w.Header()) + } w.WriteHeader(*statusCode) w.Write(data) } diff --git a/Godeps/_workspace/src/github.com/onsi/gomega/ghttp/test_server_test.go b/Godeps/_workspace/src/github.com/onsi/gomega/ghttp/test_server_test.go index 4d1081d0c..edc902e51 100644 --- a/Godeps/_workspace/src/github.com/onsi/gomega/ghttp/test_server_test.go +++ b/Godeps/_workspace/src/github.com/onsi/gomega/ghttp/test_server_test.go @@ -310,41 +310,80 @@ var _ = Describe("TestServer", func() { }) Describe("RespondWith", func() { - BeforeEach(func() { - s.AppendHandlers(CombineHandlers( - VerifyRequest("POST", "/foo"), - RespondWith(http.StatusCreated, "sweet"), - )) + Context("without headers", func() { + BeforeEach(func() { + s.AppendHandlers(CombineHandlers( + VerifyRequest("POST", "/foo"), + RespondWith(http.StatusCreated, "sweet"), + ), CombineHandlers( + VerifyRequest("POST", "/foo"), + RespondWith(http.StatusOK, []byte("sour")), + )) + }) + + It("should return the response", func() { + resp, err = http.Post(s.URL()+"/foo", "application/json", nil) + Ω(err).ShouldNot(HaveOccurred()) + + Ω(resp.StatusCode).Should(Equal(http.StatusCreated)) + + body, err := ioutil.ReadAll(resp.Body) + Ω(err).ShouldNot(HaveOccurred()) + Ω(body).Should(Equal([]byte("sweet"))) + + resp, err = http.Post(s.URL()+"/foo", "application/json", nil) + Ω(err).ShouldNot(HaveOccurred()) + + Ω(resp.StatusCode).Should(Equal(http.StatusOK)) + + body, err = ioutil.ReadAll(resp.Body) + Ω(err).ShouldNot(HaveOccurred()) + Ω(body).Should(Equal([]byte("sour"))) + }) }) - It("should return the response", func() { - resp, err = http.Post(s.URL()+"/foo", "application/json", nil) - Ω(err).ShouldNot(HaveOccurred()) + Context("with headers", func() { + BeforeEach(func() { + s.AppendHandlers(CombineHandlers( + VerifyRequest("POST", "/foo"), + RespondWith(http.StatusCreated, "sweet", http.Header{"X-Custom-Header": []string{"my header"}}), + )) + }) - Ω(resp.StatusCode).Should(Equal(http.StatusCreated)) + It("should return the headers too", func() { + resp, err = http.Post(s.URL()+"/foo", "application/json", nil) + Ω(err).ShouldNot(HaveOccurred()) - body, err := ioutil.ReadAll(resp.Body) - Ω(err).ShouldNot(HaveOccurred()) - Ω(body).Should(Equal([]byte("sweet"))) + Ω(resp.StatusCode).Should(Equal(http.StatusCreated)) + Ω(ioutil.ReadAll(resp.Body)).Should(Equal([]byte("sweet"))) + Ω(resp.Header.Get("X-Custom-Header")).Should(Equal("my header")) + }) }) }) Describe("RespondWithPtr", func() { var code int - var body string + var byteBody []byte + var stringBody string BeforeEach(func() { code = http.StatusOK - body = "sweet" + byteBody = []byte("sweet") + stringBody = "sour" s.AppendHandlers(CombineHandlers( VerifyRequest("POST", "/foo"), - RespondWithPtr(&code, &body), + RespondWithPtr(&code, &byteBody), + ), CombineHandlers( + VerifyRequest("POST", "/foo"), + RespondWithPtr(&code, &stringBody), )) }) It("should return the response", func() { code = http.StatusCreated - body = "tasty" + byteBody = []byte("tasty") + stringBody = "treat" + resp, err = http.Post(s.URL()+"/foo", "application/json", nil) Ω(err).ShouldNot(HaveOccurred()) @@ -353,6 +392,15 @@ var _ = Describe("TestServer", func() { body, err := ioutil.ReadAll(resp.Body) Ω(err).ShouldNot(HaveOccurred()) Ω(body).Should(Equal([]byte("tasty"))) + + resp, err = http.Post(s.URL()+"/foo", "application/json", nil) + Ω(err).ShouldNot(HaveOccurred()) + + Ω(resp.StatusCode).Should(Equal(http.StatusCreated)) + + body, err = ioutil.ReadAll(resp.Body) + Ω(err).ShouldNot(HaveOccurred()) + Ω(body).Should(Equal([]byte("treat"))) }) Context("when passed a nil body", func() { diff --git a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/api.go b/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/api.go deleted file mode 100644 index 655e9d744..000000000 --- a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/api.go +++ /dev/null @@ -1,35 +0,0 @@ -package cf - -import ( - "encoding/json" - "strings" - - . "github.com/onsi/gomega" - . "github.com/onsi/gomega/gexec" -) - -type GenericResource struct { - Metadata struct { - Guid string `json:"guid"` - } `json:"metadata"` -} - -type QueryResponse struct { - Resources []GenericResource `struct:"resources"` -} - -func ApiRequest(method, endpoint string, response interface{}, data ...string) { - request := Cf( - "curl", - endpoint, - "-X", method, - "-d", strings.Join(data, ""), - ) - - Eventually(request).Should(Exit(0)) - - if response != nil { - err := json.Unmarshal(request.Out.Contents(), response) - Expect(err).ToNot(HaveOccurred()) - } -} diff --git a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/api_test.go b/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/api_test.go deleted file mode 100644 index e3bc683e2..000000000 --- a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/api_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package cf_test - -import ( - "os/exec" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - . "github.com/pivotal-cf-experimental/cf-test-helpers/cf" - "github.com/pivotal-cf-experimental/cf-test-helpers/runner" -) - -var _ = Describe("ApiRequest", func() { - It("sends the request to current CF target", func() { - runner.CommandInterceptor = func(cmd *exec.Cmd) *exec.Cmd { - Expect(cmd.Path).To(Equal(exec.Command("gcf").Path)) - Expect(cmd.Args).To(Equal([]string{ - "gcf", "curl", "/v2/info", "-X", "GET", "-d", "somedata", - })) - - return exec.Command("bash", "-c", `echo \{ \"metadata\": \{ \"guid\": \"abc\" \} \}`) - } - - var response GenericResource - ApiRequest("GET", "/v2/info", &response, "some", "data") - - Expect(response.Metadata.Guid).To(Equal("abc")) - }) -}) diff --git a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/as_user.go b/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/as_user.go deleted file mode 100644 index 43b3bf1a6..000000000 --- a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/as_user.go +++ /dev/null @@ -1,60 +0,0 @@ -package cf - -import ( - "fmt" - "io/ioutil" - "os" - - ginkgoconfig "github.com/onsi/ginkgo/config" - . "github.com/onsi/gomega" - . "github.com/onsi/gomega/gexec" -) - -func AsUser(userContext UserContext, actions func()) { - originalCfHomeDir, currentCfHomeDir := InitiateUserContext(userContext) - defer func() { - RestoreUserContext(userContext, originalCfHomeDir, currentCfHomeDir) - }() - - TargetSpace(userContext) - - actions() -} - -func InitiateUserContext(userContext UserContext) (originalCfHomeDir, currentCfHomeDir string) { - originalCfHomeDir = os.Getenv("CF_HOME") - currentCfHomeDir, err := ioutil.TempDir("", fmt.Sprintf("cf_home_%d", ginkgoconfig.GinkgoConfig.ParallelNode)) - - if err != nil { - panic("Error: could not create temporary home directory: " + err.Error()) - } - - os.Setenv("CF_HOME", currentCfHomeDir) - - cfSetApiArgs := []string{"api", userContext.ApiUrl} - if userContext.SkipSSLValidation { - cfSetApiArgs = append(cfSetApiArgs, "--skip-ssl-validation") - } - - Eventually(Cf(cfSetApiArgs...), 10).Should(Exit(0)) - - Eventually(Cf("auth", userContext.Username, userContext.Password), 10).Should(Exit(0)) - - return -} - -func TargetSpace(userContext UserContext) { - if userContext.Org != "" { - if userContext.Space != "" { - Eventually(Cf("target", "-o", userContext.Org, "-s", userContext.Space), 10).Should(Exit(0)) - } else { - Eventually(Cf("target", "-o", userContext.Org), 10).Should(Exit(0)) - } - } -} - -func RestoreUserContext(_ UserContext, originalCfHomeDir, currentCfHomeDir string) { - Eventually(Cf("logout"), 10).Should(Exit(0)) - os.Setenv("CF_HOME", originalCfHomeDir) - os.RemoveAll(currentCfHomeDir) -} diff --git a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/as_user_test.go b/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/as_user_test.go deleted file mode 100644 index 4e533a062..000000000 --- a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/as_user_test.go +++ /dev/null @@ -1,131 +0,0 @@ -package cf_test - -import ( - "os" - "os/exec" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/onsi/gomega/gexec" - "github.com/pivotal-cf-experimental/cf-test-helpers/cf" -) - -var _ = Describe("AsUser", func() { - var FakeThingsToRunAsUser = func() {} - var FakeCfCalls = [][]string{} - - var FakeCf = func(args ...string) *gexec.Session { - FakeCfCalls = append(FakeCfCalls, args) - var session, _ = gexec.Start(exec.Command("echo", "nothing"), nil, nil) - return session - } - var user = cf.NewUserContext("http://FAKE_API.example.com", "FAKE_USERNAME", "FAKE_PASSWORD", "FAKE_ORG", "FAKE_SPACE", true) - - BeforeEach(func() { - FakeCfCalls = [][]string{} - cf.Cf = FakeCf - }) - - It("calls cf api", func() { - cf.AsUser(user, FakeThingsToRunAsUser) - - Expect(FakeCfCalls[0]).To(Equal([]string{"api", "http://FAKE_API.example.com", "--skip-ssl-validation"})) - }) - - It("calls cf auth", func() { - cf.AsUser(user, FakeThingsToRunAsUser) - - Expect(FakeCfCalls[1]).To(Equal([]string{"auth", "FAKE_USERNAME", "FAKE_PASSWORD"})) - }) - - Describe("cf target", func() { - Context("when org is set and space is set", func() { - It("sets org and space", func() { - cf.AsUser(user, FakeThingsToRunAsUser) - - Expect(FakeCfCalls[2]).To(Equal([]string{"target", "-o", "FAKE_ORG", "-s", "FAKE_SPACE"})) - }) - - Context("when org is set and space is NOT set", func() { - BeforeEach(func() { - user.Space = "" - }) - - It("sets org", func() { - cf.AsUser(user, FakeThingsToRunAsUser) - - Expect(FakeCfCalls[2]).To(Equal([]string{"target", "-o", "FAKE_ORG"})) - }) - - Context("when org is NOT set and space is NOT set", func() { - BeforeEach(func() { - user.Org = "" - }) - }) - }) - }) - - Context("when org is NOT set", func() { - - It("sets org", func() { - cf.AsUser(user, FakeThingsToRunAsUser) - - Expect(FakeCfCalls[2]).NotTo(Equal([]string{"target", "-o", "FAKE_ORG", "-s", "FAKE_SPACE"})) - }) - }) - - Context("when org is set", func() { - BeforeEach(func() { - user.Space = "" - }) - - Context("when space is set", func() { - }) - }) - }) - - It("calls cf logout", func() { - cf.AsUser(user, FakeThingsToRunAsUser) - - Expect(FakeCfCalls[len(FakeCfCalls)-1]).To(Equal([]string{"logout"})) - }) - - It("logs out even if actions contain a failing expectation", func() { - RegisterFailHandler(func(message string, callerSkip ...int) {}) - cf.AsUser(user, func() { Expect(1).To(Equal(2)) }) - RegisterFailHandler(Fail) - - Expect(FakeCfCalls[len(FakeCfCalls)-1]).To(Equal([]string{"logout"})) - }) - - It("calls the passed function", func() { - called := false - cf.AsUser(user, func() { called = true }) - - Expect(called).To(BeTrue()) - }) - - It("sets a unique CF_HOME value", func() { - var ( - firstHome string - secondHome string - ) - - cf.AsUser(user, func() { - firstHome = os.Getenv("CF_HOME") - }) - - cf.AsUser(user, func() { - secondHome = os.Getenv("CF_HOME") - }) - - Expect(firstHome).NotTo(Equal(secondHome)) - }) - - It("returns CF_HOME to its original value", func() { - os.Setenv("CF_HOME", "some-crazy-value") - cf.AsUser(user, func() {}) - - Expect(os.Getenv("CF_HOME")).To(Equal("some-crazy-value")) - }) -}) diff --git a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/cf.go b/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/cf.go deleted file mode 100644 index 496838992..000000000 --- a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/cf.go +++ /dev/null @@ -1,10 +0,0 @@ -package cf - -import ( - . "github.com/onsi/gomega/gexec" - "github.com/pivotal-cf-experimental/cf-test-helpers/runner" -) - -var Cf = func(args ...string) *Session { - return runner.Run("gcf", args...) -} diff --git a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/cf_suite_test.go b/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/cf_suite_test.go deleted file mode 100644 index a38450d1d..000000000 --- a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/cf_suite_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package cf_test - -import ( - "testing" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/pivotal-cf-experimental/cf-test-helpers/cf" - "github.com/pivotal-cf-experimental/cf-test-helpers/runner" -) - -var originalCf = cf.Cf -var originalCommandInterceptor = runner.CommandInterceptor - -var _ = AfterEach(func() { - cf.Cf = originalCf - runner.CommandInterceptor = originalCommandInterceptor -}) - -func TestCf(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Cf Suite") -} diff --git a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/cf_test.go b/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/cf_test.go deleted file mode 100644 index 02584b63a..000000000 --- a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/cf_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package cf_test - -import ( - "os/exec" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - . "github.com/onsi/gomega/gexec" - . "github.com/pivotal-cf-experimental/cf-test-helpers/cf" - "github.com/pivotal-cf-experimental/cf-test-helpers/runner" -) - -var _ = Describe("Cf", func() { - It("sends the request to current CF target", func() { - runner.CommandInterceptor = func(cmd *exec.Cmd) *exec.Cmd { - Expect(cmd.Path).To(Equal(exec.Command("gcf").Path)) - Expect(cmd.Args).To(Equal([]string{"gcf", "apps"})) - - return exec.Command("bash", "-c", `exit 42`) - } - - Eventually(Cf("apps")).Should(Exit(42)) - }) -}) diff --git a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/user_context.go b/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/user_context.go deleted file mode 100644 index 353e52090..000000000 --- a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/user_context.go +++ /dev/null @@ -1,22 +0,0 @@ -package cf - -type UserContext struct { - ApiUrl string - Username string - Password string - Org string - Space string - - SkipSSLValidation bool -} - -func NewUserContext(apiUrl, username, password, org, space string, skipSSLValidation bool) UserContext { - return UserContext{ - ApiUrl: apiUrl, - Username: username, - Password: password, - Org: org, - Space: space, - SkipSSLValidation: skipSSLValidation, - } -} diff --git a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/user_context_test.go b/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/user_context_test.go deleted file mode 100644 index 870c6b80a..000000000 --- a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/cf/user_context_test.go +++ /dev/null @@ -1,39 +0,0 @@ -package cf_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - "github.com/pivotal-cf-experimental/cf-test-helpers/cf" -) - -var _ = Describe("NewUserContext", func() { - - var createUser = func() cf.UserContext { - return cf.NewUserContext("http://FAKE_API.example.com", "FAKE_USERNAME", "FAKE_PASSWORD", "FAKE_ORG", "FAKE_SPACE", false) - } - - It("returns a UserContext struct", func() { - Expect(createUser()).To(BeAssignableToTypeOf(cf.UserContext{})) - }) - - It("sets UserContext.ApiUrl", func() { - Expect(createUser().ApiUrl).To(Equal("http://FAKE_API.example.com")) - }) - - It("sets UserContext.Username", func() { - Expect(createUser().Username).To(Equal("FAKE_USERNAME")) - }) - - It("sets UserContext.Password", func() { - Expect(createUser().Password).To(Equal("FAKE_PASSWORD")) - }) - - It("sets UserContext.Org", func() { - Expect(createUser().Org).To(Equal("FAKE_ORG")) - }) - - It("sets UserContext.Space", func() { - Expect(createUser().Space).To(Equal("FAKE_SPACE")) - }) -}) diff --git a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/generator/random_name.go b/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/generator/random_name.go deleted file mode 100644 index d33e35616..000000000 --- a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/generator/random_name.go +++ /dev/null @@ -1,14 +0,0 @@ -package generator - -import ( - uuid "github.com/nu7hatch/gouuid" -) - -func RandomName() string { - guid, err := uuid.NewV4() - if err != nil { - panic(err) - } - - return guid.String() -} diff --git a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/runner/run.go b/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/runner/run.go deleted file mode 100644 index eda81f070..000000000 --- a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/runner/run.go +++ /dev/null @@ -1,43 +0,0 @@ -package runner - -import ( - "fmt" - "os/exec" - "strings" - - "github.com/onsi/ginkgo" - "github.com/onsi/ginkgo/config" - - . "github.com/onsi/gomega" - "github.com/onsi/gomega/gexec" -) - -var CommandInterceptor = func(cmd *exec.Cmd) *exec.Cmd { - return cmd -} - -func Run(executable string, args ...string) *gexec.Session { - cmd := exec.Command(executable, args...) - - sayCommandWillRun(cmd) - - sess, err := gexec.Start(CommandInterceptor(cmd), ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) - Expect(err).NotTo(HaveOccurred()) - - return sess -} - -func Curl(args ...string) *gexec.Session { - args = append([]string{"-s"}, args...) - return Run("curl", args...) -} - -func sayCommandWillRun(cmd *exec.Cmd) { - startColor := "" - endColor := "" - if !config.DefaultReporterConfig.NoColor { - startColor = "\x1b[32m" - endColor = "\x1b[0m" - } - fmt.Fprintf(ginkgo.GinkgoWriter, "\n%s> %s %s\n", startColor, strings.Join(cmd.Args, " "), endColor) -} diff --git a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/runner/run_test.go b/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/runner/run_test.go deleted file mode 100644 index 53bc5b73e..000000000 --- a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/runner/run_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package runner_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - . "github.com/onsi/gomega/gbytes" - . "github.com/onsi/gomega/gexec" - "github.com/pivotal-cf-experimental/cf-test-helpers/runner" -) - -var _ = Describe("Run", func() { - It("runs the given command in a cmdtest Session", func() { - session := runner.Run("bash", "-c", "echo hi out; echo hi err 1>&2; exit 42") - Eventually(session.Out).Should(Say("hi out")) - Eventually(session.Err).Should(Say("hi err")) - Eventually(session).Should(Exit(42)) - }) -}) - -var _ = Describe("Curl", func() { - It("outputs the body of the given URL", func() { - session := runner.Curl("-I", "http://example.com") - - Eventually(session.Out).Should(Say("HTTP/1.1 200 OK")) - }) -}) diff --git a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/runner/runner_suite_test.go b/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/runner/runner_suite_test.go deleted file mode 100644 index 4695f23a7..000000000 --- a/Godeps/_workspace/src/github.com/pivotal-cf-experimental/cf-test-helpers/runner/runner_suite_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package runner_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - "testing" -) - -func TestRunner(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Runner Suite") -} diff --git a/apps/delete_route_test.go b/apps/delete_route_test.go index 0d9866f1a..4138f5e16 100644 --- a/apps/delete_route_test.go +++ b/apps/delete_route_test.go @@ -5,9 +5,9 @@ import ( . "github.com/onsi/gomega" . "github.com/onsi/gomega/gexec" + "github.com/cloudfoundry-incubator/cf-test-helpers/cf" + "github.com/cloudfoundry-incubator/cf-test-helpers/generator" "github.com/cloudfoundry/cf-acceptance-tests/helpers" - "github.com/pivotal-cf-experimental/cf-test-helpers/cf" - "github.com/pivotal-cf-experimental/cf-test-helpers/generator" ) var _ = Describe("Delete Route", func() {