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

Projects
None yet
3 participants
@pocke
Copy link
Contributor

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

  • Add integration test script.
  • Run this test on CI
  • Make the test cases green with itamae local also
  • Add test case for #277 (maybe I should work this todo on #277 )

pocke added some commits Jan 13, 2019

@pocke pocke force-pushed the pocke:test-local branch from ef8d5ea to 381c81a Jan 13, 2019

@@ -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.*\)/) }

This comment has been minimized.

Copy link
@pocke

pocke Jan 13, 2019

Author Contributor

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'

This comment has been minimized.

Copy link
@pocke

pocke Jan 13, 2019

Author Contributor

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']

This comment has been minimized.

Copy link
@pocke

pocke Jan 13, 2019

Author Contributor

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

This comment has been minimized.

Copy link
@pocke

pocke Jan 13, 2019

Author Contributor

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 pocke:test-local branch 2 times, most recently from 9dc4102 to 427bf88 Jan 13, 2019

pocke added some commits Jan 13, 2019

Use ast instead of bundler to installing gem test
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.

@pocke pocke force-pushed the pocke:test-local branch from 427bf88 to b8a8305 Jan 13, 2019


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'

This comment has been minimized.

Copy link
@pocke

pocke Jan 13, 2019

Author Contributor

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.

Skip the integration test with ruby-head
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

This comment has been minimized.

Copy link
Contributor Author

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 Jan 13, 2019

@@ -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"

This comment has been minimized.

Copy link
@sue445

sue445 Jan 13, 2019

Member

Is this necessary?

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

This comment has been minimized.

Copy link
@pocke

pocke Jan 13, 2019

Author Contributor

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.

@sue445

sue445 approved these changes Jan 13, 2019

@unasuke
Copy link
Member

left a comment

🕺

@sue445

This comment has been minimized.

Copy link
Member

commented Jan 15, 2019

@pocke Can I merge this PR?

@pocke

This comment has been minimized.

Copy link
Contributor Author

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

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@pocke pocke deleted the pocke:test-local branch Jan 15, 2019

pocke added a commit to pocke/itamae that referenced this pull request May 10, 2019

Run test cases correctly
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 referenced this pull request May 10, 2019

Merged

Run test cases correctly #289

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.