1

I am writing a simple cookbook that will be used to deploy an SSL proxy onto a server. This cookbook will ultimately be used by other cookbooks that deploy web services in order to set up an SSL proxy in front of them, but for the purpose of testing the proxy cookbook itself, there is no such service behind it. My basic testing strategy for this cookbook is as follows:

  1. Converge the box with test-kitchen
  2. Use ServerSpec (or possibly Bats) with test-kitchen to
    1. Setup test by starting a python SimpleHTTPServer on the box listing on the port that the proxy was configured to forward to, and create in index.html file for it to serve.
    2. Assert that when I hit https://localhost I get the file that SimpleHTTPServer is serving.
    3. Assert a few more things about the proxy (all of which require that there be a service behind it.)
  3. Teardown. No real need to tear anything down, just let test-kitchen destroy the box.

So my question is, what is the right way to set up these sort of test preconditions using test-kitchen and ServerSpec and/or bats?

4

2 回答 2

0

如果设置和拆卸确实不是我正在测试的一部分,那么我通常只是在每次测试之前运行的 Ruby 中进行它们(通常在 spec_helper.rb 中)。由于 serverspec 只是在测试厨房实例上逐行运行 ruby​​ 代码,因此我觉得没有必要在 serverspec 中有提供设置/拆卸功能的东西(换句话说,没有排序问题或重复测试将需要调用 setup 或 teardown 方法)。

于 2015-03-17T17:52:45.977 回答
0

老问题,但为了完整性:
您可以before在 serverspec 中使用 rspec。

describe file('/tmp/testfile') do
  before do
    File.write('/tmp/testfile', 'Hello, world')
  end
  it { should exist }
  its(:content) { should include('Hello') }
end

https://github.com/jantman/serverspec-extended-types中的http_get类型可以提供从 serverspec 中进行 HTTP 服务器测试所需的内容。

于 2018-05-15T08:42:28.940 回答