Project

General

Profile

Revision 61c9e238

Added by Partha Aji over 6 years ago

Fixes #14032 - Ostree branches now searchable in a Repo

View differences:

lib/runcible/extensions/repository.rb
240 240
        unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
241 241
      end
242 242

  
243
      # Retrieves the ostree branch IDs for a single repository
244
      #
245
      # @param  [String]                id the ID of the repository
246
      # @return [RestClient::Response]  the set of repository ostree branch IDs
247
      def ostree_branch_ids(id)
248
        criteria = {:type_ids => [Runcible::Extensions::OstreeBranch.content_type],
249
                    :fields => {:unit => [], :association => ['unit_id']}}
250

  
251
        unit_search(id, criteria).map { |i| i['unit_id'] }
252
      end
253

  
254
      # Retrieves the ostree branches for a single repository
255
      #
256
      # @param  [String]                id the ID of the repository
257
      # @return [RestClient::Response]  the set of repository ostree branches
258
      def ostree_branches(id)
259
        criteria = {:type_ids => [Runcible::Extensions::OstreeBranch.content_type]}
260
        unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
261
      end
262

  
243 263
      # Retrieves the docker manifest IDs for a single repository
244 264
      #
245 265
      # @param  [String]                id the ID of the repository
test/extensions/ostree_branch_test.rb
1
require 'rubygems'
2
require 'minitest/autorun'
3

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

  
8
module Extensions
9
  class TestOstreeBranch < MiniTest::Unit::TestCase
10
    def self.before_suite
11
      self.support = RepositorySupport.new("ostree")
12
      @@extension = TestRuncible.server.extensions.ostree_branch
13
      support.create_and_sync_repo(:importer => true)
14
    end
15

  
16
    def self.after_suite
17
      support.destroy_repo
18
    end
19

  
20
    def test_content_type
21
      assert_equal 'ostree', @@extension.content_type
22
    end
23

  
24
    def test_all
25
      response = @@extension.all
26

  
27
      assert_equal 200, response.code
28
      refute_empty response
29
    end
30

  
31
    def test_find
32
      id = @@extension.all.sort_by { |p| p['id'] }.first['id']
33
      response = @@extension.find(id)
34

  
35
      refute_empty response
36
      assert_equal id, response['id']
37
    end
38

  
39
    def test_find_by_unit_id
40
      id = @@extension.all.sort_by { |p| p['id'] }.first['_id']
41
      response = @@extension.find_by_unit_id(id)
42

  
43
      refute_empty response
44
      assert_equal id, response['_id']
45
    end
46

  
47
    def test_find_unknown
48
      response = @@extension.find_all(['f'])
49

  
50
      assert_empty response
51
    end
52

  
53
    def test_find_all
54
      pkgs = @@extension.all.sort_by { |p| p['id'] }
55
      ids = pkgs.map { |p| p['id'] }
56
      response = @@extension.find_all(ids)
57

  
58
      assert_equal 200, response.code
59
      assert_equal ids.length, response.length
60
    end
61

  
62
    def test_find_all_by_unit_ids
63
      id = @@extension.all.sort_by { |p| p['id'] }.first['_id']
64
      response = @@extension.find_all_by_unit_ids([id])
65

  
66
      refute_empty response
67
      assert_equal id, response.first['_id']
68
    end
69
  end
70

  
71
  class TestOstreeBranchCopy < UnitCopyBase
72
    def self.extension_class
73
      TestRuncible.server.extensions.ostree_branch
74
    end
75

  
76
    def test_copy
77
      response = self.class.extension_class.copy(RepositorySupport.repo_id, self.class.clone_name)
78
      tasks = assert_async_response(response)
79

  
80
      clone_ids    = unit_ids(self.class.clone_name)
81
      original_ids = unit_ids(RepositorySupport.repo_id)
82

  
83
      assert_includes tasks.first['tags'], 'pulp:action:associate'
84
      assert_equal original_ids.length, clone_ids.length
85
    end
86
  end
87
end
test/extensions/ostree_repository_test.rb
93 93
      assert_equal 'ostree_web_importer', response['importers'].first['importer_type_id']
94 94
    end
95 95
  end
96

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

  
105
    def self.after_suite
106
      self.support.destroy_repo
107
    end
108

  
109
    def test_ostree_branch_ids
110
      response = @@extension.ostree_branch_ids(RepositorySupport.repo_id)
111
      refute_empty response
112
      assert_kind_of String, response.first
113
    end
114

  
115
    def test_ostree_branches
116
      response = @@extension.ostree_branches(RepositorySupport.repo_id)
117
      refute_empty response
118
      assert_kind_of Hash, response.first
119
      assert_includes response.first.keys, "branch"
120
      assert_includes response.first.keys, "commit"
121
      assert_includes response.first.keys, "metadata"
122
      assert_includes response.first["metadata"].keys, "version"
123
    end
124
  end
96 125
end
test/fixtures/repositories/ostree/create.sh
1
#!/bin/bash
2
pushd .
3
path="/tmp/fedora"
4

  
5
echo ${path}
6

  
7
rm -rf ${path}
8
mkdir -p ${path}
9
cd ${path}
10

  
11
ostree init --repo=. --mode=archive-z2
12

  
13
# 23.1
14
ostree commit --repo=. -b fedora-atomic/f21/x86_64/updates/docker-host --add-metadata-string=version=23.1 -s testing
15
ostree commit --repo=. -b fedora-atomic/f21/x86_64/updates-testing/docker-host --add-metadata-string=version=23.1 -s testing
16
ostree commit --repo=. -b fedora-atomic/f21/x86_64/updates/docker-host --add-metadata-string=version=23.2 -s testing
17
# 23.2
18
ostree commit --repo=. -b fedora-atomic/f21/x86_64/updates-testing/docker-host --add-metadata-string=version=23.2 -s testing
19
ostree commit --repo=. -b fedora-atomic/f21/x86_64/updates/docker-host --add-metadata-string=version=23.3 -s testing
20
ostree commit --repo=. -b fedora-atomic/f21/x86_64/updates-testing/docker-host --add-metadata-string=version=23.3 -s testing
21

  
22
ostree summary -u
23
popd
24

  
25
tar czf ./ostree-fedora-repo.tgz ${path}
test/support/repository_support.rb
27 27
    elsif @repo_type == 'python'
28 28
      @distributors = [Runcible::Models::PythonDistributor.new]
29 29
      @repo_url     = "https://pypi.python.org"
30
    elsif @repo_type == 'ostree'
31
      @distributors  = [Runcible::Models::OstreeDistributor.new(:ostree_publish_directory => '/path',
32
                                                                :id => 'ostree_dist',
33
                                                                :relative_path => "/relpath")]
34
      @repo_url      = "file://#{FIXTURE_PATH}/ostree/fedora"
35
      @importer_type = "ostree_web_importer"
30 36
    end
31 37
  end
32 38

  
test/vcr_setup.rb
10 10
    unless system("sudo cp -rf #{File.dirname(__FILE__)}/fixtures/repositories /var/www/")
11 11
      fail "Cannot copy repository fixtures to /var/www, ensure sudo access"
12 12
    end
13
    unless system("sudo tar zxf /var/www/repositories/ostree/*.tgz -C /var/www/repositories/ostree")
14
      fail "Could not extract the ostree repo"
15
    end
16

  
13 17
  end
14 18

  
15 19
  VCR.configure do |c|

Also available in: Unified diff