Project

General

Profile

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

runcible / test / extensions / ostree_repository_test.rb @ 524638e4

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

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

    
7
module Extensions
8
  module TestOstreeRepositoryBase
9
    def setup
10
      @support = RepositorySupport.new('ostree')
11
      @extension = TestRuncible.server.extensions.repository
12
    end
13
  end
14

    
15
  class TestOstreeRepositoryCreate < MiniTest::Unit::TestCase
16
    include TestOstreeRepositoryBase
17

    
18
    def teardown
19
      @support.destroy_repo
20
      super
21
    end
22

    
23
    def test_create_with_importer
24
      response = @extension.create_with_importer(RepositorySupport.repo_id, :id => 'ostree_web_importer')
25
      assert_equal 201, response.code
26
      response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
27
      assert_equal RepositorySupport.repo_id, response['id']
28
      assert_equal 'ostree_web_importer', response['importers'].first['importer_type_id']
29
    end
30

    
31
    def test_create_with_importer_object
32
      url = "http://cdn.qa.redhat.com/content/htb/rhel/server/7/x86_64/extras/ostree/"
33
      branches = ["redhat-atomic-host/el7.0/x86_64/base", "redhat-atomic-host/el7.0/x86_64/medium"]
34
      mock_importer = Runcible::Models::OstreeImporter.new(:feed => url,
35
                                                           :branches => branches)
36
      response = @extension.create_with_importer(RepositorySupport.repo_id, mock_importer)
37
      assert_equal 201, response.code
38
      response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
39
      assert_equal RepositorySupport.repo_id, response['id']
40
      assert_equal 'ostree_web_importer', response['importers'].first['importer_type_id']
41

    
42
      @extension.expects(:create).with(RepositorySupport.repo_id, has_entry(:notes, anything)).returns(true)
43
      @extension.create_with_importer(RepositorySupport.repo_id, Runcible::Models::OstreeImporter.new)
44
    end
45

    
46
    def test_create_with_distributors
47
      distributors = [{'type_id' => 'ostree_web_distributor', 'id' => '123', 'auto_publish' => true,
48
                       'config' => {'ostree_publish_directory' => '/path'}}]
49
      response = @extension.create_with_distributors(RepositorySupport.repo_id, distributors)
50

    
51
      assert_equal 201, response.code
52
      assert_equal RepositorySupport.repo_id, response['id']
53
    end
54

    
55
    def test_create_with_distributor_object
56
      repo_id = "#{RepositorySupport.repo_id}_distro"
57
      ostree_publish_directory = "/path"
58
      relative_path = "/relative_path"
59
      mock_distro = Runcible::Models::OstreeDistributor.new(:ostree_publish_directory => ostree_publish_directory,
60
                                                            :id => '123',
61
                                                            :relative_path => relative_path)
62
      response = @extension.create_with_distributors(repo_id, [mock_distro])
63
      assert_equal 201, response.code
64
      response = @extension.retrieve(repo_id, :details => true)
65
      assert_equal repo_id, response['id']
66
      assert_equal 'ostree_web_distributor', response['distributors'].first['distributor_type_id']
67
      assert_equal relative_path, response['distributors'].first['config']["relative_path"]
68
      assert_equal ostree_publish_directory, response['distributors'].first['config']["ostree_publish_directory"]
69
    ensure
70
      @support.destroy_repo(repo_id)
71
    end
72

    
73
    def test_create_with_importer_and_distributors
74
      distributors = [{'type_id' => 'ostree_web_distributor', 'id' => '123', 'auto_publish' => true,
75
                       'config' => {}}]
76
      response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id,
77
                                                                 {:id => 'ostree_web_importer'}, distributors)
78
      assert_equal 201, response.code
79

    
80
      response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
81
      assert_equal RepositorySupport.repo_id, response['id']
82
      assert_equal 'ostree_web_distributor', response['distributors'].first['distributor_type_id']
83
    end
84

    
85
    def test_create_with_importer_and_distributors_objects
86
      distributors = [Runcible::Models::OstreeDistributor.new(:id => '123')]
87
      importer = Runcible::Models::OstreeImporter.new
88
      depth = -1
89
      importer.depth = depth
90
      response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id, importer, distributors)
91
      assert_equal 201, response.code
92

    
93
      response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
94
      assert_equal RepositorySupport.repo_id, response['id']
95
      assert_equal 'ostree_web_importer', response['importers'].first['importer_type_id']
96
      assert_equal depth, response['importers'].first['config']['depth']
97
    end
98
  end
99

    
100
  class TestOstreeBranchRepositoryUnitList < MiniTest::Unit::TestCase
101
    def self.before_suite
102
      @@extension = TestRuncible.server.extensions.repository
103
      self.support = RepositorySupport.new("ostree")
104
      self.support.destroy_repo
105
      self.support.create_and_sync_repo(:importer => true)
106
    end
107

    
108
    def self.after_suite
109
      self.support.destroy_repo
110
    end
111

    
112
    def test_ostree_branch_ids
113
      response = @@extension.ostree_branch_ids(RepositorySupport.repo_id)
114
      refute_empty response
115
      assert_kind_of String, response.first
116
    end
117

    
118
    def test_ostree_branches
119
      response = @@extension.ostree_branches(RepositorySupport.repo_id)
120
      refute_empty response
121
      assert_kind_of Hash, response.first
122
      assert_includes response.first.keys, "branch"
123
      assert_includes response.first.keys, "commit"
124
      assert_includes response.first.keys, "metadata"
125
      assert_includes response.first["metadata"].keys, "version"
126
    end
127
  end
128
end