Skip to content

Commit

Permalink
chore: update tests and types for spaces:wait and spaces:info
Browse files Browse the repository at this point in the history
  • Loading branch information
k80bowman committed Oct 18, 2024
1 parent e84ce39 commit cdce785
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 23 deletions.
5 changes: 1 addition & 4 deletions packages/cli/src/commands/spaces/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import {renderInfo} from '../../lib/spaces/spaces'
import debug from 'debug'
import {IncomingHttpHeaders} from 'node:http'
import {Space, SpaceNat} from '../../lib/types/fir'
import {SpaceWithOutboundIps} from '../../lib/types/spaces'

const spacesDebug = debug('spaces:info')

type SpaceWithOutboundIps = Space & {
outbound_ips?: SpaceNat
}

export default class Info extends Command {
static topic = 'spaces'
static description = 'show info about a space'
Expand Down
7 changes: 2 additions & 5 deletions packages/cli/src/commands/spaces/wait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ import debug from 'debug'
import {renderInfo} from '../../lib/spaces/spaces'
import {Notification, notify} from '@heroku-cli/notifications'
import {IncomingHttpHeaders} from 'node:http'
import {Space, SpaceNat} from '../../lib/types/fir'
import {SpaceNat} from '../../lib/types/fir'
import {SpaceWithOutboundIps} from '../../lib/types/spaces'

const spacesDebug = debug('spaces:wait')

type SpaceWithOutboundIps = Space & {
outbound_ips?: SpaceNat
}

export default class Wait extends Command {
static topic = 'spaces'
static description = 'wait for a space to be created'
Expand Down
10 changes: 3 additions & 7 deletions packages/cli/src/lib/spaces/spaces.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import * as Heroku from '@heroku-cli/schema'
import {ux} from '@oclif/core'
import {Space, SpaceNat, SpaceRegion} from '../types/fir'

type SpaceExpanded = Space & {
outbound_ips?: SpaceNat
region: SpaceRegion & {description?: string}
}
import {SpaceNat} from '../types/fir'
import {SpaceWithOutboundIps} from '../types/spaces'

export function displayShieldState(space: Heroku.Space) {
return space.shield ? 'on' : 'off'
Expand All @@ -17,7 +13,7 @@ export function displayNat(nat?: Required<SpaceNat>) {
return nat.sources.join(', ')
}

export function renderInfo(space: SpaceExpanded, json: boolean) {
export function renderInfo(space: SpaceWithOutboundIps, json: boolean) {
if (json) {
ux.log(JSON.stringify(space, null, 2))
} else {
Expand Down
14 changes: 14 additions & 0 deletions packages/cli/src/lib/types/spaces.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {
Space,
Region,
SpaceRegion,
SpaceNat,
} from './fir'

export type SpaceExpanded = Omit<Space, 'region'> & {
region: SpaceRegion & Partial<Region>
}

export type SpaceWithOutboundIps = SpaceExpanded & {
outbound_ips?: SpaceNat
}
9 changes: 8 additions & 1 deletion packages/cli/test/fixtures/spaces/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import * as Heroku from '@heroku-cli/schema'
import type {SpaceTopology} from '../../../src/commands/spaces/topology'
import {SpaceWithOutboundIps} from '../../../src/lib/types/spaces'

export const spaces: Record<string, Required<Heroku.Space>> = {
export const spaces: Record<string, SpaceWithOutboundIps> = {
'non-shield-space': {
id: '1234',
name: 'my-unshielded-space',
shield: false,
region: {
id: '1',
description: 'virginia',
name: 'us',
},
Expand All @@ -19,6 +21,7 @@ export const spaces: Record<string, Required<Heroku.Space>> = {
organization: {
name: 'my-org',
},
generation: 'cedar',
created_at: '2016-01-06T03:23:13Z',
updated_at: '2016-01-06T03:23:13Z',
},
Expand All @@ -27,6 +30,7 @@ export const spaces: Record<string, Required<Heroku.Space>> = {
name: 'my-shielded-space',
shield: true,
region: {
id: '1',
description: 'virginia',
name: 'us',
},
Expand All @@ -39,6 +43,7 @@ export const spaces: Record<string, Required<Heroku.Space>> = {
organization: {
name: 'my-org',
},
generation: 'cedar',
created_at: '2016-01-06T03:23:13Z',
updated_at: '2016-01-06T03:23:13Z',
},
Expand All @@ -48,6 +53,7 @@ export const spaces: Record<string, Required<Heroku.Space>> = {
name: 'my-unshielded-space',
shield: false,
region: {
id: '1',
description: 'virginia',
name: 'us',
},
Expand All @@ -60,6 +66,7 @@ export const spaces: Record<string, Required<Heroku.Space>> = {
organization: {
name: 'my-org',
},
generation: 'cedar',
created_at: '2016-01-06T03:23:13Z',
updated_at: '2016-01-06T03:23:13Z',
},
Expand Down
12 changes: 9 additions & 3 deletions packages/cli/test/unit/commands/spaces/info.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import * as nock from 'nock'
import heredoc from 'tsheredoc'
import expectOutput from '../../../helpers/utils/expectOutput'
import * as fixtures from '../../../fixtures/spaces/fixtures'
import * as Heroku from '@heroku-cli/schema'
import {SpaceWithOutboundIps} from '../../../../src/lib/types/spaces'

describe('spaces:info', function () {
let space: Required<Heroku.Space>
let shieldSpace: Required<Heroku.Space>
let space: SpaceWithOutboundIps
let shieldSpace: SpaceWithOutboundIps

beforeEach(function () {
space = fixtures.spaces['non-shield-space']
Expand All @@ -34,6 +34,7 @@ describe('spaces:info', function () {
Data CIDR: ${space.data_cidr}
State: ${space.state}
Shield: off
Generation: ${space.generation}
Created at: ${space.created_at}
`))
})
Expand Down Expand Up @@ -73,6 +74,7 @@ describe('spaces:info', function () {
State: ${space.state}
Shield: off
Outbound IPs: 123.456.789.123
Generation: ${space.generation}
Created at: ${space.created_at}
`))
})
Expand All @@ -99,6 +101,7 @@ describe('spaces:info', function () {
State: ${space.state}
Shield: off
Outbound IPs: disabled
Generation: ${space.generation}
Created at: ${space.created_at}
`))
})
Expand All @@ -121,6 +124,7 @@ describe('spaces:info', function () {
Data CIDR: ${space.data_cidr}
State: ${space.state}
Shield: off
Generation: ${space.generation}
Created at: ${space.created_at}
`))
})
Expand All @@ -143,6 +147,7 @@ describe('spaces:info', function () {
Data CIDR: ${shieldSpace.data_cidr}
State: ${shieldSpace.state}
Shield: on
Generation: ${space.generation}
Created at: ${shieldSpace.created_at}
`))
})
Expand All @@ -164,6 +169,7 @@ describe('spaces:info', function () {
Data CIDR: ${space.data_cidr}
State: ${space.state}
Shield: off
Generation: ${space.generation}
Created at: ${space.created_at}
`))
})
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/test/unit/commands/spaces/wait.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {expect} from 'chai'
import expectOutput from '../../../helpers/utils/expectOutput'
import * as fixtures from '../../../fixtures/spaces/fixtures'
import * as sinon from 'sinon'
import {Space} from '@heroku-cli/schema'
import {SpaceWithOutboundIps} from '../../../../src/lib/types/spaces'

describe('spaces:wait', function () {
let allocatingSpace: Required<Space>
let allocatedSpace: Required<Space>
let allocatingSpace: SpaceWithOutboundIps
let allocatedSpace: SpaceWithOutboundIps
let sandbox: sinon.SinonSandbox
let notifySpy: sinon.SinonSpy

Expand Down Expand Up @@ -56,6 +56,7 @@ describe('spaces:wait', function () {
State: ${allocatedSpace.state}
Shield: off
Outbound IPs: 123.456.789.123
Generation: ${allocatedSpace.generation}
Created at: ${allocatedSpace.created_at}
`))
expect(notifySpy.called).to.be.true
Expand Down Expand Up @@ -114,6 +115,7 @@ describe('spaces:wait', function () {
Data CIDR: ${allocatedSpace.data_cidr}
State: ${allocatedSpace.state}
Shield: off
Generation: ${allocatedSpace.generation}
Created at: ${allocatedSpace.created_at}
`))
expect(notifySpy.called).to.be.true
Expand Down

0 comments on commit cdce785

Please sign in to comment.