Foreman Ansible: How to run unit tests


I’m working on a patch for Foreman Ansible, however, I’ve found it quite difficult to figure out how I can run the tests. rake -T displays “test:core” as a potential tasks, but it doesn’t really run any tests.

Did anyone manage to get this working? Wouldn’t want to have to push and wait for Jenkins to fail actually.
…Unless that would be the only way forward :frowning:

Kind regards,

It should be something like rake test:foreman_ansible and you should run that from Foreman’s checkout.

1 Like

In addition to what @aruzicka said you can also specify a single test file by passing the TEST= variable[1].

[1] Fixed: Ability to efficiently run single test cases (not just a file)

1 Like

Hey Azuzicka,

I don’t think I fully understand how to use this. I’ll try to explain what I’ve done so far:

  • Cloned GIT of foreman_ansible repo
  • Added my unit test
  • Execute: rake test:foreman_ansible
    => It states it doesn’t know how to run this tasks (also, -T does not provide this task).

Now, when I read your text, you state that i “should run that from Foreman’s checkout”, do you mean I also have to clone the foreman repo and from there I should run the command? How does that clone know where to look for my development repo? (sorry for this total n00b question :frowning: )

The general approach is:

  1. clone foreman to $FOREMAN_DIR
  2. clone foreman_ansible to $FOREMAN_ANSIBLE_DIR
  3. put gem 'foreman_ansible', :path => $FOREMAN_ANSIBLE_DIR into $FOREMAN_DIR/bundler.d/my_gems.local.rb. This tells the clone where to look for your development repo
  4. Do the bundle install, npm install, bundle exec rake db:create db:migrate dance
  5. Run bundle exec rake test:foreman_ansible from $FOREMAN_DIR

Aah, will try this tonight; explains a lot actually! Feels like I’ll be able to make a quantum leap once I got that set-up. Thank you for these clear steps on how to get this to run.

Works like a charm! Thank you for your input!