File: test_content_encoding.rb

package info (click to toggle)
ruby-aliyun-sdk 0.8.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 792 kB
  • sloc: ruby: 7,909; ansic: 204; makefile: 4
file content (54 lines) | stat: -rw-r--r-- 1,310 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require 'minitest/autorun'
require 'yaml'
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
require 'aliyun/oss'
require 'zlib'
require_relative 'config'

class TestContentEncoding < Minitest::Test
  def setup
    Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
    client = Aliyun::OSS::Client.new(TestConf.creds)
    @bucket = client.get_bucket(TestConf.bucket)

    @prefix = "tests/content_encoding/"
  end

  def get_key(k)
    "#{@prefix}#{k}"
  end

  def test_gzip_encoding
    key = get_key('gzip')
    File.open('/tmp/x', 'w') do |f|
      1000.times { f.write 'hello world' * 1024 }
    end

    @bucket.put_object(
      key, file: '/tmp/x', content_type: 'text/plain')

    @bucket.get_object(
      key, file: '/tmp/y', headers: {'accept-encoding' => 'gzip'})

    assert File.exist?('/tmp/y')
    diff = `diff /tmp/x /tmp/y`
    assert diff.empty?
  end

  def test_deflate_encoding
    key = get_key('deflate')
    File.open('/tmp/x', 'w') do |f|
      1000.times { f.write 'hello world' * 1024 }
    end

    @bucket.put_object(
      key, file: '/tmp/x', content_type: 'text/plain')

    @bucket.get_object(
      key, file: '/tmp/y', headers: {'accept-encoding' => 'deflate'})

    assert File.exist?('/tmp/y')
    diff = `diff /tmp/x /tmp/y`
    assert diff.empty?
  end
end