12. Copyright Drecom Co., Ltd. All Rights Reserved.
http://www.slideshare.net/t_wada/the-spirit-of-tdd/27
テスト駆動インフラでもTDDの黄金の回転
13. Copyright Drecom Co., Ltd. All Rights Reserved.
● 新しいサーバを作ると自分のhomeディレクトリがないので手
軽に作りたい
【例】自分のhomeディレクトリを作る
14. Copyright Drecom Co., Ltd. All Rights Reserved.
describe file("/home/sueyoshi_go") do
it { should be_directory }
it { should be_mode 700 }
it { should be_owned_by "sueyoshi_go" }
it { should be_grouped_into "drecom" }
end
TARGET_HOST=xxx.xxx.xxx.xxx rspec spec/myhome_spec.rb
Serverspecのテストコード(myhome_spec.rb)
15. Copyright Drecom Co., Ltd. All Rights Reserved.
Serverspecのテストコード(myhome_spec.rb)
/home/sueyoshi_go が
ディレクトリで
パーミッション700で
ownerがsueyoshi_go で
drecom groupに所属していること
describe file("/home/sueyoshi_go") do
it { should be_directory }
it { should be_mode 700 }
it { should be_owned_by "sueyoshi_go" }
it { should be_grouped_into "drecom" }
end
TARGET_HOST=xxx.xxx.xxx.xxx rspec spec/myhome_spec.rb
16. Copyright Drecom Co., Ltd. All Rights Reserved.
Serverspecのテストコード(myhome_spec.rb)
/home/sueyoshi_go が
ディレクトリで
パーミッション700で
ownerがsueyoshi_go で
drecom groupに所属していること
describe file("/home/sueyoshi_go") do
it { should be_directory }
it { should be_mode 700 }
it { should be_owned_by "sueyoshi_go" }
it { should be_grouped_into "drecom" }
end
TARGET_HOST=xxx.xxx.xxx.xxx rspec spec/myhome_spec.rb
それっぽく読める!
17. Copyright Drecom Co., Ltd. All Rights Reserved.
directory "/home/sueyoshi_go" do
mode "700"
owner "sueyoshi_go"
group "drecom"
not_if "ls /home/sueyoshi_go"
end
itamae ssh -h xxx.xxx.xxx.xxx -p 10022 recipes/myhome.rb
itamaeのレシピ (myhome.rb)
18. Copyright Drecom Co., Ltd. All Rights Reserved.
itamaeのレシピ (myhome.rb)
ディレクトリが存在していなければ
/home/sueyoshi_go を作って
パーミッション700で
ownerがsueyoshi_goで
groupをdrecomにすること
directory "/home/sueyoshi_go" do
mode "700"
owner "sueyoshi_go"
group "drecom"
not_if "ls /home/sueyoshi_go"
end
itamae ssh -h xxx.xxx.xxx.xxx -p 10022 recipes/myhome.rb
19. Copyright Drecom Co., Ltd. All Rights Reserved.
itamaeのレシピ (myhome.rb)
ディレクトリが存在していなければ
/home/sueyoshi_go を作って
パーミッション700で
ownerがsueyoshi_goで
groupをdrecomにすること
directory "/home/sueyoshi_go" do
mode "700"
owner "sueyoshi_go"
group "drecom"
not_if "ls /home/sueyoshi_go"
end
itamae ssh -h xxx.xxx.xxx.xxx -p 10022 recipes/myhome.rb
それっぽく読める!
20. Copyright Drecom Co., Ltd. All Rights Reserved.
● 目視確認の自動化
○ インフラコードを書く、適用、確認のサイクルを素早く回
せる
● インフラコードがリファクタリングできる
○ バグってもテストコードで検知できる
テスト駆動インフラのメリット