Skip to content
This repository was archived by the owner on May 9, 2020. It is now read-only.

Conversation

dcrosta
Copy link
Contributor

@dcrosta dcrosta commented Feb 7, 2013

Also fixes the other knife.rb test cases, which were failing.

username = os.environ.get('LOGNAME')
if username is None:
self.fail('could not read $LOGNAME from environment')
api = self.load('env_values.rb')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to commit this env_values.rb too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😭 yes. thanks.

@@ -18,3 +18,10 @@ def test_current_dir(self):
api = self.load('current_dir.rb')
path = os.path.join(os.path.dirname(__file__), 'configs', 'test_1')
self.assertEqual(api.client, path)

def test_env_variables(self):
username = os.environ.get('LOGNAME')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would fail on some OSes, probably safer to just forcibly set it to something for the test and then revert back. If you wanted to be extra sexy you could also mock os.environ for this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but it will definitely pass on *NIX/OS X systems, which is probably where most people will run tests and where Travis will run them. I'm happy to fix it if you think that's the best route, though.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would at least do the set/unset dance:

old_logname = os.environ.get('LOGNAME')
os.environ['LOGNAME'] = 'pychefenv'
try:
    ...
finally:
    if old_logname is None:
        del os.environ['LOGNAME']
    else:
        os.environ['LOGNAME'] = old_logname

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be better to use a variable that's definitely not going to be used by anything else. Added try/finally to unset it in any event.

@coderanger
Copy link
Owner

Looks good, thanks for the patch!

coderanger added a commit that referenced this pull request Feb 7, 2013
Support "#{ENV['FOO']}" expressions in knife.rb
@coderanger coderanger merged commit 3b83835 into coderanger:master Feb 7, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants