Skip to content

Commit

Permalink
feat: add new helper 'resolveServiceAddress' (#162)
Browse files Browse the repository at this point in the history
Co-authored-by: Erik Engervall <erik.engervall@gmail.com>
  • Loading branch information
n1ru4l and erikengervall authored Mar 26, 2020
1 parent 9730433 commit c7f3de3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/dockest/src/test-helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const getHostAddress = () => {
return DOCKEST_HOST_ADDRESS
}

export const getServiceAddress = (serviceName: string, targetPort: number | string) => {
export const resolveServiceAddress = (serviceName: string, targetPort: number | string) => {
const service = config.services[serviceName]
if (!service) {
throw new DockestError(`Service "${serviceName}" does not exist`)
Expand All @@ -33,8 +33,13 @@ export const getServiceAddress = (serviceName: string, targetPort: number | stri
}

if (isInsideDockerContainer) {
return `${serviceName}:${portBinding.target}`
return { host: serviceName, port: portBinding.target }
}

return `localhost:${portBinding.published}`
return { host: 'localhost', port: portBinding.published }
}

export const getServiceAddress = (serviceName: string, targetPort: number | string) => {
const record = resolveServiceAddress(serviceName, targetPort)
return `${record.host}:${record.port}`
}

0 comments on commit c7f3de3

Please sign in to comment.