Skip to content

Commit

Permalink
Extract molecule to subgenerator (#36)
Browse files Browse the repository at this point in the history
* Add molecule subgenerator skel

* Move molecule generation to its own subgenerator

* Remove extra prompts overrides

* Mock molecule subgenerator

* Spy on mocked generator

* Add molecule subgenerator options

* Extract prompts to module

* Fix options

* 0.3.0
  • Loading branch information
coaxial committed Oct 6, 2018
1 parent 5bb71dc commit aa1a9f1
Show file tree
Hide file tree
Showing 18 changed files with 826 additions and 439 deletions.
21 changes: 21 additions & 0 deletions __tests__/__helpers__/mockGenerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var Generator = require('yeoman-generator');

const spy = jest.fn();
const mockGenerator = () =>
class extends Generator {
constructor(args, opts) {
super(args, opts);
spy(args, opts);
}

test() {
// This method is required so that it doesn't complain about the
// generator having no method to run. It doesn't do anything useful other
// than that.
}
};

module.exports = {
mockGenerator,
spy,
};
136 changes: 0 additions & 136 deletions __tests__/__snapshots__/app.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -199,112 +199,6 @@ galaxy_info:
"
`;

exports[`generator-molecule-lxd-role:app when all the prompts have answers molecule/create.yml is correctly formatted 1`] = `
"---
- name: Create
hosts: localhost
connection: local
gather_facts: false
no_log: \\"{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}\\"
tasks:
- name: Create molecule instance(s)
lxd_container:
name: \\"{{ item.name }}\\"
state: started
source:
type: image
mode: pull
server: https://images.linuxcontainers.org
protocol: simplestreams
alias: \\"{{ item.alias }}/amd64\\"
profiles: [\\"default\\"]
wait_for_ipv4_addresses: true
timeout: 600
with_items: \\"{{ molecule_yml.platforms }}\\"
- name: Install Python in container
delegate_to: \\"{{ item.name }}\\"
raw: apt-get install -y python
with_items: \\"{{ molecule_yml.platforms }}\\"
"
`;

exports[`generator-molecule-lxd-role:app when all the prompts have answers molecule/default/molecule.yml is correctly formatted 1`] = `
"---
dependency:
name: galaxy
driver:
name: lxd
lint:
name: yamllint
platforms:
- name: ubuntu-trusty
alias: ubuntu/trusty
- name: ubuntu-xenial
alias: ubuntu/xenial
- name: ubuntu-bionic
alias: ubuntu/bionic
provisioner:
name: ansible
playbooks:
create: ../create.yml
destroy: ../destroy.yml
lint:
name: ansible-lint
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8
"
`;

exports[`generator-molecule-lxd-role:app when all the prompts have answers molecule/default/playbook.yml is correctly formatted 1`] = `
"---
- name: Converge
hosts: all
roles:
- name: ansible-role-test-role
"
`;

exports[`generator-molecule-lxd-role:app when all the prompts have answers molecule/default/tests/test_default.py is correctly formatted 1`] = `
"import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_example(host):
file = host.file('/etc/hosts')
assert file.exists
assert file.user == 'root'
assert file.group == 'root'
"
`;

exports[`generator-molecule-lxd-role:app when all the prompts have answers molecule/destroy.yml is correctly formatted 1`] = `
"---
- name: Destroy
hosts: localhost
connection: local
gather_facts: false
no_log: \\"{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}\\"
tasks:
- name: Destroy molecule instance(s)
lxd_container:
name: \\"{{ item.name }}\\"
state: absent
force_stop: \\"{{ item.force_stop | default(true) }}\\"
with_items: \\"{{ molecule_yml.platforms }}\\"
"
`;

exports[`generator-molecule-lxd-role:app when all the prompts have answers tasks/main.yml is correctly formatted 1`] = `
"---
"
Expand All @@ -315,36 +209,6 @@ exports[`generator-molecule-lxd-role:app when all the prompts have answers vars/
"
`;

exports[`generator-molecule-lxd-role:app when targetting another distribution than Ubuntu molecule/default/molecule.yml formats the platform list properly 1`] = `
"---
dependency:
name: galaxy
driver:
name: lxd
lint:
name: yamllint
platforms:
- name: debian-jessie
alias: debian/jessie
- name: debian-stretch
alias: debian/stretch
provisioner:
name: ansible
playbooks:
create: ../create.yml
destroy: ../destroy.yml
lint:
name: ansible-lint
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8
"
`;

exports[`generator-molecule-lxd-role:app when there are no dependencies README.md skips the dependencies section 1`] = `
"Test role
=========
Expand Down
Loading

0 comments on commit aa1a9f1

Please sign in to comment.