Beispiel #1
0
		loginRequirement = &passingRequirement{}
		factory.NewLoginRequirementReturns(loginRequirement)

		userRequirement = &fakerequirements.FakeUserRequirement{}
		userRequirement.ExecuteReturns(true)
		factory.NewUserRequirementReturns(userRequirement)

		organizationRequirement = &fakerequirements.FakeOrganizationRequirement{}
		organizationRequirement.ExecuteReturns(true)
		factory.NewOrganizationRequirementReturns(organizationRequirement)
	})

	Describe("Requirements", func() {
		Context("when not provided exactly three args", func() {
			BeforeEach(func() {
				flagContext.Parse("the-user-name", "the-org-name")
			})

			It("fails with usage", func() {
				Expect(func() { cmd.Requirements(factory, flagContext) }).To(Panic())
				Expect(ui.Outputs).To(ContainSubstrings(
					[]string{"Incorrect Usage. Requires USERNAME, ORG, ROLE as arguments"},
					[]string{"NAME"},
					[]string{"USAGE"},
				))
			})
		})

		Context("when provided three args", func() {
			BeforeEach(func() {
				flagContext.Parse("the-user-name", "the-org-name", "OrgManager")
Beispiel #2
0
		deps.Ui = ui
		deps.Config = configRepo
		deps.RepoLocator = repoLocator

		cmd = &user.SetSpaceRole{}
		cmd.SetDependency(deps, false)

		requirementsFactory = &testreq.FakeReqFactory{}
		flagContext = flags.NewFlagContext(map[string]flags.FlagSet{})
	})

	Describe("Requirements", func() {
		Context("when not provided exactly four args", func() {
			BeforeEach(func() {
				flagContext.Parse("the-username", "the-org-name", "the-space-name")
			})

			It("fails with usage", func() {
				Expect(func() { cmd.Requirements(requirementsFactory, flagContext) }).To(Panic())
				Expect(ui.Outputs).To(ContainSubstrings(
					[]string{"Incorrect Usage. Requires USERNAME, ORG, SPACE, ROLE as arguments"},
					[]string{"NAME"},
					[]string{"USAGE"},
				))
			})
		})

		Context("when provided three args", func() {
			BeforeEach(func() {
				flagContext.Parse("the-username", "the-org-name", "the-space-name", "SpaceManager")
Beispiel #3
0
		domainRequirement = &fakerequirements.FakeDomainRequirement{}
		domainRequirement.GetDomainReturns(models.DomainFields{
			Guid: "domain-guid",
			Name: "domain-name",
		})
		factory.NewDomainRequirementReturns(domainRequirement)

		minAPIVersionRequirement = &passingRequirement{}
		factory.NewMinAPIVersionRequirementReturns(minAPIVersionRequirement)
	})

	Describe("Requirements", func() {
		Context("when not provided exactly two args", func() {
			BeforeEach(func() {
				flagContext.Parse("space-name")
			})

			It("fails with usage", func() {
				Expect(func() { cmd.Requirements(factory, flagContext) }).To(Panic())
				Expect(ui.Outputs).To(ContainSubstrings(
					[]string{"Incorrect Usage. Requires SPACE and DOMAIN as arguments"},
					[]string{"NAME"},
					[]string{"USAGE"},
				))
			})
		})

		Context("when provided exactly two args", func() {
			BeforeEach(func() {
				flagContext.Parse("space-name", "domain-name")
Beispiel #4
0
		factory = &fakerequirements.FakeFactory{}

		loginRequirement = &passingRequirement{}
		factory.NewLoginRequirementReturns(loginRequirement)

		targetedSpaceRequirement = &passingRequirement{}
		factory.NewTargetedSpaceRequirementReturns(targetedSpaceRequirement)

		applicationRequirement = &fakerequirements.FakeApplicationRequirement{}
		factory.NewApplicationRequirementReturns(applicationRequirement)
	})

	Describe("Requirements", func() {
		Context("when not provided exactly one arg", func() {
			BeforeEach(func() {
				flagContext.Parse("app-name", "extra-arg")
			})

			It("fails with usage", func() {
				Expect(func() { cmd.Requirements(factory, flagContext) }).To(Panic())
				Expect(ui.Outputs).To(ContainSubstrings(
					[]string{"Incorrect Usage. Requires an argument"},
					[]string{"NAME"},
					[]string{"USAGE"},
				))
			})
		})

		Context("when provided exactly one arg", func() {
			BeforeEach(func() {
				flagContext.Parse("app-name")
	. "github.com/onsi/gomega"
)

var _ = Describe("Flag Constructors", func() {

	var (
		fc flags.FlagContext
	)

	BeforeEach(func() {
		fc = flags.New()
	})

	Describe("NewStringFlag()", func() {
		It("init the flag context with a new string flagset", func() {
			fc.Parse("-s", "test")
			Ω(fc.IsSet("s")).To(BeFalse())
			Ω(fc.String("s")).To(Equal(""))

			fc.NewStringFlag("s", "s2", "setting new string flag")
			fc.Parse("-s", "test2")
			Ω(fc.IsSet("s")).To(BeTrue())
			Ω(fc.IsSet("s2")).To(BeTrue())
			Ω(fc.String("s")).To(Equal("test2"))
			Ω(fc.String("s2")).To(Equal("test2"))
		})
	})

	Describe("NewStringFlagWithDefault()", func() {
		It("init the flag context with a new string flagset with default value", func() {
			fc.Parse("-s", "test")
		flagContext = flags.NewFlagContext(cmd.MetaData().Flags)

		factory = &fakerequirements.FakeFactory{}

		loginRequirement = &passingRequirement{}
		factory.NewLoginRequirementReturns(loginRequirement)

		minAPIVersionRequirement = &passingRequirement{}
		factory.NewMinAPIVersionRequirementReturns(minAPIVersionRequirement)
	})

	Describe("Requirements", func() {
		Context("when not provided exactly one arg", func() {
			BeforeEach(func() {
				flagContext.Parse("service-instance", "extra-arg")
			})

			It("fails with usage", func() {
				Expect(func() { cmd.Requirements(factory, flagContext) }).To(Panic())
				Expect(ui.Outputs).To(ContainSubstrings(
					[]string{"Incorrect Usage. Requires an argument"},
					[]string{"NAME"},
					[]string{"USAGE"},
				))
			})
		})

		Context("when provided exactly one arg", func() {
			BeforeEach(func() {
				flagContext.Parse("service-instance")
Beispiel #7
0
			fc = flags.New()
			fc.NewStringSliceFlag("L", "", "")
			fc.NewStringSliceFlag("command", "c", "")
			fc.NewIntFlag("app-instance-index", "i", "")
			fc.NewBoolFlag("skip-host-validation", "k", "")
			fc.NewBoolFlag("skip-remote-execution", "N", "")
			fc.NewBoolFlag("request-pseudo-tty", "t", "")
			fc.NewBoolFlag("force-pseudo-tty", "tt", "")
			fc.NewBoolFlag("disable-pseudo-tty", "T", "")

			args = []string{}
			parseError = nil
		})

		JustBeforeEach(func() {
			err := fc.Parse(args...)
			Ω(err).ToNot(HaveOccurred())

			opts, parseError = options.NewSSHOptions(fc)
		})

		Context("when an app name is provided", func() {
			Context("as the only argument", func() {
				BeforeEach(func() {
					args = append(args, "app-1")
				})

				It("populates the AppName field", func() {
					Expect(parseError).NotTo(HaveOccurred())
					Expect(opts.AppName).To(Equal("app-1"))
				})