Merge lp://staging/~bjornt/charms/precise/landscape-client/container-relation-joined-test into lp://staging/charms/landscape-client

Proposed by Björn Tillenius
Status: Merged
Approved by: Björn Tillenius
Approved revision: 44
Merge reported by: Björn Tillenius
Merged at revision: not available
Proposed branch: lp://staging/~bjornt/charms/precise/landscape-client/container-relation-joined-test
Merge into: lp://staging/charms/landscape-client
Diff against target: 456 lines (+215/-146)
4 files modified
hooks/common.py (+104/-100)
hooks/container-relation-joined (+0/-26)
hooks/hooks.py (+41/-19)
hooks/test_hooks.py (+70/-1)
To merge this branch: bzr merge lp://staging/~bjornt/charms/precise/landscape-client/container-relation-joined-test
Reviewer Review Type Date Requested Status
Chris Glass Approve
Free Ekanayaka (community) Approve
Review via email: mp+191616@code.staging.launchpad.net

Description of the change

Add a basic test for the container-relation-joined relation.

The purpose of this branch isn't to add full test coverage for the
container-relation-joined relation. It's to make it possible to add
tests for this hooks (and other hooks as well, of course). I added a
simple test to show that it's indeed possible to test it.

This is just a suggestion on how testing can be done. I'm open to
suggestion of better solutions. What I did was to extract the parts that
talk to Juju and Landscape, to make it possible to override that
functionality. I also made the hooks return an exit status, instead of
exiting directly in the hook itself.

I considered using mocker to mock out everything, but we would have to
mock out too much, so the tests would be hard to write and understand.

To post a comment you must log in.
37. By Björn Tillenius

Add missing parameter.

Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Looks like an improvement to me, +1!

[0]

+ def get_environment_config(self):
+ """Get the shell environment variables."""
+ return self.environment

It feels a bit verbose to add a getter method for a public attribute. I'd rather make the attribute private or drop the method.

[1]

+class TestingJujuBroker(JujuBroker):

I'd probably rename this to FakeJujuBroker, for consistency with the naming that we generally use in the client and server code (and it matches the widely accepted terminology http://xunitpatterns.com/Fake%20Object.html)

TestingLandscapeBroker too.

[2]

+ self.landscape_broker = TestingLandscapeBroker(data_path=data_path)
+ self.landscape_broker._config.config = os.path.join(
+ data_path, "landscape.conf")
+ self.landscape_broker._config.write()

This boilerplate isn't great, and it also accesses the private _config attribute. I think one problem is that TestingLandscapeBroker tries to abstract away the interaction with the client, but it actually leaks it by returning the config object with get_client_config, which forces tests to manage such config object. I don't have an easy solution, so I think this good enough as a first step in a better direction.

[3]

+ with open(juju_info_path, "r") as juju_file:
+ juju_info = json.loads(juju_file.read())

You could use landscape.lib.fs.read_file here:

            juju_info = json.loads(read_file(juju_info_path))

review: Approve
38. By Björn Tillenius

Remove LandscapeBroker.get_client_config().

39. By Björn Tillenius

No need to pass data_path to the constructor.

40. By Björn Tillenius

s/Testing/Fake/

41. By Björn Tillenius

Drop get_environment_config.

42. By Björn Tillenius

Use read_file.

Revision history for this message
Björn Tillenius (bjornt) wrote :

On Fri, Oct 18, 2013 at 09:48:33AM -0000, Free Ekanayaka wrote:
> Review: Approve
>
> Looks like an improvement to me, +1!
>
> [0]
>
> + def get_environment_config(self):
> + """Get the shell environment variables."""
> + return self.environment
>
> It feels a bit verbose to add a getter method for a public attribute.
> I'd rather make the attribute private or drop the method.

Agreed, I removed the method.

> [1]
>
> +class TestingJujuBroker(JujuBroker):
>
> I'd probably rename this to FakeJujuBroker, for consistency with the naming that we generally use in the client and server code (and it matches the widely accepted terminology http://xunitpatterns.com/Fake%20Object.html)
>
> TestingLandscapeBroker too.

Fair enough, renamed.

> [2]
>
> + self.landscape_broker = TestingLandscapeBroker(data_path=data_path)
> + self.landscape_broker._config.config = os.path.join(
> + data_path, "landscape.conf")
> + self.landscape_broker._config.write()
>
> This boilerplate isn't great, and it also accesses the private _config
> attribute. I think one problem is that TestingLandscapeBroker tries to
> abstract away the interaction with the client, but it actually leaks it
> by returning the config object with get_client_config, which forces
> tests to manage such config object. I don't have an easy solution, so I
> think this good enough as a first step in a better direction.

Yeah, I wasn't proud of that :) One problem was that we had a
get_client_config() that reloaded the config. I don't know why the
config is reloaded, but I changed is so that LandscapeBroker now creates
a Configuration object and exposes it as the .config attribute. I
changed the callsites to call landscape_broker.config.reload().

I also removed the data_path argument to the constructor, since it
didn't make sense to pass in data_path and then set .config.config
outside the constructor.

> [3]
>
> + with open(juju_info_path, "r") as juju_file:
> + juju_info = json.loads(juju_file.read())
>
> You could use landscape.lib.fs.read_file here:
>
> juju_info = json.loads(read_file(juju_info_path))

Done.

Revision history for this message
Chris Glass (tribaal) wrote :

Looks great! This is really nice. +1

[1]
+class JujuBroker:
and
+class LandscapeBroker:

Nitpick: maybe use new-style classes by subclassing object?

[2]
+ If the client has already been configured, not registration attempt

Small typo s/not/no/ (was not your code).

review: Approve
43. By Björn Tillenius

Use new-style classes.

44. By Björn Tillenius

Typo.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches