2

I have a website to be tested for status code, Using curl command to get the status code of the website. Sometimes it is giving 200 and 302 status codes. I am using serverspec to test the website status code. As I am getting 2 status code, I want to use 'or' condition to get it done. How could I use it. Here is my Serverspec test case.

describe command('curl -IL --retry 4 "www.example.com"') do
  its(:stdout) { should match '200' or '302' }
end

This one is giving error for me.

udondan
  • 57,263
  • 20
  • 190
  • 175
Venu
  • 378
  • 3
  • 10

1 Answers1

4

I have never seen an or in serverspec. But maybe just solve this in the command itself:

describe command('curl -sL -w "%{http_code}\\n" "www.example.com" -o /dev/null | sed "s/200/OK/" | sed "s/302/OK/"') do
  its(:stdout) { should match 'OK' }
end
udondan
  • 57,263
  • 20
  • 190
  • 175
  • it is not "302 OK" but it is "302 NOT Found". This is how it gives "HTTP/1.1 302 Found" or "HTTP/1.1 200 OK", can't be sure when we gonna get these two – Venu Mar 25 '16 at 07:19
  • Pay attention to the command. curl output will ONLY be the status code which later then is **replaced by** "OK" if it was 200 or 302. OK is no related to the meaning of a status code at all. – udondan Mar 25 '16 at 07:21