nickjj / rolespec

A test library for testing Ansible roles
GNU General Public License v3.0
232 stars 17 forks source link

Unable to install in private Travis with private Github #15

Open hyperfocus1338 opened 9 years ago

hyperfocus1338 commented 9 years ago

What kind of URL should I place in the installation script? Can't get it to work in this part:

  # The location of YOUR test suite
  - 'cd rolespec ; bin/rolespec -r https://github.com/you/some-test-suite'

When I analyze the following debops Travis run: https://travis-ci.org/debops/ansible-role-ansible

I see that it uses the whole repository:

  # The location of YOUR test suite
  - 'cd rolespec ; bin/rolespec -r https://github.com/debops/test-suite

But before that it clones the repository with the playbook: git://github.com/debops/ansible-role-ansible.git which is not mentioned in the install file.

However my playbook is build up in this format (the format Ansible recommends), I don't know how to make a 'test suite' of this.

roles/
    common/               # this hierarchy represents a "role"
        tasks/            #
            main.yml      #  <-- tasks file can include smaller files if warranted
        handlers/         #
            main.yml      #  <-- handlers file
        templates/        #  <-- files for use with the template resource
            ntp.conf.j2   #  <------- templates end in .j2
        files/            #
            bar.txt       #  <-- files for use with the copy resource
            foo.sh        #  <-- script files for use with the script resource
        vars/             #
            main.yml      #  <-- variables associated with this role
        defaults/         #
            main.yml      #  <-- default lower priority variables for this role
        meta/             #
            main.yml      #  <-- role dependencies

What would be the best way to build a test suite with a complete playbook build up from the above format?

I have made a test file which looks like this:

#!/bin/bash

# test: Test debops.nginx
# Copyright (C) 2014 Nick Janetakis <nick.janetakis@gmail.com>
# Part of the DebOps project - http://debops.org/

# Rolespec settings
#
. "${ROLESPEC_LIB}/main"
. "${ROLESPEC_TEST}/../defaults.conf"

# Install Ansible
#
install_ansible [branch=master]
ansible_plugins

# Systemd
#
assert_playbook_runs ansible-playbook site.yml -i inventory/hosts -t systemd,reboot

Lots more ansible-playbook runs with tags.

Tried serveral things but I can't make it run due to several errors:

Cloning into '/home/travis/build/hyperfocus1337/nginx/rolespec/travis/tests'...
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/hyperfocus1337/nginx.git/'
The command "cd rolespec ; bin/rolespec -r https://github.com/hyperfocus1337/nginx.git" exited with 128.
Cloning into '/home/travis/build/hyperfocus1337/nginx/rolespec/travis/tests'...
fatal: repository 'https://github.com/hyperfocus1337/nginx/tree/master/test/test.sh/' not found
The command "cd rolespec ; bin/rolespec -r https://github.com/hyperfocus1337/nginx/tree/master/test/test.sh" exited with 128.

Basically I have two issues:

I'm not sure if the way my playbook is build up is correct for using Rolespec, and I'm not sure if I can use it with private github/travis and if I need extra settings to make it work.

How should I authenticate using rolespec? Can I use this in the installation?

http://docs.travis-ci.com/user/private-dependencies/

nickjj commented 9 years ago

For now Rolespec expects that you setup a separate repository which contain the tests for 1 or more roles. You can name it whatever you want, but test-suite seemed like a reasonable way to describe it.

You can view a test suite that has over 60 Rolespec driven tests here to see how to configure it: https://github.com/debops/test-suite

That concept is covered briefly in the readme here: https://github.com/nickjj/rolespec/#ways-to-organize-your-tests

In the future there may be a second option which allows you to put your tests inside of your role but atm you can't do that.

As for authentication on private repos, if travis can reach the repo then rolespec should have no problem working because the travis script is what kicks everything off.

Lastly you can remove this line from your test script . "${ROLESPEC_TEST}/../defaults.conf". The defaults.conf file is something custom to DebOps' test-suite, it contains stuff that we wanted all role tests to be able to access to without modifying Rolespec because a lot of it is specific to DebOps only.

You should also remove ansible_plugins because that is part of what defaults.conf supplies.

You can check what's natively supplied by Rolespec by looking at its API docs here: https://github.com/nickjj/rolespec/#test-api

robinmulder commented 9 years ago

+1 for test inside the role support. Another issue which would help with private repositories is to officially support multiple playbooks in 1 repository. It doesn't make much sense to keep every playbook in a separate repository when you are on the paid tier of GitHub ;).

I imagine you would be able to set a variable in your test which would indicate where the playbook is located inside the repository.