juju / charm-tools

Tools for charm authors and maintainers
Other
42 stars 64 forks source link

Writing Amulet tests for layers needs a solution #86

Open mbruzek opened 8 years ago

mbruzek commented 8 years ago

We wrote Amulet tests for a middle layer (tls) that can be built as a stand alone charm. The Amulet tests are very specific to use the middle layer name when adding the charm and searching for the units.

When a charm gets built with this layer the unit tests will not function because there is will be no charm named "tls" .

cls.deployment.add('tls', units=3)

unit_0 = self.deployment.sentry['tls'][0]
unit_1 = self.deployment.sentry['tls'][1]
unit_2 = self.deployment.sentry['tls'][2]

After some discussion with @johnsca I came up with a work around:

# Specify charm_name because this layer could be named something else.
cls.deployment.add('tls', cls.deployment.charm_name, units=3)

for unit in self.deployment.sentry['tls']
    # Use the individual units in this block.

This solution may not work in all cases. When the charm gets built the charm name will be different and may not run correctly. The charm tests from other layers will show up in the built charm, which I am guessing will override each other if they are named the same 10_deploy.py.

This is both a charm-tools and an Amulet issue. We should document in layers/charm-tools how to test layered charms and make changes to Amulet (if necessary) to make this less painful to developers like Oliver.

lazypower commented 8 years ago

+1 to this

marcoceppi commented 8 years ago

Actually, I think the workaround described is appropriate enough. I'd probably just have it be this though:

service = cls.deployment.charm_name
# Specify charm_name because this layer could be named something else.
cls.deployment.add(service, units=3)

for unit in self.deployment.sentry[service]
    # Use the individual units in this block.

Either way, naming is the same as reactive file naming. So all you need to do is name the test 10_tls_deploy.py or really just tls_deploy.py. Preface the tests with the layer name to avoid collisions.