Skip to content

Commit

Permalink
add test for local vcapFile port usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Mueller committed Feb 21, 2019
1 parent c6262a6 commit b60ef7c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ The `options` parameter is optional, and can contain the following properties:

This option property is ignored if not running locally.

This function returns an object with the following properties:
#### return value

The `getAppEnv()` function returns an object with the following properties:

* `app`: object version of `VCAP_APPLICATION` env var
* `services`: object version of `VCAP_SERVICES` env var
Expand Down
5 changes: 4 additions & 1 deletion lib-src/cfenv.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ getServices = (appEnv, options) ->

#-------------------------------------------------------------------------------
getPort = (appEnv) ->
portString = process.env.PORT || process.env.CF_INSTANCE_PORT || process.env.VCAP_APP_PORT || appEnv?.app?.port
portString = process.env.PORT ||
process.env.CF_INSTANCE_PORT ||
process.env.VCAP_APP_PORT ||
appEnv?.app?.port

unless portString?
return 3000 unless appEnv.name?
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/vcap-local-good.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"application": {
"port": 42
},
"services": {
"service-a-label": [
{
Expand Down
1 change: 1 addition & 0 deletions tests/test-core.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ describe "appEnv", ->
creds = appEnv.getServiceCreds "service-a"
creds = JSON.stringify(creds)
expect(creds).to.be '{"url":"foo"}'
expect(appEnv.port).to.be 42

#-------------------------------------------
vcapFile = path.join(__dirname, 'fixtures', 'vcap-local-bad.json')
Expand Down

0 comments on commit b60ef7c

Please sign in to comment.