Skip to content

Commit

Permalink
feat(windows): add support to work with the default suite
Browse files Browse the repository at this point in the history
  • Loading branch information
myii committed Mar 24, 2022
1 parent 1d97949 commit f1066d6
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion node/config/environ.sls
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{%- from tplroot ~ "/map.jinja" import node with context %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
{%- if 'environ' in node and node.environ %}
{%- if 'environ' in node and node.environ and grains.os_family != 'Windows' %}
{%- if node.pkg.use_upstream_source %}
{%- set sls_package_install = tplroot ~ '.source.install' %}
Expand Down
2 changes: 2 additions & 0 deletions node/config/file.sls
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ node-config-npmrc-file-managed-config_file:
lookup='node-config-file-file-managed-config_file'
)
}}
{%- if grains.os_family != 'Windows' %}
- mode: 640
- user: {{ node.rootuser }}
- group: {{ node.rootgroup }}
{%- endif %}
- makedirs: True
- template: jinja
- context:
Expand Down
2 changes: 1 addition & 1 deletion node/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import node with context %}
{%- if grains.os_family not in ('Windows', 'MacOS',) %}
{%- if grains.os_family not in ('MacOS',) %}
{%- set p = node.pkg %}
include:
Expand Down
4 changes: 4 additions & 0 deletions node/osfamilymap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ OpenBSD:
Solaris: {}

Windows:
config_file: C:\Program Files\nodejs\node_modules\npm\npmrc
config:
prefix: '${APPDATA}\\npm'
pkg:
name: node.js
source:
# win-x64/node.exe
source_hash: 7fca04f83b0e2169e41b2e1845e8da0f07d66cf9c3a1b4150767bf3ffddccf62
Expand Down
20 changes: 15 additions & 5 deletions test/integration/default/controls/config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# frozen_string_literal: true

# Overide by Platform
npmrc_file, config_prefix =
case platform[:family]
when 'windows'
['C:\\Program Files\\nodejs\\node_modules\\npm\\npmrc', '${APPDATA}\\npm']
else
%w[/etc/npmrc /home/vagrant/.npm-packages]
end

root_group =
case platform[:family]
when 'bsd'
Expand All @@ -12,11 +20,13 @@
control 'node configuration' do
title 'should match desired lines'

describe file('/etc/npmrc') do
describe file(npmrc_file) do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into root_group }
its('mode') { should cmp '0640' }
its('content') { should include 'prefix = /home/vagrant/.npm-packages' }
unless %w[windows].include?(platform[:family])
it { should be_owned_by 'root' }
it { should be_grouped_into root_group }
its('mode') { should cmp '0640' }
end
its('content') { should include "prefix = #{config_prefix}" }
end
end
4 changes: 4 additions & 0 deletions test/integration/default/controls/environ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
control 'node configuration environment' do
title 'should match desired lines'

only_if('Environment file not managed on Windows') do
!%w[windows].include?(system.platform[:name])
end

describe file('/etc/default/node.sh') do
it { should be_file }
it { should be_owned_by 'root' }
Expand Down
2 changes: 2 additions & 0 deletions test/integration/default/controls/packages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
else
'nodejs'
end
when 'windows'
'node.js'
else
'nodejs'
end
Expand Down
3 changes: 2 additions & 1 deletion test/salt/pillar/default.sls
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
node:
version: 16.13.0
config:
prefix: '/home/vagrant/.npm-packages'
# yamllint disable-line rule:line-length
prefix: '{{ "${APPDATA}\\npm" if grains.os == "Windows" else "/home/vagrant/.npm-packages" }}'
environ:
a: b
pkg:
Expand Down

0 comments on commit f1066d6

Please sign in to comment.