fastly 1.00 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,8 @@
1
- #!/usr/bin/env ruby
1
+ require 'helper'
2
2
 
3
- require 'rubygems'
4
- require 'test/unit'
5
- require File.expand_path(File.dirname(__FILE__) + '/helper')
6
-
7
- class FullLoginTest < Test::Unit::TestCase
3
+ class FullLoginTest < Fastly::TestCase
8
4
  include CommonTests
9
-
5
+
10
6
  def setup
11
7
  @opts = login_opts(:full).merge(:use_curb => false)
12
8
  begin
@@ -18,7 +14,7 @@ class FullLoginTest < Test::Unit::TestCase
18
14
  exit(-1)
19
15
  end
20
16
  end
21
-
17
+
22
18
  def test_raw_client
23
19
  user = @client.get('/current_user')
24
20
  assert user
@@ -29,8 +25,8 @@ class FullLoginTest < Test::Unit::TestCase
29
25
  assert customer
30
26
  assert_equal @opts[:customer], customer['name']
31
27
  end
32
-
33
-
28
+
29
+
34
30
  def test_current_user_and_customer
35
31
  user = @fastly.current_user
36
32
  assert user
@@ -40,28 +36,28 @@ class FullLoginTest < Test::Unit::TestCase
40
36
  customer = @fastly.current_customer
41
37
  assert customer
42
38
  assert_equal @opts[:customer], customer.name
43
-
39
+
44
40
  tmp_customer = user.customer
45
41
  assert_equal customer.id, tmp_customer.id
46
-
42
+
47
43
  tmp_user = customer.owner
48
44
  assert tmp_user
49
45
  assert_equal user.id, tmp_user.id
50
46
  end
51
-
52
-
47
+
48
+
53
49
  def test_fetching_particular_user
54
50
  current_user = @fastly.current_user
55
51
  assert current_user
56
-
52
+
57
53
  id_user = @fastly.get_user(current_user.id)
58
54
  assert_equal current_user.id, id_user.id
59
55
  assert_equal current_user.name, id_user.name
60
-
56
+
61
57
  # FIXME looking up by login doesn't work yet
62
58
  #login_user = @fastly.get_user(current_user.login)
63
59
  #assert_equal current_user.id, login_user.id
64
- #assert_equal current_user.name, login_user.name
60
+ #assert_equal current_user.name, login_user.name
65
61
 
66
62
  current_customer = @fastly.current_customer
67
63
  assert current_customer
@@ -77,7 +73,7 @@ class FullLoginTest < Test::Unit::TestCase
77
73
  user = @fastly.create_user(:login => email, :name => "New User")
78
74
  assert user
79
75
  assert_equal customer.id, user.customer_id
80
- assert_equal "New User", user.name
76
+ assert_equal "New User", user.name
81
77
  assert_equal email, user.login
82
78
 
83
79
  tmp = @fastly.get_user(user.id)
@@ -85,13 +81,13 @@ class FullLoginTest < Test::Unit::TestCase
85
81
  assert tmp
86
82
  assert_equal user.id, tmp.id
87
83
  assert_equal user.name, tmp.name
88
-
84
+
89
85
  user.name = "Updated Name"
90
- tmp = @fastly.update_user(user)
86
+ tmp = @fastly.update_user(user)
91
87
  assert tmp
92
88
  assert_equal user.id, tmp.id
93
89
  assert_equal "Updated Name", tmp.name
94
-
90
+
95
91
  assert @fastly.delete_user(user)
96
92
  tmp = @fastly.get_user(user.id)
97
93
  assert_equal nil, tmp
@@ -1,4 +1,20 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/common')
1
+ require 'common'
2
+ require 'fastly'
3
+ require 'minitest/autorun'
4
+
5
+ # Accommodate a more modern version of Minitest compared to the stdlib
6
+ if defined? Minitest::Test
7
+ class Fastly::TestCase < Minitest::Test
8
+ end
9
+ else
10
+ class Fastly::TestCase < MiniTest::Unit::TestCase
11
+ end
12
+ end
13
+
14
+ class Fastly::TestCase
15
+ # Map inconsistency between Test::Unit and Minitest
16
+ alias :assert_raise :assert_raises
17
+ end
2
18
 
3
19
  def login_opts(mode=:full)
4
20
  opts = { }
@@ -6,7 +22,7 @@ def login_opts(mode=:full)
6
22
  key = "FASTLY_TEST_BASE_#{what.to_s.upcase}"
7
23
  opts["base_#{what}".to_sym] = ENV[key] if ENV.has_key?(key)
8
24
  end
9
-
25
+
10
26
  required = :full == mode ? [:user, :name, :password, :customer] : [:api_key, :customer]
11
27
  required.each do |what|
12
28
  key ="FASTLY_TEST_#{what.to_s.upcase}"
@@ -21,4 +37,4 @@ end
21
37
 
22
38
  def get_rand
23
39
  "#{Process.pid}-#{Time.now.to_i}-#{Kernel.rand(1000)}"
24
- end
40
+ end
@@ -0,0 +1,85 @@
1
+ require 'helper'
2
+
3
+ FROM = "2011-01-01 00:00:00"
4
+
5
+ class StatsTest < Fastly::TestCase
6
+
7
+ def setup
8
+ opts = login_opts(:api_key).merge(:use_curb => false)
9
+ begin
10
+ @fastly = Fastly.new(opts)
11
+ rescue Exception => e
12
+ warn e.inspect
13
+ warn e.backtrace.join("\n")
14
+ exit(-1)
15
+ end
16
+ end
17
+
18
+ def test_regions
19
+ regions = @fastly.regions
20
+ assert(regions.size>0)
21
+ end
22
+
23
+ def test_usage
24
+ usage = @fastly.usage(:from => FROM)
25
+ assert(usage["usa"], "Found a USA region in usage");
26
+ assert(usage["usa"]["requests"], "USA region has a requests field");
27
+
28
+ usage = @fastly.usage(:from => FROM, :by_service => 1)
29
+ assert(usage["usa"], "Found a USA region in usage");
30
+ assert(usage["usa"]["requests"].nil?, "USA region doesn't have a requests field");
31
+ end
32
+
33
+
34
+ def test_stats
35
+ stats = @fastly.stats(:from => $FROM)
36
+ service1, service2 = stats.keys
37
+ assert(stats[service1][0]["requests"], "Found requests")
38
+ assert(stats[service1][0]["hits"], "Found hits")
39
+ assert(stats[service2][0]["requests"], "Found requests")
40
+ assert(stats[service2][0]["hits"], "Found hits")
41
+
42
+ stats = @fastly.stats(:from => $FROM, :field => "requests")
43
+ assert(stats[service1][0]["requests"], "Found requests")
44
+ assert(stats[service1][0]["hits"].nil?, "Didn't find hits")
45
+ assert(stats[service2][0]["requests"], "Found requests")
46
+ assert(stats[service2][0]["hits"].nil?, "Didn't find hits")
47
+
48
+ stats = @fastly.stats(:from => $FROM, :service => service1)
49
+ assert_equal(stats[0]["service_id"], service1, "Got correct service id")
50
+ assert(stats[0]["requests"], "Found requests")
51
+ assert(stats[0]["hits"], "Found hits")
52
+
53
+ stats = @fastly.stats(:from => $FROM, :field => "requests", :service => service1)
54
+ assert_equal(stats[0]["service_id"], service1, "Got correct service id")
55
+ assert(stats[0]["requests"], "Found requests")
56
+ assert(stats[0]["hits"].nil?, "Didn't find hits")
57
+
58
+ stats = @fastly.stats(:from => $FROM, :aggregate => true)
59
+ assert(stats[0]["service_id"].nil?, "No service id")
60
+ assert(stats[0]["requests"], "Found requests")
61
+ assert(stats[0]["hits"], "Found hits")
62
+
63
+ stats = nil
64
+ # stats aggregate with field
65
+ begin
66
+ stats = @fastly.stats(:from => $FROM, :field => "requests", :aggregate => true)
67
+ rescue Fastly::Error => e
68
+ end
69
+ assert stats.nil?
70
+
71
+ # stats aggregate with service
72
+ begin
73
+ stats = @fastly.stats(:from => $FROM, :service => service1, :aggregate => true)
74
+ rescue Fastly::Error => e
75
+ end
76
+ assert stats.nil?
77
+
78
+ begin
79
+ stats = @fastly.stats(:from => $FROM, :service => service1, :field => "requests", :aggregate => true)
80
+ rescue Fastly::Error => e
81
+ end
82
+ assert stats.nil?
83
+ end
84
+
85
+ end
metadata CHANGED
@@ -1,70 +1,98 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: fastly
3
- version: !ruby/object:Gem::Version
4
- version: "1.00"
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Fastly Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2013-07-16 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: json
11
+ date: 2014-06-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
16
21
  prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
19
- - &id005
20
- - ">="
21
- - !ruby/object:Gem::Version
22
- version: "0"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
23
34
  type: :runtime
24
- version_requirements: *id001
25
- - !ruby/object:Gem::Dependency
26
- name: curb
27
35
  prerelease: false
28
- requirement: &id002 !ruby/object:Gem::Requirement
29
- requirements:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: curb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
30
45
  - - ">="
31
- - !ruby/object:Gem::Version
46
+ - !ruby/object:Gem::Version
32
47
  version: 0.7.15
33
48
  type: :runtime
34
- version_requirements: *id002
35
- - !ruby/object:Gem::Dependency
36
- name: curb-fu
37
49
  prerelease: false
38
- requirement: &id003 !ruby/object:Gem::Requirement
39
- requirements:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
40
52
  - - ">="
41
- - !ruby/object:Gem::Version
53
+ - !ruby/object:Gem::Version
54
+ version: 0.7.15
55
+ - !ruby/object:Gem::Dependency
56
+ name: curb-fu
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
42
61
  version: 0.6.1
43
62
  type: :runtime
44
- version_requirements: *id003
45
- - !ruby/object:Gem::Dependency
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.6.1
69
+ - !ruby/object:Gem::Dependency
46
70
  name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
47
77
  prerelease: false
48
- requirement: &id004 !ruby/object:Gem::Requirement
49
- requirements:
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
50
80
  - - ">="
51
- - !ruby/object:Gem::Version
52
- version: "3.11"
53
- type: :runtime
54
- version_requirements: *id004
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
55
83
  description: Client library for the Fastly acceleration system
56
- email:
84
+ email:
57
85
  - support@fastly.com
58
- executables:
86
+ executables:
59
87
  - fastly_upload_vcl
60
88
  extensions: []
61
-
62
89
  extra_rdoc_files: []
63
-
64
- files:
65
- - .gitignore
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
66
93
  - Changes
67
94
  - Gemfile
95
+ - LICENSE
68
96
  - README.md
69
97
  - Rakefile
70
98
  - bin/fastly_upload_vcl
@@ -73,17 +101,26 @@ files:
73
101
  - lib/fastly/backend.rb
74
102
  - lib/fastly/base.rb
75
103
  - lib/fastly/belongs_to_service_and_version.rb
104
+ - lib/fastly/cache_setting.rb
76
105
  - lib/fastly/client.rb
106
+ - lib/fastly/condition.rb
77
107
  - lib/fastly/customer.rb
78
108
  - lib/fastly/director.rb
79
109
  - lib/fastly/domain.rb
80
110
  - lib/fastly/fetcher.rb
111
+ - lib/fastly/gem_version.rb
112
+ - lib/fastly/gzip.rb
113
+ - lib/fastly/header.rb
81
114
  - lib/fastly/healthcheck.rb
82
115
  - lib/fastly/invoice.rb
83
116
  - lib/fastly/match.rb
84
117
  - lib/fastly/origin.rb
118
+ - lib/fastly/request_setting.rb
119
+ - lib/fastly/response_object.rb
120
+ - lib/fastly/s3_logging.rb
85
121
  - lib/fastly/service.rb
86
122
  - lib/fastly/settings.rb
123
+ - lib/fastly/string.rb
87
124
  - lib/fastly/syslog.rb
88
125
  - lib/fastly/user.rb
89
126
  - lib/fastly/vcl.rb
@@ -93,33 +130,35 @@ files:
93
130
  - test/common.rb
94
131
  - test/full_login_test.rb
95
132
  - test/helper.rb
133
+ - test/stats_test.rb
96
134
  homepage: http://github.com/fastly/fastly-ruby
97
- licenses: []
98
-
135
+ licenses:
136
+ - MIT
99
137
  metadata: {}
100
-
101
138
  post_install_message:
102
139
  rdoc_options: []
103
-
104
- require_paths:
140
+ require_paths:
105
141
  - lib
106
- required_ruby_version: !ruby/object:Gem::Requirement
107
- requirements:
108
- - *id005
109
- required_rubygems_version: !ruby/object:Gem::Requirement
110
- requirements:
111
- - *id005
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
112
152
  requirements: []
113
-
114
153
  rubyforge_project:
115
- rubygems_version: 2.0.5
154
+ rubygems_version: 2.2.2
116
155
  signing_key:
117
156
  specification_version: 4
118
157
  summary: Client library for the Fastly acceleration system
119
- test_files:
158
+ test_files:
120
159
  - test/admin_test.rb
121
160
  - test/api_key_test.rb
122
161
  - test/common.rb
123
162
  - test/full_login_test.rb
124
163
  - test/helper.rb
125
- has_rdoc:
164
+ - test/stats_test.rb