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
}
				},
				api.EqualFilter{
					Name:  "organization_guid",
					Value: "some-organization-guid",
				},
			}

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

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

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

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