Skip to content

Commit 1a96921

Browse files
authored
Merge pull request #216 from myii/add-test-vimrc-generation
fix(vimrc): ensure `vimrc` state runs
2 parents 852dff2 + 86144be commit 1a96921

File tree

9 files changed

+123
-3
lines changed

9 files changed

+123
-3
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ jobs:
5050
## Define the rest of the matrix based on Kitchen testing
5151
# Make sure the instances listed below match up with
5252
# the `platforms` defined in `kitchen.yml`
53-
- env: INSTANCE=default-debian-10-master-py3
53+
# - env: INSTANCE=default-debian-10-master-py3
54+
- env: INSTANCE=vimrc-debian-10-master-py3
5455
# - env: INSTANCE=default-ubuntu-1804-master-py3
5556
# - env: INSTANCE=default-centos-8-master-py3
5657
# - env: INSTANCE=default-fedora-31-master-py3

kitchen.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,26 @@ suites:
192192
verifier:
193193
inspec_tests:
194194
- path: test/integration/default
195+
- name: vimrc
196+
provisioner:
197+
state_top:
198+
base:
199+
'*':
200+
- users.vimrc
201+
pillars:
202+
top.sls:
203+
base:
204+
'*':
205+
- users
206+
- vimrc
207+
pillars_from_files:
208+
users.sls: test/salt/pillar/default.sls
209+
vimrc.sls: test/salt/pillar/vimrc.sls
210+
dependencies:
211+
- name: vim
212+
repo: git
213+
source: https://github.com/saltstack-formulas/vim-formula.git
214+
verifier:
215+
inspec_tests:
216+
- path: test/integration/default
217+
- path: test/integration/vimrc

test/integration/vimrc/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# InSpec Profile: `vimrc`
2+
3+
This shows the implementation of the `vimrc` InSpec [profile](https://github.com/inspec/inspec/blob/master/docs/profiles.md).
4+
5+
## Verify a profile
6+
7+
InSpec ships with built-in features to verify a profile structure.
8+
9+
```bash
10+
$ inspec check vimrc
11+
Summary
12+
-------
13+
Location: vimrc
14+
Profile: profile
15+
Controls: 4
16+
Timestamp: 2019-06-24T23:09:01+00:00
17+
Valid: true
18+
19+
Errors
20+
------
21+
22+
Warnings
23+
--------
24+
```
25+
26+
## Execute a profile
27+
28+
To run all **supported** controls on a local machine use `inspec exec /path/to/profile`.
29+
30+
```bash
31+
$ inspec exec vimrc
32+
..
33+
34+
Finished in 0.0025 seconds (files took 0.12449 seconds to load)
35+
8 examples, 0 failures
36+
```
37+
38+
## Execute a specific control from a profile
39+
40+
To run one control from the profile use `inspec exec /path/to/profile --controls name`.
41+
42+
```bash
43+
$ inspec exec vimrc --controls package
44+
.
45+
46+
Finished in 0.0025 seconds (files took 0.12449 seconds to load)
47+
1 examples, 0 failures
48+
```
49+
50+
See an [example control here](https://github.com/inspec/inspec/blob/master/examples/profile/controls/example.rb).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
control 'vimrc is managed' do
4+
title 'formula should manage .vimrc'
5+
6+
describe file('/home/vim_user/.vimrc') do
7+
it { should be_owned_by 'vim_user' }
8+
its('mode') { should cmp '0644' }
9+
its('content') { should match(/syntax on/) }
10+
end
11+
end

test/integration/vimrc/inspec.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
name: vimrc
5+
title: users formula
6+
maintainer: SaltStack Formulas
7+
license: Apache-2.0
8+
summary: Verify that the `.vimrc` file is configured correctly for specified users
9+
supports:
10+
- platform-name: debian
11+
- platform-name: ubuntu
12+
- platform-name: centos
13+
- platform-name: fedora
14+
- platform-name: opensuse
15+
- platform-name: suse
16+
- platform-name: freebsd
17+
- platform-name: amazon
18+
- platform-name: arch

test/salt/pillar/default.sls

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# vim: ft=yaml
33
---
44
users-formula:
5-
use_vim_formula: true
65
lookup: # override the defauls in map.jinja
76
root_group: root
87

test/salt/pillar/vimrc.sls

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
users-formula:
5+
use_vim_formula: true
6+
7+
users:
8+
## Minimal required pillar values
9+
vim_user:
10+
fullname: Vim User
11+
manage_vimrc: true

users/files/vimrc/vimrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2+
" File managed by Salt at <{{ source }}>.
3+
" Your changes will be overwritten.
4+
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5+
"
6+
{% raw -%}
17
" URL: http://vim.wikia.com/wiki/Example_vimrc
28
" Authors: http://vim.wikia.com/wiki/Vim_on_Freenode
39
" Description: A minimal, but feature rich, example .vimrc. If you are a
@@ -158,3 +164,4 @@ nnoremap <C-L> :nohl<CR><C-L>
158164
159165

160166
"------------------------------------------------------------
167+
{%- endraw %}

users/vimrc.sls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% from "users/map.jinja" import users with context %}
22
3-
{% if users.use_vim_formula %}
3+
{% if salt['pillar.get']('users-formula:use_vim_formula', False) %}
44
55
include:
66
- users

0 commit comments

Comments
 (0)