Skip to content

Commit f408dd2

Browse files
committed
Add tests
1 parent 69a243e commit f408dd2

File tree

8 files changed

+30
-42
lines changed

8 files changed

+30
-42
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Set up Node Version Manager ([nvm](https://github.com/nvm-sh/nvm)) in Debian-lik
1414

1515
* `nvm_version` [default: `v0.40.2`]: Version to install
1616
* `nvm_install` [default: `[]`]: (Additional) packages to install (e.g. `build-essential`, `libssl-dev`)
17+
* `nvm_user` [default: `root`]: The user to install nvm for (you want this to be something different than `root`)
18+
* `nvm_shell` [default: `/bin/bash`]: The shell to use to install nvm (changing this to something different is not tested (yet))
1719

1820
## Dependencies
1921

defaults/main.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# defaults file
22
---
33
nvm_version: 'v0.40.2'
4-
54
nvm_install: []
5+
nvm_user: root
6+
nvm_shell: /bin/bash

molecule/default/verify.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
- name: Verify
33
hosts: all
44
become: true
5-
tasks: []
5+
tasks:
6+
- name: include tasks
7+
ansible.builtin.import_tasks: "{{ playbook_dir }}/../../tests/tasks/post.yml"

tasks/main.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
- nvm
2929
- nvm-install
3030
become: true
31-
become_user: "{{ nvm_user | default('root') }}"
31+
become_user: "{{ nvm_user }}"
3232
block:
3333
- name: install | nvm | get current version # noqa command-instead-of-module
3434
ansible.builtin.shell: >
@@ -41,7 +41,9 @@
4141

4242
- name: install | nvm | install given version # noqa command-instead-of-module risky-shell-pipe
4343
ansible.builtin.shell: >
44-
curl -sSL https://raw.githubusercontent.com/nvm-sh/nvm/{{ nvm_version }}/install.sh | bash -
44+
curl -sSL https://raw.githubusercontent.com/nvm-sh/nvm/{{ nvm_version }}/install.sh | {{ nvm_shell }} -
45+
args:
46+
executable: "{{ nvm_shell }}"
4547
environment:
4648
PROFILE: /dev/null
4749
changed_when: true

tests/tasks/post.yml

+13-32
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,15 @@
11
# post test file
22
---
3-
- name: install dependencies # noqa package-latest
4-
ansible.builtin.apt:
5-
name:
6-
- curl
7-
state: latest
8-
update_cache: true
9-
cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}"
10-
11-
- name: test installation # noqa command-instead-of-module risky-shell-pipe
12-
ansible.builtin.command: >
13-
echo 'console.log("PING".replace("I", "O"));'
14-
| nodejs
15-
| grep -q 'PONG'
16-
&& (echo 'Availability test: pass' && exit 0)
17-
|| (echo 'Availability test: fail' && exit 1)
18-
register: _result
19-
changed_when: false
20-
tags:
21-
- skip_ansible_lint
22-
23-
- name: run tests
24-
ansible.builtin.command: >
25-
{{ item }}
26-
changed_when: false
27-
with_items:
28-
# Ensure Node.js is installed
29-
- which node
30-
- node -v
31-
32-
# Ensure npm packages are installed globally
33-
- npm list -g --depth=0 jslint
34-
- npm list -g --depth=0 yo
3+
- name: post | install
4+
become: true
5+
become_user: "{{ nvm_user }}"
6+
block:
7+
- name: post | install | test # noqa command-instead-of-module risky-shell-pipe
8+
ansible.builtin.shell: >
9+
export NVM_DIR=~/.nvm;
10+
source "${NVM_DIR}/nvm.sh" && command -v nvm;
11+
args:
12+
executable: "{{ nvm_shell }}"
13+
register: _result
14+
changed_when: false
15+
failed_when: _result.stdout != 'nvm'

tests/test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
become: true
77
roles:
88
- ../../
9+
post_tasks:
10+
- name: include tasks
11+
ansible.builtin.import_tasks: "{{ playbook_dir }}/tasks/post.yml"

tests/vagrant.yml

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99
nvm_version: 'v0.40.1'
1010
- role: ../../
1111
nvm_user: vagrant
12+
post_tasks:
13+
- name: include tasks
14+
ansible.builtin.import_tasks: "{{ playbook_dir }}/tasks/post.yml"

tests/vars/main.yml

-6
This file was deleted.

0 commit comments

Comments
 (0)