我希望在serverspec中为nginx重写调用创建一个测试,如下所示(它将@ / folder / file.json URL的请求重定向到@redirect_url变量):
rewrite ^/folder/file.json <%= @redirect_url %> permanent;
对于我正在更新的厨师食谱。不幸的是,从我在互联网上找到的内容来看,它要么强调我完全缺乏对nginx和serverspec术语的理解,要么就是你无法做到这一点。有人能帮忙吗?
答案 0 :(得分:3)
您可以使用Ruby的Net :: HTTP
直接检查响应代码describe Net::HTTP.get_response(URI('http://localhost:port/path')) do
its(:code) { should eq '301' }
its(:msg) { should match 'Moved Permanently' }
end
答案 1 :(得分:1)
使用curl命令重定向severspec是这样的:
redirect_url = "..."
describe command("curl -I http://example.com/folder/file.json") do
its(:stdout) { should match(%r|HTTP/1.1 301 Moved Permanently|) }
its(:stdout) { should match(%r|Location: #{Regexp.escape(redirect_url)}|) }
end