upr.git  about / heads / tags
Upload Progress for Rack
blob bfa9a7c440e605047ea976c9343cc4fc0a136782 1499 bytes (raw)
$ git show HEAD:test/test_monitor.rb	# shows this blob on the CLI

 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
55
56
57
58
 
require 'test/unit'
require 'upr'

class MonitorTest < Test::Unit::TestCase
  def setup
    @monitor = Upr::Monitor.new
  end

  def test_start_with_length
    assert_kind_of Upr::Status, @monitor.start('abcde', 5)
    status = @monitor.read('abcde')
    assert_equal 5, status.length
    assert_equal 0, status.seen
    assert ! status.error?
    assert ! status.done?
  end

  def test_start_without_length
    assert_kind_of Upr::Status, @monitor.start('abcde', nil)
    status = @monitor.read('abcde')
    assert_nil status.length
    assert_equal 0, status.seen
    assert ! status.error?
    assert ! status.done?
  end

  def test_to_incr
    assert_kind_of Upr::Status, @monitor.start('abcde', 5)
    status = @monitor.incr('abcde', 2)
    assert_kind_of Upr::Status, status
    assert_equal 2, status.seen
    assert ! status.error?
    assert ! status.done?
    @monitor.incr('abcde', 3)
    assert_equal 5, status.seen
    assert ! status.error?
    assert status.done?
  end

  def test_finish_with_length
    assert_kind_of Upr::Status, status = @monitor.start('abcde', 5)
    @monitor.finish('abcde')
    assert ! status.error?
    assert status.done?
    assert_equal 5, status.seen
    assert_equal 5, status.length
  end

  def test_finish_without_length
    assert_kind_of Upr::Status, status = @monitor.start('abcde', nil)
    @monitor.finish('abcde')
    assert ! status.error?
    assert status.done?
    assert_equal 0, status.seen
    assert_equal 0, status.length
  end

end

git clone https://yhbt.net/upr.git