ruby-pwsh 0.10.1 → 0.10.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -25
- data/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb +3 -0
- data/lib/pwsh/version.rb +1 -1
- data/lib/pwsh.rb +1 -1
- data/lib/templates/init.ps1 +11 -1
- data/spec/acceptance/dsc/basic.rb +205 -0
- data/spec/acceptance/dsc/cim_instances.rb +82 -0
- data/spec/acceptance/dsc/class.rb +129 -0
- data/spec/acceptance/dsc/complex.rb +139 -0
- data/spec/exit-27.ps1 +1 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb +2026 -0
- data/spec/unit/pwsh/util_spec.rb +286 -0
- data/spec/unit/pwsh/version_spec.rb +10 -0
- data/spec/unit/pwsh/windows_powershell_spec.rb +116 -0
- data/spec/unit/pwsh_spec.rb +823 -0
- metadata +17 -22
- data/.gitattributes +0 -2
- data/.github/workflows/ci.yml +0 -109
- data/.gitignore +0 -23
- data/.pmtignore +0 -21
- data/.rspec +0 -3
- data/CHANGELOG.md +0 -196
- data/CODEOWNERS +0 -2
- data/CONTRIBUTING.md +0 -155
- data/DESIGN.md +0 -70
- data/Gemfile +0 -54
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -188
- data/design-comms.png +0 -0
- data/metadata.json +0 -82
- data/pwshlib.md +0 -92
- data/ruby-pwsh.gemspec +0 -39
@@ -0,0 +1,139 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'ruby-pwsh'
|
5
|
+
|
6
|
+
# Needs to be declared here so it is usable in before and it blocks alike
|
7
|
+
test_manifest = File.expand_path('../../fixtures/test.pp', File.dirname(__FILE__))
|
8
|
+
fixtures_path = File.expand_path('../../fixtures', File.dirname(__FILE__))
|
9
|
+
|
10
|
+
def execute_reset_command(reset_command)
|
11
|
+
manager = Pwsh::Manager.instance(Pwsh::Manager.powershell_path, Pwsh::Manager.powershell_args)
|
12
|
+
result = manager.execute(reset_command)
|
13
|
+
raise result[:errormessage] unless result[:errormessage].nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec.describe 'DSC Acceptance: Complex' do
|
17
|
+
let(:powershell) { Pwsh::Manager.instance(Pwsh::Manager.powershell_path, Pwsh::Manager.powershell_args) }
|
18
|
+
let(:module_path) { File.expand_path('../../fixtures/modules', File.dirname(__FILE__)) }
|
19
|
+
let(:puppet_apply) do
|
20
|
+
"bundle exec puppet apply #{test_manifest} --modulepath #{module_path} --detailed-exitcodes --trace"
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'Adding a new website' do
|
24
|
+
before(:each) do
|
25
|
+
reset_command = <<~RESET_COMMAND
|
26
|
+
# Ensure IIS is not installed
|
27
|
+
$Feature = Get-WindowsFeature -Name 'Web-Asp-Net45'
|
28
|
+
If ($Feature.Installed) {
|
29
|
+
Remove-WindowsFeature -Name $Feature.Name -ErrorAction Stop
|
30
|
+
}
|
31
|
+
$DefaultSite = Get-Website 'Default Web Site' -ErrorAction Continue
|
32
|
+
$ExampleSite = Get-Website 'Puppet DSC Site' -ErrorAction Continue
|
33
|
+
If ($DefaultSite.State -eq 'Stopped') {
|
34
|
+
Start-Website -Name $DefaultSite.Name
|
35
|
+
}
|
36
|
+
If ($ExampleSite) {
|
37
|
+
Stop-Website -Name $ExampleSite.Name
|
38
|
+
Remove-Website -Name $ExampleSite.Name
|
39
|
+
Remove-Item -Path '#{fixtures_path}/website' -Recurse -Force -ErrorAction SilentlyContinue
|
40
|
+
}
|
41
|
+
RESET_COMMAND
|
42
|
+
execute_reset_command(reset_command)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'applies idempotently' do
|
46
|
+
content = <<~MANIFEST.strip
|
47
|
+
$destination_path = '#{fixtures_path}/website'
|
48
|
+
$website_name = 'Puppet DSC Site'
|
49
|
+
$site_id = 7
|
50
|
+
$index_html = @(INDEXHTML)
|
51
|
+
<!doctype html>
|
52
|
+
<html lang=en>
|
53
|
+
|
54
|
+
<head>
|
55
|
+
<meta charset=utf-8>
|
56
|
+
<title>blah</title>
|
57
|
+
</head>
|
58
|
+
|
59
|
+
<body>
|
60
|
+
<p>I'm the content</p>
|
61
|
+
</body>
|
62
|
+
|
63
|
+
</html>
|
64
|
+
| INDEXHTML
|
65
|
+
# Install the IIS role
|
66
|
+
dsc_xwindowsfeature { 'IIS':
|
67
|
+
dsc_ensure => 'Present',
|
68
|
+
dsc_name => 'Web-Server',
|
69
|
+
}
|
70
|
+
|
71
|
+
# Stop the default website
|
72
|
+
dsc_xwebsite { 'DefaultSite':
|
73
|
+
dsc_ensure => 'Present',
|
74
|
+
dsc_name => 'Default Web Site',
|
75
|
+
dsc_state => 'Stopped',
|
76
|
+
dsc_serverautostart => false,
|
77
|
+
dsc_physicalpath => 'C:\inetpub\wwwroot',
|
78
|
+
require => Dsc_xwindowsfeature['IIS'],
|
79
|
+
}
|
80
|
+
|
81
|
+
# Install the ASP .NET 4.5 role
|
82
|
+
dsc_xwindowsfeature { 'AspNet45':
|
83
|
+
dsc_ensure => 'Present',
|
84
|
+
dsc_name => 'Web-Asp-Net45',
|
85
|
+
}
|
86
|
+
|
87
|
+
file { 'WebContentFolder':
|
88
|
+
ensure => directory,
|
89
|
+
path => $destination_path,
|
90
|
+
require => Dsc_xwindowsfeature['AspNet45'],
|
91
|
+
}
|
92
|
+
|
93
|
+
# Copy the website content
|
94
|
+
file { 'WebContentIndex':
|
95
|
+
path => "${destination_path}/index.html",
|
96
|
+
content => $index_html,
|
97
|
+
require => File['WebContentFolder'],
|
98
|
+
}
|
99
|
+
|
100
|
+
# Create the new Website
|
101
|
+
dsc_xwebsite { 'NewWebsite':
|
102
|
+
dsc_ensure => 'Present',
|
103
|
+
dsc_name => $website_name,
|
104
|
+
dsc_siteid => $site_id,
|
105
|
+
dsc_state => 'Started',
|
106
|
+
dsc_serverautostart => true,
|
107
|
+
dsc_physicalpath => $destination_path,
|
108
|
+
require => File['WebContentIndex'],
|
109
|
+
}
|
110
|
+
MANIFEST
|
111
|
+
File.open(test_manifest, 'w') { |file| file.write(content) }
|
112
|
+
# Puppet apply the test manifest
|
113
|
+
first_run_result = powershell.execute(puppet_apply)
|
114
|
+
expect(first_run_result[:exitcode]).to be(2)
|
115
|
+
# The Default Site is stopped
|
116
|
+
expect(first_run_result[:native_stdout]).to match(%r{Dsc_xwebsite\[DefaultSite\]/dsc_state: dsc_state changed 'Started' to 'Stopped'})
|
117
|
+
expect(first_run_result[:native_stdout]).to match(/dsc_xwebsite\[{:name=>"DefaultSite", :dsc_name=>"Default Web Site"}\]: Updating: Finished/)
|
118
|
+
# AspNet45 is installed
|
119
|
+
expect(first_run_result[:native_stdout]).to match(%r{Dsc_xwindowsfeature\[AspNet45\]/dsc_ensure: dsc_ensure changed 'Absent' to 'Present'})
|
120
|
+
expect(first_run_result[:native_stdout]).to match(/dsc_xwindowsfeature\[{:name=>"AspNet45", :dsc_name=>"Web-Asp-Net45"}\]: Creating: Finished/)
|
121
|
+
# Web content folder created
|
122
|
+
expect(first_run_result[:native_stdout]).to match(%r{File\[WebContentFolder\]/ensure: created})
|
123
|
+
# Web content index created
|
124
|
+
expect(first_run_result[:native_stdout]).to match(%r{File\[WebContentIndex\]/ensure: defined content as '.+'})
|
125
|
+
# Web site created
|
126
|
+
expect(first_run_result[:native_stdout]).to match(%r{Dsc_xwebsite\[NewWebsite\]/dsc_siteid: dsc_siteid changed to 7})
|
127
|
+
expect(first_run_result[:native_stdout]).to match(%r{Dsc_xwebsite\[NewWebsite\]/dsc_ensure: dsc_ensure changed 'Absent' to 'Present'})
|
128
|
+
expect(first_run_result[:native_stdout]).to match(%r{Dsc_xwebsite\[NewWebsite\]/dsc_physicalpath: dsc_physicalpath changed to '.+fixtures/website'})
|
129
|
+
expect(first_run_result[:native_stdout]).to match(%r{Dsc_xwebsite\[NewWebsite\]/dsc_state: dsc_state changed to 'Started'})
|
130
|
+
expect(first_run_result[:native_stdout]).to match(%r{Dsc_xwebsite\[NewWebsite\]/dsc_serverautostart: dsc_serverautostart changed to 'true'})
|
131
|
+
expect(first_run_result[:native_stdout]).to match(/dsc_xwebsite\[{:name=>"NewWebsite", :dsc_name=>"Puppet DSC Site"}\]: Creating: Finished/)
|
132
|
+
# Run finished
|
133
|
+
expect(first_run_result[:native_stdout]).to match(/Applied catalog/)
|
134
|
+
# Second run is idempotent
|
135
|
+
second_run_result = powershell.execute(puppet_apply)
|
136
|
+
expect(second_run_result[:exitcode]).to be(0)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/spec/exit-27.ps1
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
exit 27
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'ruby-pwsh'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
# Enable flags like --only-failures and --next-failure
|
8
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
9
|
+
|
10
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
11
|
+
config.disable_monkey_patching!
|
12
|
+
|
13
|
+
config.expect_with :rspec do |c|
|
14
|
+
c.syntax = :expect
|
15
|
+
end
|
16
|
+
end
|