KontextWork / chef-cookbook-kontextwork-helpers-lib

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

WAT

Provides helper methods for other cookbooks - a shared library

Library

valOrDefault

# does return val, if val is not nil, otherwise uses default
# Very handy if you want to pick either one value, if it exist, or the node.default or similar
def valOrDefault(val, default)

Usage example. add depends "kontextwork-helpers-lib to your metadata.rb

# if node[:key][:nested1][:nested2] is set, return that value, otherwise "other"
valOrDefault(node.dig(:key,:nested1, :nested2), "other")
valOrDefault(node.dig(:key,:nested1, :nested2), node.default.dig(:key,:nested1, :nested2))

nodeOrDefaultAttr

# does return val, if val is not nil, otherwise uses default
# Very handy if you want to pick either one value, if it exist, or the node.default or similar
def nodeOrDefaultAttr(*keys)

Usage example. add depends "kontextwork-helpers-lib to your metadata.rb

# if node[:key][:nested1][:nested2] is set, return it, otherwise return node.default[:key][:nested1][:nested2]
# or if even that is missing, return nil
nodeOrDefaultAttr(:key,:nested1, :nested2))

Tests

The test provision via dokken, so be sure to have a docker engine running

make prepare
make test

Attribute tests

Right now we are testing the different sources and aspects of attribute precendence

  • no-attributes-test no extra attributes in kitchen - so just attribute defaults
  • attributes-test uses kitchen node attributes and tests if you can override node.default values with it The result is: no
  • roles-attributes-test uses the role at test/integration/roles/attributes_test.json to define default_attributes and the run list. The result of this is fairly suprising, the entire order is messed up

About


Languages

Language:Ruby 99.3%Language:Makefile 0.7%