Sha256: 98beae476d8581c4fcd35ee02a251254e42e962df0ed37ba371ce0678b528979

Contents?: true

Size: 1.87 KB

Versions: 22

Compression:

Stored size: 1.87 KB

Contents

require 'helper'

FROM = '2011-01-01 00:00:00'

# Testing client components related to stats
class StatsTest < Fastly::TestCase
  def setup
    opts = login_opts(:api_key)

    begin
      @fastly = Fastly.new(opts)
    rescue => e
      warn e.inspect
      warn e.backtrace.join("\n")
      exit(-1)
    end
  end

  def test_regions
    regions = @fastly.regions
    assert_equal true, (regions.size > 0)
  end

  def test_usage
    usage = @fastly.usage(:from => FROM)
    # usage can be and empty hash if no usage stats
    # this client is not responsiblew for verifying the stats api,
    # just that requests to stats work
    assert(usage)
    assert(usage['meta'])
    assert_equal 'success', usage['status']

    usage = @fastly.usage(:from => FROM, :by_service => 1)
    assert(usage)
    assert(usage['meta'])
    assert_equal 'success', usage['status']
  end

  def test_stats
    stats = @fastly.stats(:from => FROM)
    # stats can be and empty hash if no usage stats
    assert(stats)
    assert_equal 'success', stats['status']
    assert_equal 'all', stats['meta']['region']

    stats = @fastly.stats(:from => FROM, :field => 'requests')
    assert(stats)
    assert_equal 'success', stats['status']
    assert_equal 'all', stats['meta']['region']

    stats = @fastly.stats(:from => FROM, :aggregate => true)
    assert(stats)
    assert_equal 'success', stats['status']
    assert_equal 'all', stats['meta']['region']

    # stats aggregate with field
    assert_raises Fastly::Error do
      @fastly.stats(:from => FROM, :field => 'requests', :aggregate => true)
    end

    # stats aggregate with service
    assert_raises Fastly::Error do
      @fastly.stats(:from => FROM, :service => 'myserviceId', :aggregate => true)
    end

    assert_raises Fastly::Error do
      @fastly.stats(:from => FROM, :service => 'datServiceID', :field => 'requests', :aggregate => true)
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
fastly-1.14.0 test/stats_test.rb
fastly-1.13.2 test/stats_test.rb
fastly-1.13.1 test/stats_test.rb
fastly-1.13.0 test/stats_test.rb
fastly-1.12.0 test/stats_test.rb
fastly-1.11.0 test/stats_test.rb
fastly-1.10.0 test/stats_test.rb
fastly-1.9.0 test/stats_test.rb
fastly-1.8.0 test/stats_test.rb
fastly-1.7.0 test/stats_test.rb
fastly-1.6.1 test/stats_test.rb
fastly-1.6.0 test/stats_test.rb
fastly-1.5.0 test/stats_test.rb
fastly-1.4.3 test/stats_test.rb
fastly-1.4.2 test/stats_test.rb
fastly-1.4.1 test/stats_test.rb
fastly-1.4.0 test/stats_test.rb
fastly-1.3.0 test/stats_test.rb
fastly-1.2.3 test/stats_test.rb
fastly-1.2.2 test/stats_test.rb