ogle 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/ogle/resource.rb CHANGED
@@ -24,27 +24,19 @@ module Ogle
24
24
  # +image_id+: A String representing an image_id.
25
25
 
26
26
  def find image_id
27
- headers = @connection.head "/images/#{image_id}"
28
-
29
- meta ={}
30
-
31
- headers.each_header do |k, v|
32
- if k.match('x-image-meta-')
33
- meta["#{k}"] = v
27
+ response = @connection.head "/images/#{image_id}"
28
+
29
+ Hash.new.tap do |h|
30
+ properties = h['properties'] = Hash.new
31
+ response.each_header do |k, v|
32
+ case k.downcase.tr '-', '_'
33
+ when %r{^x_image_meta_property_([a-z_]+)$}
34
+ properties[$1] = v
35
+ when %r{^x_image_meta_([a-z_]+)$}
36
+ h[$1] = v
37
+ end
34
38
  end
35
39
  end
36
-
37
- meta
38
- end
39
-
40
- ##
41
- # Stores the disk provided disk image in glance
42
- # Stores provided meta-data about the image in glance
43
- #
44
- # +image_location+: A string representing the location of the image to updload
45
-
46
- def add image_location
47
40
  end
48
-
49
41
  end
50
42
  end
data/lib/ogle/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ogle
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -4,34 +4,104 @@ CONNECTION = Ogle::Client.new(
4
4
  :host => "10.1.170.33"
5
5
  )
6
6
 
7
+ def must_have_valid_keys response, keys
8
+ raise "The response passed in is empty." if response.keys.empty?
9
+ response.keys.delete_if { |k| keys.include? k }.must_be_empty
10
+ end
11
+
7
12
  describe Ogle::Resource do
8
13
  describe "#all" do
9
- it "returns a hash of images" do
14
+ before do
10
15
  VCR.use_cassette "resource_all" do
11
- response = CONNECTION.resource.all
12
-
13
- response.size.must_equal 6
16
+ @response = CONNECTION.resource.all
14
17
  end
15
18
  end
19
+
20
+ it "returns a hash of images" do
21
+ @response.size.must_be :>=, 1
22
+ end
23
+
24
+ it "returns metadata" do
25
+ must_have_valid_keys @response.first, %w(
26
+ name
27
+ container_format
28
+ disk_format
29
+ checksum
30
+ id
31
+ size
32
+ )
33
+ end
16
34
  end
17
35
 
18
36
  describe "#all true" do
19
- it "returns a detailed hash of images (verbose = true)" do
37
+ before do
20
38
  VCR.use_cassette "resource_all_verbose" do
21
- response = CONNECTION.resource.all true
22
-
23
- response.size.must_equal 6
39
+ @response = CONNECTION.resource.all true
24
40
  end
25
41
  end
42
+
43
+ it "returns a detailed hash of images" do
44
+ @response.size.must_be :>=, 1
45
+ end
46
+
47
+ it "returns metadata" do
48
+ must_have_valid_keys @response.first, %w(
49
+ status
50
+ name
51
+ deleted
52
+ container_format
53
+ created_at
54
+ disk_format
55
+ updated_at
56
+ id
57
+ location
58
+ checksum
59
+ is_public
60
+ deleted_at
61
+ properties
62
+ size
63
+ )
64
+ end
26
65
  end
27
66
 
28
67
  describe "#find" do
29
- it "returns X-Image-Meta-* headers as a hash" do
68
+ before do
30
69
  VCR.use_cassette "resource_find" do
31
- response = CONNECTION.resource.find 6
32
-
33
- response.size.must_equal 20
70
+ @response = CONNECTION.resource.find 6
34
71
  end
35
72
  end
73
+
74
+ ### TODO: May want to refactor these keys into a variable,
75
+ ### TODO: since Resource#find verbose shares them.
76
+ it "returns X-Image-Meta-* headers as a hash" do
77
+ must_have_valid_keys @response, %w(
78
+ status
79
+ name
80
+ deleted
81
+ container_format
82
+ created_at
83
+ disk_format
84
+ updated_at
85
+ id
86
+ location
87
+ checksum
88
+ is_public
89
+ deleted_at
90
+ properties
91
+ size
92
+ )
93
+ end
94
+
95
+ it "returns a nested properties hash" do
96
+ must_have_valid_keys @response['properties'], %w(
97
+ distro
98
+ arch
99
+ uploader
100
+ type
101
+ kernel_name
102
+ kernel_id
103
+ version
104
+ )
105
+ end
36
106
  end
37
107
  end
data/test/test_helper.rb CHANGED
@@ -1,18 +1,14 @@
1
- %w(bundler minitest/spec ogle vcr webmock).each { |r| require r }
2
-
3
1
  Bundler.setup :default, :test
4
2
 
3
+ %w(minitest/spec ogle vcr webmock).each { |r| require r }
4
+
5
5
  class MiniTest::Unit::TestCase
6
- def cassette_for cassette
7
- c = VCR::Cassette.new(cassette).send :recorded_interactions
8
- end
9
6
  end
10
7
 
11
8
  VCR.config do |c|
12
9
  c.stub_with :webmock
13
- c.cassette_library_dir = "test/cassettes"
14
- c.default_cassette_options = { :record => :none }
10
+ c.cassette_library_dir = "test/cassettes"
11
+ c.default_cassette_options = { :record => :none }
15
12
  end
16
13
 
17
-
18
14
  MiniTest::Unit.autorun
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ogle
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kevin Bringard
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-08 00:00:00 -06:00
13
+ date: 2011-04-11 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency