Skip to content

Commit

Permalink
chore(spaces): add code coverage reports (#2322)
Browse files Browse the repository at this point in the history
* Update sorting logic in topology command

* Add additional tests for format.js

* Reinstate dynos sorting logic
  • Loading branch information
zwhitfield3 authored Apr 26, 2023
1 parent d24ff80 commit dd85b41
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
98 changes: 98 additions & 0 deletions packages/spaces/test/commands/topology.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,69 @@ const topo = {
'number': 1,
'private_ip': '10.0.134.42',
'hostname': '1.example-app-90210.app.localspace'
},
{ 'id': '01234567-89ab-cdef-0123-456789abcdeb',
'number': 2,
'private_ip': '10.0.134.42',
'hostname': '1.example-app-90210.app.localspace'
}
]
}
]
}
]
}

const topo2 = {
'version': 1,
'apps': [
{ 'id': '01234567-89ab-cdef-0123-456789abcdef',
'domains': [
'example.com',
'example.net'
],
'formations': [
{ 'id"': '01234567-89ab-cdef-0123-456789abcdef',
'process_type': 'web',
'dynos': [
{ 'id': '01234567-89ab-cdef-0123-456789abcdef',
'number': 2,
'private_ip': '10.0.134.42',
'hostname': '1.example-app-90210.app.localspace'
},
{ 'id': '01234567-89ab-cdef-0123-456789abcdeb',
'number': 1,
'private_ip': '10.0.134.42',
'hostname': '1.example-app-90210.app.localspace'
}
]
}
]
}
]
}

const topo3 = {
'version': 1,
'apps': [
{ 'id': '01234567-89ab-cdef-0123-456789abcdef',
'domains': [
'example.com',
'example.net'
],
'formations': [
{ 'id"': '01234567-89ab-cdef-0123-456789abcdef',
'process_type': 'web',
'dynos': [
{ 'id': '01234567-89ab-cdef-0123-456789abcdef',
'number': 1,
'private_ip': '10.0.134.42',
'hostname': '1.example-app-90210.app.localspace'
},
{ 'id': '01234567-89ab-cdef-0123-456789abcdeb',
'number': 1,
'private_ip': '10.0.134.42',
'hostname': '1.example-app-90210.app.localspace'
}
]
}
Expand Down Expand Up @@ -49,6 +112,41 @@ describe('spaces:toplogy', function () {
Domains: example.com
example.net
Dynos: web.1 - 10.0.134.42 - 1.example-app-90210.app.localspace
web.2 - 10.0.134.42 - 1.example-app-90210.app.localspace
`))
.then(() => api.done())
})

it('shows space topology with first dyno having higher process number', function () {
let api = nock('https://api.heroku.com:443')
.get('/spaces/my-space/topology').reply(200, topo2)
.get(`/apps/${app['id']}`).reply(200, app)

return cmd.run({ flags: { space: 'my-space' } })
.then(() => expect(cli.stdout).to.equal(
`=== app-name (web)
Domains: example.com
example.net
Dynos: web.1 - 10.0.134.42 - 1.example-app-90210.app.localspace
web.2 - 10.0.134.42 - 1.example-app-90210.app.localspace
`))
.then(() => api.done())
})

it('shows space topology with dynos having same process number', function () {
let api = nock('https://api.heroku.com:443')
.get('/spaces/my-space/topology').reply(200, topo3)
.get(`/apps/${app['id']}`).reply(200, app)

return cmd.run({ flags: { space: 'my-space' } })
.then(() => expect(cli.stdout).to.equal(
`=== app-name (web)
Domains: example.com
example.net
Dynos: web.1 - 10.0.134.42 - 1.example-app-90210.app.localspace
web.1 - 10.0.134.42 - 1.example-app-90210.app.localspace
`))
.then(() => api.done())
Expand Down
35 changes: 35 additions & 0 deletions packages/spaces/test/lib/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ describe('CIDRBlocksOrCIDRBlock', function () {
})
})

describe('CIDR', function () {
it('returns empty string if cidr has no value', function () {
return expect(format.CIDR()).to.eq('')
})
})

describe('Percent', function () {
it('formats a truthy number', function () {
return expect(format.Percent(100)).to.eq('100%')
Expand All @@ -53,3 +59,32 @@ describe('Percent', function () {
return expect(format.Percent(undefined)).to.eq(undefined)
})
})

describe('VPN Status', function () {
it('returns VPN status if status meets switch statement condition', function () {
expect(format.VPNStatus('pending')).to.eq('pending')
expect(format.VPNStatus('provisioning')).to.eq('provisioning')
expect(format.VPNStatus('deprovisioning')).to.eq('deprovisioning')
})

it('returns VPN status if status = "DOWN" or "deleting" or "deleted"', function () {
expect(format.VPNStatus('DOWN')).to.eq('DOWN')
expect(format.VPNStatus('deleting')).to.eq('deleting')
expect(format.VPNStatus('deleted')).to.eq('deleted')
})
})

describe('Peering Status', function () {
it('returns peering status if default case is reached in switch statement', function () {
return expect(format.PeeringStatus('foo')).to.eq('foo')
})
})

describe('Host Status', function () {
it('returns host status if status meets switch statement condition', function () {
expect(format.HostStatus('under-assessment')).to.eq('under-assessment')
expect(format.HostStatus('permanent-failure')).to.eq('permanent-failure')
expect(format.HostStatus('released-permanent-failure')).to.eq('released-permanent-failure')
expect(format.HostStatus('foo')).to.eq('foo')
})
})

0 comments on commit dd85b41

Please sign in to comment.