Last active
August 29, 2015 14:00
-
-
Save yshnb/11501428 to your computer and use it in GitHub Desktop.
test-kitchen + serverspecで行うchef-repoのテスト ref: http://qiita.com/yshnb/items/854a1770d0d47479ab47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| driver: | |
| name: vagrant | |
| provisioner: | |
| name: chef_solo | |
| platforms: | |
| # - name: ubuntu-12.04 | |
| - name: centos-64 | |
| suites: | |
| - name: app | |
| run_list: | |
| - recipe[apache2::default] | |
| attributes: | |
| platform_family: "rhel" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'serverspec' | |
| set :backend, :exec | |
| # httpdがインストールされている | |
| describe package("httpd") do | |
| it { should be_installed } | |
| end | |
| # httpdプロセスが稼働している | |
| describe process("httpd") do | |
| it { should be_running } | |
| end | |
| # TCP80番で待ち受けている | |
| describe port("80") do | |
| it { should be_listening.with("tcp") } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| source "http://api.berksfile.com" # berkshelfのバージョンが<3の場合は site: opscode | |
| cookbook "apache2" | |
| cookbook "hoge", path: "site-cookbooks/hoge" # ローカルのsite-cookbooksに直接存在するcookbook | |
| cookbook "fuga", git: "git:fuga@fuga-repository.com" # gitのリポジトリ上に存在するcookbook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ gem install chef | |
| $ gem install berkshelf | |
| $ gem install test-kitchen | |
| $ gem install serverspec |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ kitchen converge [INSTANCE] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [2014-05-03T16:13:59+00:00] INFO: Report handlers complete | |
| Chef Client finished, 67/74 resources updated in 67.515359435 seconds | |
| Finished converging <default-centos-64> (2m18.63s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # テスト用ディレクトリ | |
| $ mkdir -p CHEF-REPO_PATH/test/integration/SUITE_NAME/TESTING_FRAMEWORK/ | |
| # テスト用ファイルの作成 | |
| $ touch CHEF-REPO_PATH/test/integration/SUITE_NAME/TESTING_FRAMEWORK/*_spec.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ kitchen verify [INSTANCE] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -----> Starting Kitchen (v1.2.1) | |
| -----> Verifying <default-centos-64>... | |
| Suite path directory /tmp/busser/suites does not exist, skipping. | |
| Uploading /tmp/busser/suites/serverspec/apache2_spec.rb (mode=0644) | |
| Uploading /tmp/busser/suites/serverspec/vagrant_spec.rb (mode=0644) | |
| -----> Running serverspec test suite | |
| /opt/chef/embedded/bin/ruby -I/tmp/busser/suites/serverspec -S /opt/chef/embedded/bin/rspec /tmp/busser/suites/serverspec/apache2_spec.rb /tmp/busser/suites/serverspec/vagrant_spec.rb --color --format documentation | |
| Package "httpd" | |
| should be installed | |
| Process "httpd" | |
| should be running | |
| Port "80" | |
| should be listening | |
| User "vagrant" | |
| should exist [] | |
| should belong to group "wheel" | |
| Finished in 0.35567 seconds | |
| 5 examples, 0 failures | |
| Finished verifying <default-centos-64> (0m2.52s). | |
| -----> Kitchen is finished. (0m3.54s) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'serverspec' | |
| set :backend, :exec | |
| # vagrantユーザについて | |
| describe user("vagrant") do | |
| it { should exist } # vagrantユーザが存在する | |
| it { should belong_to_group "wheel" } # vagrantユーザはwheelに所属している | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment