Project

General

Profile

Download (1.42 KB) Statistics
| Branch: | Tag: | Revision:

runcible / test / resources / task_test.rb @ master

1
require 'rubygems'
2
require 'minitest/autorun'
3

    
4
require './test/support/repository_support'
5
require './lib/runcible/resources/task'
6

    
7
module Resources
8
  module TestTaskBase
9
    def setup
10
      @resource = TestRuncible.server.resources.task
11
    end
12
  end
13

    
14
  class TestTask < MiniTest::Unit::TestCase
15
    include TestTaskBase
16
    def self.before_suite
17
      self.support = RepositorySupport.new
18
      self.support.create_repo(:importer => true)
19
      @@task_id = self.support.sync_repo['spawned_tasks'].first['task_id']
20
    end
21

    
22
    def self.after_suite
23
      self.support.destroy_repo
24
    end
25

    
26
    def test_path
27
      path = @resource.class.path
28

    
29
      assert_match 'tasks/', path
30
    end
31

    
32
    def test_path_with_task_id
33
      path = @resource.class.path(@@task_id)
34

    
35
      assert_match "tasks/#{@@task_id}/", path
36
    end
37

    
38
    def test_poll
39
      response = @resource.poll(@@task_id)
40

    
41
      assert_equal 200, response.code
42
      assert_equal @@task_id, response['task_id']
43
    end
44

    
45
    def test_list
46
      response = @resource.list
47

    
48
      assert_equal 200, response.code
49
      refute_empty response
50
    end
51

    
52
    def test_cancel
53
      skip 'TODO: Needs more reliable testable scenario'
54
      response = @resource.cancel(@@task_id)
55

    
56
      assert_equal 200, response.code
57
    end
58

    
59
    def test_poll_all
60
      tasks = @resource.poll_all([@@task_id])
61

    
62
      refute_empty tasks
63
      refute_empty tasks.select { |task| task['task_id'] == @@task_id }
64
    end
65
  end
66
end