Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Added bats integration tests to verify that users can send mail via ssmtp #11

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

trinitronx
Copy link
Contributor

Looks like bats runs as root via test-kitchen, so this only tests email
sent by root
Install pre-release mailtrap gem if 0.2.3 is not found on rubygems

Wait max of 5 seconds for mailtrap to be ready
 - Dynamically find ssmtp executable path (not the same on all distros)

 - Unset the options that the bats test runner sets for us during setup... we definitely don't want the errexit option during the setup phase
 - Reinstate mailtrap teardown function now that race condition test works

 - Send subject header in body since ssmtp does not support -s

 - Make sure to get groups of vagrant user so we don't break sudo by adding them to only the groups root has
   (Fixes second run of verify on VM `kitchen test -d never && kitchen verify`)

 - Hopefully make bats tests more user agnostic
   (should work as long as they run as root or a user who has passwordless sudo)

 - Fix bats/bash script OS portability on CentOS 5.8:
  - Check for any executable bit set in find_mailtrap_bin
  - Run `which ssmtp` as root to find ssmtp binary on distros that don't
    include sbin dirs on normal user's PATH
  - Run usermod as root to ensure it works when sbin is not in user's PATH
@svanzoest
Copy link
Contributor

Hi Thanks for the PRs. The two PRs are all on the same branch which means they can not pull them in separately. Was that the intent?

@trinitronx
Copy link
Contributor Author

Yes. Since the other PR was based off of this one, the patches depend on the prior commits to apply cleanly

@svanzoest
Copy link
Contributor

Okay. This means that I there is a lot of code to accept all at once. It will take me quite a bit more time to ensure we can accept it all. If there are things we may want to discuss it may be hard to make adjustments. I'll see what I can do, but just so you know. Having each of them come in as separate PRs on separate branches will increase my ability to accept your changes within a reasonable amount of time.

@trinitronx
Copy link
Contributor Author

ok, understood. I'll keep that in mind in the future

@svanzoest
Copy link
Contributor

@trinitronx I tried to merge this in today, but a dependency on a patched version of mailtrap gem is hard to take into the main line. We have been using minitest for the cookbook and the plan was to add more tests for that. I definitely see the appeal to bats, but over time it is easy to outgrow the simple bats tests.

While running this I got the following error:

$ kitchen test
<snip>
  Saving to: `/tmp/mailtrap-0.2.3.20130709144258.gem'       

        0K .......... .                                            119K=0.09s       

   2013-11-04 23:19:32 (119 KB/s) - `/tmp/mailtrap-0.2.3.20130709144258.gem' saved [11264]       

   ERROR:  Could not find a valid gem 'mailtrap' (>= 0.2.3) in any repository       
   ERROR:  Possible alternatives: mailtrap       
   Successfully installed daemons-1.1.9       
   Successfully installed trollop-2.0       
   Successfully installed polyglot-0.3.3       
   Successfully installed treetop-1.4.15       
          Successfully installed mail-2.3.3
          Successfully installed mailtrap-0.2.3.20130709144258
          6 gems installed
          ERROR: Could not install mailtrap for sendmail testing...
   verify sending mail as root                                              2/3
<snip>

3 tests, 3 failures       
Command [/tmp/kitchen-busser/vendor/bats/bin/bats /tmp/kitchen-busser/suites/bats] exit code was 1       
>>>>>> Verify failed on instance <default-ubuntu-1204>.
>>>>>> Please see .kitchen/logs/default-ubuntu-1204.log for more details
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: SSH exited (1) for command: [BUSSER_ROOT=/tmp/kitchen-busser GEM_HOME=/tmp/kitchen-busser/gems GEM_PATH=$GEM_HOME GEM_CACHE=$GEM_HOME/cache PATH=$PATH:$GEM_HOME/bin sudo -E /opt/chef/embedded/bin/ruby /tmp/kitchen-busser/gems/bin/busser test]
>>>>>> ----------------------

I will see what I can salvage from the rest of your work, but ideally we would have these tests depend on a released version of gems and pass tests.

Let me know what you would like to do.

@ghost ghost assigned svanzoest Nov 5, 2013
@trinitronx
Copy link
Contributor Author

@svanzoest The dependency on the updated version of mailtrap is indeed necessary for the tests to work, as I had to fork and update the gem to work well with testing ssmtp.

I've got an open pull request on mmower/mailtrap#7 but not sure when or if that will be merged or not. I agree that bats tests with the development gem are not ideal.

If that ever gets merged and released, perhaps the gem could be installed via chef and used for testing in minitest. The bats test setup and teardown took a while to get working, and seems too complicated when compared to the actual ssmtp test commands to verify that it works.

@svanzoest
Copy link
Contributor

@trinitronx looks like mmower/mailtrap#7 has merged. Let's get this pulled in :-)

@svanzoest svanzoest removed their assignment Nov 13, 2017
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