require 'common'

class Protocol::V01::TestBase < Net::SFTP::TestCase
  def setup
    @session = stub('session', :logger => nil)
    @base = Net::SFTP::Protocol::V01::Base.new(@session)
  end

  def test_parse_attrs_packet_should_use_correct_attributes_class
    Net::SFTP::Protocol::V01::Attributes.expects(:from_buffer).with(:packet).returns(:result)
    assert_equal({ :attrs => :result }, @base.parse_attrs_packet(:packet))
  end
end

class Protocol::V04::TestAttributes < Net::SFTP::TestCase

  def test_from_buffer_should_correctly_parse_buffer_and_return_attribute_object
    attributes = Net::SFTP::Protocol::V04::Attributes.from_buffer(full_buffer)
    #attribues should be an object of class Net::SFTP::Protocol::V04::Attributes
    #assertion modified to verify this:
    assert_equal(Net::SFTP::Protocol::V04::Attributes, attributes.class)
  end

  private
    def full_buffer
      Net::SSH::Buffer.from(:long, 0x800001fd,
        :byte, 9, :int64, 1234567890,
        :string, "jamis", :string, "users",
        :long, 0755,
        :int64, 1234567890, :long, 12345,
        :int64, 2345678901, :long, 23456,
        :int64, 3456789012, :long, 34567,
        :string, raw(:long, 2,
          :long, 1, :long, 2, :long, 3, :string, "foo",
          :long, 4, :long, 5, :long, 6, :string, "bar"),
        :long, 1, :string, "first", :string, "second")
    end
end
