Skip to content

Commit

Permalink
(SDK-336) Add operating system question to new module interview
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjek committed Aug 17, 2017
1 parent 86b161f commit b0c0ba1
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 13 deletions.
73 changes: 73 additions & 0 deletions lib/pdk/generators/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,67 @@ def self.module_interview(metadata, opts = {})
required: true,
default: metadata.data['license'],
},
{
name: 'operatingsystem_support',
question: _('What operating systems does this module support?'),
help: _('Use the up and down keys to move between the choices, space to select and enter to continue.'),
required: true,
choices: {
'CentOS' => {
'operatingsystem' => 'CentOS',
'operatingsystemrelease' => ['7'],
},
'Debian' => {
'operatingsystem' => 'Debian',
'operatingsystemrelease' => ['8'],
},
'Fedora' => {
'operatingsystem' => 'Fedora',
'operatingsystemrelease' => ['25'],
},
'Oracle Linux' => {
'operatingsystem' => 'OracleLinux',
'operatingsystemrelease' => ['7'],
},
'OSX' => {
'operatingsystem' => 'Darwin',
'operatingsystemrelease' => ['16'],
},
'RedHat' => {
'operatingsystem' => 'RedHat',
'operatingsystemrelease' => ['7'],
},
'Scientific' => {
'operatingsystem' => 'Scientific',
'operatingsystemrelease' => ['7'],
},
'SLES' => {
'operatingsystem' => 'SLES',
'operatingsystemrelease' => ['12'],
},
'Solaris' => {
'operatingsystem' => 'Solaris',
'operatingsystemrelease' => '11',
},
'Ubuntu' => {
'operatingsystem' => 'Ubuntu',
'operatingsystemrelease' => ['16.04'],
},
'Windows Server 2008 R2' => {
'operatingsystem' => 'windows',
'operatingsystemrelease' => ['2008 R2'],
},
'Windows Server 2012 R2' => {
'operatingsystem' => 'windows',
'operatingsystemrelease' => ['2012 R2'],
},
'Windows 10' => {
'operatingsystem' => 'windows',
'operatingsystemrelease' => ['10'],
},
},
default: [2, 6, 10, 12],
},
{
name: 'summary',
question: _('Please summarize the purpose of this module in a single sentence.'),
Expand Down Expand Up @@ -225,6 +286,18 @@ def self.module_interview(metadata, opts = {})
forge_username = answers['name']
answers['name'] = "#{answers['name']}-#{opts[:name]}"
answers['license'] = opts[:license] if opts.key?(:license)
operating_systems = answers['operatingsystem_support'].dup
answers['operatingsystem_support'] = operating_systems.inject([]) do |result, os_hash|
existing = result.select { |r| r['operatingsystem'] == os_hash['operatingsystem'] }

if existing.empty?
result << os_hash
else
existing.first['operatingsystemrelease'].concat(os_hash['operatingsystemrelease'])
end

result
end
metadata.update!(answers)

puts '-' * 40
Expand Down
106 changes: 93 additions & 13 deletions spec/unit/pdk/generate/module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
'2.2.0',
'William Hopper',
'Apache-2.0',
'',
'A simple module to do some stuff.',
'github.com/whopper/bar',
'forge.puppet.com/whopper/bar',
Expand All @@ -253,17 +254,35 @@
end

it 'populates the Metadata object based on user input' do
allow($stdout).to receive(:puts).with(a_string_matching(%r{8 quick questions}m))
allow($stdout).to receive(:puts).with(a_string_matching(%r{9 quick questions}m))

expect(interview_metadata).to include(
'name' => 'foo-bar',
'version' => '2.2.0',
'author' => 'William Hopper',
'license' => 'Apache-2.0',
'summary' => 'A simple module to do some stuff.',
'source' => 'github.com/whopper/bar',
'project_page' => 'forge.puppet.com/whopper/bar',
'issues_url' => 'tickets.foo.com/whopper/bar',
'name' => 'foo-bar',
'version' => '2.2.0',
'author' => 'William Hopper',
'license' => 'Apache-2.0',
'summary' => 'A simple module to do some stuff.',
'source' => 'github.com/whopper/bar',
'project_page' => 'forge.puppet.com/whopper/bar',
'issues_url' => 'tickets.foo.com/whopper/bar',
'operatingsystem_support' => [
{
'operatingsystem' => 'Debian',
'operatingsystemrelease' => ['8'],
},
{
'operatingsystem' => 'RedHat',
'operatingsystemrelease' => ['7'],
},
{
'operatingsystem' => 'Ubuntu',
'operatingsystemrelease' => ['16.04'],
},
{
'operatingsystem' => 'windows',
'operatingsystemrelease' => ['2012 R2'],
}
],
)
end

Expand Down Expand Up @@ -303,11 +322,12 @@
'',
'',
'',
'',
]
end

it 'populates the interview question defaults with existing metadata values' do
allow($stdout).to receive(:puts).with(a_string_matching(%r{8 quick questions}))
allow($stdout).to receive(:puts).with(a_string_matching(%r{9 quick questions}))

expect(interview_metadata).to include(
'name' => 'defaultauthor-bar',
Expand Down Expand Up @@ -341,6 +361,7 @@
'foo',
'2.2.0',
'William Hopper',
'',
'A simple module to do some stuff.',
'github.com/whopper/bar',
'forge.puppet.com/whopper/bar',
Expand All @@ -350,7 +371,7 @@
end

it 'populates the Metadata object based on user input' do
allow($stdout).to receive(:puts).with(a_string_matching(%r{7 quick questions}m))
allow($stdout).to receive(:puts).with(a_string_matching(%r{8 quick questions}m))

expect(interview_metadata).to include(
'name' => 'foo-bar',
Expand Down Expand Up @@ -386,7 +407,7 @@

it 'exits cleanly' do
allow(logger).to receive(:info).with(a_string_matching(%r{interview cancelled}i))
allow($stdout).to receive(:puts).with(a_string_matching(%r{8 quick questions}m))
allow($stdout).to receive(:puts).with(a_string_matching(%r{9 quick questions}m))

expect { interview_metadata }.to raise_error(SystemExit) { |error|
expect(error.status).to eq(0)
Expand All @@ -403,6 +424,7 @@
'2.2.0',
'William Hopper',
'Apache-2.0',
'',
'A simple module to do some stuff.',
'github.com/whopper/bar',
'forge.puppet.com/whopper/bar',
Expand All @@ -413,7 +435,7 @@

it 'exits cleanly' do
allow(logger).to receive(:info).with(a_string_matching(%r{module not generated}i))
allow($stdout).to receive(:puts).with(a_string_matching(%r{8 quick questions}m))
allow($stdout).to receive(:puts).with(a_string_matching(%r{9 quick questions}m))

expect { interview_metadata }.to raise_error(SystemExit) { |error|
expect(error.status).to eq(0)
Expand All @@ -430,6 +452,7 @@
'2.2.0',
'William Hopper',
'Apache-2.0',
'',
'A simple module to do some stuff.',
'github.com/whopper/bar',
'forge.puppet.com/whopper/bar',
Expand All @@ -455,6 +478,63 @@
)
end
end

context 'when the user selects operating systems' do
include_context 'allow summary to be printed to stdout'

let(:responses) do
[
'foo',
'2.2.0',
'William Hopper',
'Apache-2.0',
"\e[A 1 ", # \e[A == up arrow
'A simple module to do some stuff.',
'github.com/whopper/bar',
'forge.puppet.com/whopper/bar',
'tickets.foo.com/whopper/bar',
'yes',
]
end

it 'includes the modified operatingsystem_support value in the metadata' do
allow($stdout).to receive(:puts).and_call_original
expect { interview_metadata }.not_to raise_error

expect(interview_metadata).to include(
'name' => 'foo-bar',
'version' => '2.2.0',
'author' => 'William Hopper',
'license' => 'Apache-2.0',
'summary' => 'A simple module to do some stuff.',
'source' => 'github.com/whopper/bar',
'project_page' => 'forge.puppet.com/whopper/bar',
'issues_url' => 'tickets.foo.com/whopper/bar',
'operatingsystem_support' => [
{
'operatingsystem' => 'Debian',
'operatingsystemrelease' => ['8'],
},
{
'operatingsystem' => 'RedHat',
'operatingsystemrelease' => ['7'],
},
{
'operatingsystem' => 'Ubuntu',
'operatingsystemrelease' => ['16.04'],
},
{
'operatingsystem' => 'windows',
'operatingsystemrelease' => ['2012 R2', '2008 R2'],
},
{
'operatingsystem' => 'CentOS',
'operatingsystemrelease' => ['7'],
},
],
)
end
end
end

describe '.prepare_metadata' do
Expand Down

0 comments on commit b0c0ba1

Please sign in to comment.