Skip to content

Commit

Permalink
single: improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Dec 8, 2017
1 parent d32bb38 commit d1f5ee7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/config/normalize.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ module.exports = (config) ->
for sname, service of cluster.services
for dname, dep of service.deps
continue unless dep.local and dep.required
dservice = config.clusters[dep.cluster].services[dep.service]
for snode in service.nodes
dservice = config.clusters[dep.cluster].services[dep.service]
continue if snode in dservice.nodes
throw Error "Required Local Dependency: service #{JSON.stringify sname} in cluster #{JSON.stringify cname} require service #{JSON.stringify dep.service} in cluster #{JSON.stringify dep.cluster} to be present on node #{snode}"

Expand Down Expand Up @@ -216,7 +216,7 @@ module.exports = (config) ->
# Get dependency service
deps[dname] = Object.values config.clusters[dep.cluster].services[dep.service].service_by_nodes
if dep.single
throw Error "Invalid Option: single only appy to 0 or 1 dependencies, found #{deps[dname].length}" if deps[dname].length isnt 1
throw Error "Invalid Option: single only apply to 1 dependencies, found #{deps[dname].length}" if deps[dname].length isnt 1
deps[dname] = deps[dname][0] or null
if dep.local
deps[dname] = [deps[dname]] if dep.single
Expand Down
2 changes: 1 addition & 1 deletion test/config/normalize_deps_auto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe 'normalize deps auto', ->
fs.writeFileSync "#{tmp}/dep_a.json", JSON.stringify {}
fs.writeFileSync "#{tmp}/a.json", JSON.stringify {}
services = []
s = store normalize
store normalize
clusters: 'cluster_a': services:
'service_a':
module: "#{tmp}/a"
Expand Down
15 changes: 14 additions & 1 deletion test/config/normalize_deps_single.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ describe 'normalize deps single', ->
then service.deps.my_dep_a.node.id
else null
.should.eql [null, 'b.fqdn']

it 'dependency not loaded', ->
fs.writeFileSync "#{tmp}/dep_a.json", JSON.stringify {}
fs.writeFileSync "#{tmp}/a.json", JSON.stringify {}
normalize
clusters: 'cluster_a': services:
'service_a':
module: "#{tmp}/a"
affinity: type: 'nodes', match: 'any', values: ['a.fqdn', 'b.fqdn']
deps: 'my_dep_a': module: "#{tmp}/dep_a", single: true
nodes:
'a.fqdn': ip: '10.10.10.1'
'b.fqdn': ip: '10.10.10.2'

it 'single throw if multiple', ->
fs.writeFileSync "#{tmp}/dep_a.json", JSON.stringify {}
Expand All @@ -85,4 +98,4 @@ describe 'normalize deps single', ->
'a.fqdn': ip: '10.10.10.1'
'b.fqdn': ip: '10.10.10.2'
'c.fqdn': ip: '10.10.10.3'
).should.throw 'Invalid Option: single only appy to 0 or 1 dependencies, found 3'
).should.throw 'Invalid Option: single only apply to 1 dependencies, found 3'

0 comments on commit d1f5ee7

Please sign in to comment.