Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration test with itamae local command #281

Merged
merged 12 commits into from
Jan 15, 2019

Conversation

pocke
Copy link
Contributor

@pocke pocke commented Jan 13, 2019

Problem

We don't have any integration test for itamae local command, so we cannot test #277.

Solution

Add an integation test for itamae local command.

Strategy:

  1. Start a docker container for the test.
  2. Execute itamae local comamnd in the container.
  3. Execute the serverspec from the host machine.

Goal of this pull request

@@ -206,7 +178,7 @@
end

describe command('gem list') do
its(:stdout) { should include('rake (11.1.0)') }
its(:stdout) { should match(/^rake \(.*11.1.0.*\)/) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another rake version is installed in the docker image that is used for itamae local command test, so relax the test.

@@ -0,0 +1,10 @@
package 'sl' do
version '3.03-17+b2'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruby docker image does not have sl package version 3.03-17, it only has 3.03-17+b2.


gem_package 'bundler' do
version '1.17.3'
options ['--no-document']
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New rubygems, which is installed in ruby docker image, does not have --no-rdoc and --no-ri options. So use --no-document option instead.

Note: Ubuntu trusty, which is used in the existing integration test, installs Ruby 1.9.3!!!!! Rubygems on Ruby 1.9.3 has --no-rodc and --no-ri options 🙃 .

@@ -1,5 +1,6 @@
language: ruby
sudo: required
dist: xenial
Copy link
Contributor Author

@pocke pocke Jan 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need upgrading ubuntu version to use new version docker.
In trusty, docker exec does not have --workdir option, so I upgraded it to xenial.

@pocke pocke force-pushed the test-local branch 2 times, most recently from 9dc4102 to 427bf88 Compare January 13, 2019 14:00
pocke added 3 commits January 13, 2019 23:12
Because bundler is too special gem, I got an unexpected and mysterious error with bundler, so I replaced bundler with ast, which is not a special gem.

def docker_run
mount_dir = Pathname(__dir__).join('../').to_s
sh 'docker', 'run', '--privileged', '-d', '--name', CONTAINER_NAME, '-v', "#{mount_dir}:/itamae", "ruby:#{@ruby_version}", 'sleep', '1d'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sleep command is a hack...
/sbin/init is used for the existing integration test, but the image does not have /sbin/init.
So use sleep command instead.

Because `ruby:2.7` image does not exist until releasing Ruby 2.7
@pocke pocke changed the title [WIP] Add integration test with itamae local command Add integration test with itamae local command Jan 13, 2019
@pocke
Copy link
Contributor Author

pocke commented Jan 13, 2019

I think this pull request is ready to review. Can you review this pull request?

I still have an unchecked TODO, but I will work on the todo on #277 .

@sue445 sue445 requested review from sue445 and unasuke January 13, 2019 14:56
@@ -64,7 +69,7 @@ namespace :spec do
RSpec::Core::RakeTask.new(target.to_sym) do |t|
ENV['DOCKER_CONTAINER'] = container_name
t.ruby_opts = '-I ./spec/integration'
t.pattern = "spec/integration/*_spec.rb"
t.pattern = "spec/integration/[default|docker]_spec.rb"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?

Even without changing here, I think that default_spec.rb and docker_spec.rbwill be executed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, it is unnecessary, but I think it is necessary in the near future.
Because I'll add a test case(s) for #277 , and serverspec file. Probably the new serverspec file is needed only by the new test. Test for itamae docker should not load the new serverspec file, so it's necessary.

Copy link
Member

@unasuke unasuke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕺

@sue445
Copy link
Member

sue445 commented Jan 15, 2019

@pocke Can I merge this PR?

@pocke
Copy link
Contributor Author

pocke commented Jan 15, 2019

@pocke Can I merge this PR?

Sure! Thanks for your reviewing!

@sue445 sue445 merged commit efda69f into itamae-kitchen:master Jan 15, 2019
@pocke pocke deleted the test-local branch January 15, 2019 14:54
pocke added a commit to pocke/itamae that referenced this pull request May 10, 2019
Since itamae-kitchen#281 , spec for integration tests are not executed.

Because the pattern is not correct. `[default|docker]` is bad for OR pattern.
It should be `{default,docker}`.

It was introduced by me. I'm sorry🙇🙇

Before
===

```console
$ bundle exec rake spec:integration:ubuntu:trusty

(snip)

/home/pocke/.rbenv/versions/trunk/bin/ruby -I ./spec/integration -I/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rspec-core-3.8.0/lib:/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rspec-support-3.8.0/lib /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rspec-core-3.8.0/exe/rspec --pattern spec/integration/\[default\|docker\]_spec.rb
No examples found.

Finished in 0.00016 seconds (files took 0.03293 seconds to load)
0 examples, 0 failures
```

After
===

```console
$ bundle exec rake spec:integration:ubuntu:trusty

(snip)

/home/pocke/.rbenv/versions/trunk/bin/ruby -I ./spec/integration -I/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rspec-core-3.8.0/lib:/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rspec-support-3.8.0/lib /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rspec-core-3.8.0/exe/rspec --pattern spec/integration/\{default,docker\}_spec.rb

(snip)

Finished in 13.9 seconds (files took 0.28032 seconds to load)
139 examples, 0 failures
```
@pocke pocke mentioned this pull request May 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants