|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +module VCAP::CloudController |
| 4 | + RSpec.describe OrganizationQuotaUsage do |
| 5 | + let(:org) { Organization.make } |
| 6 | + let(:space1) { Space.make(organization: org) } |
| 7 | + let(:space2) { Space.make } |
| 8 | + let(:space3) { Space.make(organization: org) } |
| 9 | + |
| 10 | + subject(:org_usage) { OrganizationQuotaUsage.new(org) } |
| 11 | + |
| 12 | + describe '#routes' do |
| 13 | + before do |
| 14 | + [space1, space1, space2, space3].each { |s| Route.make(space: s) } |
| 15 | + end |
| 16 | + |
| 17 | + it 'returns the number of routes in all spaces under the org' do |
| 18 | + expect(org_usage.routes).to eq(3) |
| 19 | + end |
| 20 | + end |
| 21 | + |
| 22 | + describe '#service_instances' do |
| 23 | + before do |
| 24 | + [space1, space1, space2, space3].each { |s| ManagedServiceInstance.make(space: s) } |
| 25 | + UserProvidedServiceInstance.make(space: space1) |
| 26 | + end |
| 27 | + |
| 28 | + it 'returns the number of service instances in all spaces under the org' do |
| 29 | + expect(org_usage.service_instances).to eq(3) |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + describe '#private_domains' do |
| 34 | + before do |
| 35 | + [space1, space1, space2, space3].each { |s| Domain.make(owning_organization: s.organization) } |
| 36 | + end |
| 37 | + |
| 38 | + it 'returns the number of private domains in all spaces under the org' do |
| 39 | + expect(org_usage.private_domains).to eq(3) |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + describe '#service_keys' do |
| 44 | + before do |
| 45 | + [space1, space1, space2, space3].each { |s| ServiceKey.make(service_instance: ServiceInstance.make(space: s)) } |
| 46 | + end |
| 47 | + |
| 48 | + it 'returns the number of service keys in all spaces under the org' do |
| 49 | + expect(org_usage.service_keys).to eq(3) |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + describe '#reserved_route_ports' do |
| 54 | + before do |
| 55 | + reservable_ports = [1234, 2, 2345, 3] |
| 56 | + router_group = instance_double(RoutingApi::RouterGroup, type: 'tcp', reservable_ports: reservable_ports) |
| 57 | + routing_api_client = instance_double(RoutingApi::Client, router_group: router_group, enabled?: true) |
| 58 | + allow(CloudController::DependencyLocator.instance).to receive(:routing_api_client).and_return(routing_api_client) |
| 59 | + domain = SharedDomain.make(router_group_guid: 'some-router-group') |
| 60 | + [space1, space1, space2, space3].each_with_index { |s, i| Route.make(space: s, domain: domain, host: '', port: reservable_ports[i]) } |
| 61 | + end |
| 62 | + |
| 63 | + it 'returns the number of reserved route ports in all spaces under the org' do |
| 64 | + expect(org_usage.reserved_route_ports).to eq(3) |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + describe '#app_tasks' do |
| 69 | + before do |
| 70 | + [space1, space1, space2, space3].each { |s| TaskModel.make(app: AppModel.make(space: s), state: TaskModel::RUNNING_STATE) } |
| 71 | + TaskModel.make(app: AppModel.make(space: space1), state: TaskModel::PENDING_STATE) |
| 72 | + TaskModel.make(app: AppModel.make(space: space1), state: TaskModel::CANCELING_STATE) |
| 73 | + end |
| 74 | + |
| 75 | + it 'returns the number of app tasks in all spaces under the org' do |
| 76 | + expect(org_usage.app_tasks).to eq(4) |
| 77 | + end |
| 78 | + end |
| 79 | + end |
| 80 | +end |
0 commit comments