Ejemplo n.º 1
0
func NewAppsGetterFunc(
	cliConnection api.Connection,
	orgName string,
	spaceName string,
	runtime ui.Runtime,
) (thingdoer.AppsGetterFunc, error) {
	diegoAppsCommand := thingdoer.AppsGetter{}

	if orgName != "" {
		org, err := cliConnection.GetOrg(orgName)
		if err != nil || org.Guid == "" {
			return nil, OrgNotFoundErr{OrganizationName: orgName}
		}
		diegoAppsCommand.OrganizationGuid = org.Guid
	} else if spaceName != "" {
		space, err := cliConnection.GetSpace(spaceName)
		if err != nil || space.Guid == "" {
			return nil, SpaceNotFoundErr{SpaceName: spaceName}
		}
		diegoAppsCommand.SpaceGuid = space.Guid
	}

	var appsGetterFunc = diegoAppsCommand.DiegoApps
	if runtime == ui.DEA {
		appsGetterFunc = diegoAppsCommand.DeaApps
	}

	return appsGetterFunc, nil
}
	It("should create a request with diego filter set to false", func() {
		expectedFilters := api.Filters{
			api.EqualFilter{
				Name:  "diego",
				Value: false,
			},
		}

		Expect(fakePaginatedRequester.DoCallCount()).To(Equal(1))
		filters, _ := fakePaginatedRequester.DoArgsForCall(0)
		Expect(filters).To(Equal(expectedFilters))
	})

	Context("when an organization name is specified", func() {
		BeforeEach(func() {
			command.OrganizationGuid = "some-organization-guid"
		})

		It("should create a request with organization guid set", func() {
			expectedFilters := api.Filters{
				api.EqualFilter{
					Name:  "diego",
					Value: false,
				},
				api.EqualFilter{
					Name:  "organization_guid",
					Value: "some-organization-guid",
				},
			}

			Expect(fakePaginatedRequester.DoCallCount()).To(Equal(1))