# coding: UTF-8

require "spec_helper"

describe Warden::Protocol::InfoRequest do
  subject(:request) do
    Warden::Protocol::InfoRequest.new(:handle => "handle")
  end

  it_should_behave_like "wrappable request"

  it 'has class type methods' do
    expect(request.class.type_camelized).to eq('Info')
    expect(request.class.type_underscored).to eq('info')
  end

  field :handle do
    it_should_be_required
    it_should_be_typed_as_string
  end

  it "should respond to #create_response" do
    expect(request.create_response).to be_a(Warden::Protocol::InfoResponse)
  end
end

describe Warden::Protocol::InfoResponse::CpuStat do
  subject(:response) do
    Warden::Protocol::InfoResponse::CpuStat.new
  end

  field :usage do
    it_should_be_optional
    it_should_be_typed_as_uint64
  end

  field :user do
    it_should_be_optional
    it_should_be_typed_as_uint64
  end

  field :system do
    it_should_be_optional
    it_should_be_typed_as_uint64
  end
end

describe Warden::Protocol::InfoResponse::DiskStat do
  subject(:response) do
    Warden::Protocol::InfoResponse::DiskStat.new
  end

  field :bytes_used do
    it_should_be_optional
    it_should_be_typed_as_uint64
  end

  field :inodes_used do
    it_should_be_optional
    it_should_be_typed_as_uint64
  end
end

describe Warden::Protocol::InfoResponse do
  subject(:response) do
    Warden::Protocol::InfoResponse.new
  end

  it_should_behave_like "wrappable response"

  it 'has class type methods' do
    expect(response.class.type_camelized).to eq('Info')
    expect(response.class.type_underscored).to eq('info')
  end

  it 'should be ok' do
    expect(response).to be_ok
  end

  it 'should not be an error' do
    expect(response).to_not be_error
  end

  field :state do
    it_should_be_optional
    it_should_be_typed_as_string
  end

  field :events do
    it_should_be_optional

    it "should allow one or more events" do
      subject.events = ["a", "b"]
      expect(subject).to be_valid
    end
  end

  field :host_ip do
    it_should_be_optional
    it_should_be_typed_as_string
  end

  field :container_ip do
    it_should_be_optional
    it_should_be_typed_as_string
  end

  field :container_path do
    it_should_be_optional
    it_should_be_typed_as_string
  end

  field :cpu_stat do
    it_should_be_optional

    it "should allow instances of CpuStat" do
      subject.cpu_stat = Warden::Protocol::InfoResponse::CpuStat.new
      expect(subject).to be_valid
    end
  end

  field :disk_stat do
    it_should_be_optional

    it "should allow instances of DiskStat" do
      subject.disk_stat = Warden::Protocol::InfoResponse::DiskStat.new
      expect(subject).to be_valid
    end
  end

  field :job_ids do
    it_should_be_optional

    it "should allow one or more job ids" do
      subject.job_ids = [1, 2]
      expect(subject).to be_valid
    end
  end
end
