dboard 1.1.0 → 1.1.1
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.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +26 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -0
- data/Gemfile +6 -1
- data/README.md +2 -0
- data/Rakefile +3 -3
- data/dboard.gemspec +5 -6
- data/lib/api.rb +8 -8
- data/lib/cache.rb +1 -1
- data/lib/collector.rb +2 -2
- data/lib/dboard.rb +3 -3
- data/lib/publisher.rb +2 -2
- data/lib/version.rb +1 -1
- data/spec/collector_spec.rb +21 -20
- data/spec/publisher_spec.rb +5 -7
- data/spec/spec_helper.rb +7 -7
- metadata +11 -11
- data/.rvmrc +0 -1
- data/spec/integration_spec.rb +0 -54
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 60c9af8ba57dc09e45ec0f39a2e8394705c4cfadd771f52210578438f4f64219
         | 
| 4 | 
            +
              data.tar.gz: d1422616d6c609c49cd32c1a88481ae929391d5d3d937cc81b5abb1e37457a90
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: '091c5bebede637161ece4d905ec07acb12d018c2d7dde186bb427639edbebe43211393ea6279b9ec212f02cdaff847b9812d21e6f1e1bc98dd9dbf117d0ee33a'
         | 
| 7 | 
            +
              data.tar.gz: dcc00cb4d504f0911b19f68c98af3db66e76a4cef444a8efcbb0e1a8daaa2a281da11f12eb3ae132bee5c7b06c09e0e228c17b2ad1ad2af005e47d379d71c5b0
         | 
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            name: Ruby CI
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            on:
         | 
| 4 | 
            +
              push:
         | 
| 5 | 
            +
                branches: [ master ]
         | 
| 6 | 
            +
              pull_request:
         | 
| 7 | 
            +
                branches: [ master ]
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            jobs:
         | 
| 10 | 
            +
              test:
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                runs-on: ubuntu-latest
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                strategy:
         | 
| 15 | 
            +
                  matrix:
         | 
| 16 | 
            +
                    ruby-version: ["3.0", "2.7", "2.6", "2.5"]
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                steps:
         | 
| 19 | 
            +
                  - uses: actions/checkout@v2
         | 
| 20 | 
            +
                  - name: Set up Ruby ${{ matrix.ruby-version }}
         | 
| 21 | 
            +
                    uses: ruby/setup-ruby@v1
         | 
| 22 | 
            +
                    with:
         | 
| 23 | 
            +
                      ruby-version: ${{ matrix.ruby-version }}
         | 
| 24 | 
            +
                      bundler-cache: true # runs 'bundle install' and caches installed gems automatically
         | 
| 25 | 
            +
                  - name: Run tests
         | 
| 26 | 
            +
                    run: bundle exec rake
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/.rubocop.yml
    ADDED
    
    
    
        data/Gemfile
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,3 +1,5 @@ | |
| 1 | 
            +
            [](https://github.com/barsoom/dboard/actions/workflows/ci.yml)
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            A dashboard framework.
         | 
| 2 4 |  | 
| 3 5 | 
             
            It handles collecting data from user defined sources (simple ruby classes) and provides a simple API to poll for updates. See the [example app](https://github.com/joakimk/dboard_example) for information on how to use it.
         | 
    
        data/Rakefile
    CHANGED
    
    | @@ -1,5 +1,5 @@ | |
| 1 | 
            -
            require  | 
| 2 | 
            -
            require  | 
| 1 | 
            +
            require "bundler"
         | 
| 2 | 
            +
            require "rspec/core/rake_task"
         | 
| 3 3 |  | 
| 4 4 | 
             
            Bundler::GemHelper.install_tasks
         | 
| 5 5 |  | 
| @@ -7,4 +7,4 @@ desc "Run specs" | |
| 7 7 | 
             
            RSpec::Core::RakeTask.new do |t|
         | 
| 8 8 | 
             
            end
         | 
| 9 9 |  | 
| 10 | 
            -
            task : | 
| 10 | 
            +
            task default: :spec
         | 
    
        data/dboard.gemspec
    CHANGED
    
    | @@ -6,22 +6,21 @@ Gem::Specification.new do |s| | |
| 6 6 | 
             
              s.name        = "dboard"
         | 
| 7 7 | 
             
              s.version     = Dboard::VERSION
         | 
| 8 8 | 
             
              s.platform    = Gem::Platform::RUBY
         | 
| 9 | 
            -
              s.authors     = ["Joakim Kolsjö"]
         | 
| 10 | 
            -
              s.email       = ["joakim.kolsjo@gmail.com"]
         | 
| 9 | 
            +
              s.authors     = [ "Joakim Kolsjö" ]
         | 
| 10 | 
            +
              s.email       = [ "joakim.kolsjo@gmail.com" ]
         | 
| 11 11 | 
             
              s.homepage    = ""
         | 
| 12 12 | 
             
              s.summary     = %q{Dashboard framework}
         | 
| 13 13 | 
             
              s.description = %q{Dashboard framework}
         | 
| 14 14 | 
             
              s.license     = "MIT"
         | 
| 15 | 
            +
              s.metadata    = { "rubygems_mfa_required" => "true" }
         | 
| 15 16 |  | 
| 16 17 | 
             
              s.files         = `git ls-files`.split("\n")
         | 
| 17 | 
            -
              s. | 
| 18 | 
            -
              s.executables   = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
         | 
| 19 | 
            -
              s.require_paths = ["lib"]
         | 
| 18 | 
            +
              s.require_paths = [ "lib" ]
         | 
| 20 19 |  | 
| 21 20 | 
             
              s.add_dependency "httparty"
         | 
| 22 21 | 
             
              s.add_dependency "rake"
         | 
| 23 22 | 
             
              s.add_dependency "json"
         | 
| 24 23 | 
             
              s.add_dependency "dalli"
         | 
| 25 24 | 
             
              s.add_dependency "sinatra"
         | 
| 26 | 
            -
              s.add_development_dependency "rspec", " | 
| 25 | 
            +
              s.add_development_dependency "rspec", "~> 3.9"
         | 
| 27 26 | 
             
            end
         | 
    
        data/lib/api.rb
    CHANGED
    
    | @@ -1,8 +1,8 @@ | |
| 1 | 
            -
            require File.expand_path(File.join(File.dirname(__FILE__),  | 
| 2 | 
            -
            require File.expand_path(File.join(File.dirname(__FILE__),  | 
| 3 | 
            -
            require  | 
| 4 | 
            -
            require  | 
| 5 | 
            -
            require  | 
| 1 | 
            +
            require File.expand_path(File.join(File.dirname(__FILE__), "cache"))
         | 
| 2 | 
            +
            require File.expand_path(File.join(File.dirname(__FILE__), "collector.rb"))
         | 
| 3 | 
            +
            require "digest/md5"
         | 
| 4 | 
            +
            require "json"
         | 
| 5 | 
            +
            require "httparty"
         | 
| 6 6 |  | 
| 7 7 | 
             
            module Dboard
         | 
| 8 8 | 
             
              class Api
         | 
| @@ -15,12 +15,12 @@ module Dboard | |
| 15 15 |  | 
| 16 16 | 
             
                def self.get(params)
         | 
| 17 17 | 
             
                  types = {}
         | 
| 18 | 
            -
                  params[:types].split( | 
| 18 | 
            +
                  params[:types].split(",").each do |type|
         | 
| 19 19 | 
             
                    raw_data = CACHE.get("dashboard::source::#{type}")
         | 
| 20 20 | 
             
                    data = raw_data ? JSON.parse(raw_data) : {}
         | 
| 21 | 
            -
                    types.merge!(type => { : | 
| 21 | 
            +
                    types.merge!(type => { data: data, checksum: Digest::MD5.hexdigest(data.inspect) })
         | 
| 22 22 | 
             
                  end
         | 
| 23 | 
            -
                  { : | 
| 23 | 
            +
                  { version: (@@version || ENV["COMMIT_HASH"] || "unversioned"), sources: types }.to_json
         | 
| 24 24 | 
             
                end
         | 
| 25 25 |  | 
| 26 26 | 
             
                def self.version=(version)
         | 
    
        data/lib/cache.rb
    CHANGED
    
    
    
        data/lib/collector.rb
    CHANGED
    
    
    
        data/lib/dboard.rb
    CHANGED
    
    | @@ -1,3 +1,3 @@ | |
| 1 | 
            -
            require File.expand_path(File.join(File.dirname(__FILE__),  | 
| 2 | 
            -
            require File.expand_path(File.join(File.dirname(__FILE__),  | 
| 3 | 
            -
            require File.expand_path(File.join(File.dirname(__FILE__),  | 
| 1 | 
            +
            require File.expand_path(File.join(File.dirname(__FILE__), "config.rb"))
         | 
| 2 | 
            +
            require File.expand_path(File.join(File.dirname(__FILE__), "api.rb"))
         | 
| 3 | 
            +
            require File.expand_path(File.join(File.dirname(__FILE__), "collector.rb"))
         | 
    
        data/lib/publisher.rb
    CHANGED
    
    | @@ -1,9 +1,9 @@ | |
| 1 | 
            -
            require  | 
| 1 | 
            +
            require "json"
         | 
| 2 2 |  | 
| 3 3 | 
             
            module Dboard
         | 
| 4 4 | 
             
              class Publisher
         | 
| 5 5 | 
             
                def self.publish(source, data)
         | 
| 6 | 
            -
                  Api::Client.post("/sources/#{source}", : | 
| 6 | 
            +
                  Api::Client.post("/sources/#{source}", body: { data: data.to_json }, timeout: 10000)
         | 
| 7 7 | 
             
                rescue SocketError => ex
         | 
| 8 8 | 
             
                  puts "SocketError: #{ex.message}"
         | 
| 9 9 | 
             
                end
         | 
    
        data/lib/version.rb
    CHANGED
    
    
    
        data/spec/collector_spec.rb
    CHANGED
    
    | @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            require File.expand_path(File.join(File.dirname(__FILE__),  | 
| 1 | 
            +
            require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe Dboard::Collector, "register_source" do
         | 
| 4 4 | 
             
              before do
         | 
| @@ -6,20 +6,20 @@ describe Dboard::Collector, "register_source" do | |
| 6 6 | 
             
              end
         | 
| 7 7 |  | 
| 8 8 | 
             
              it "can register a source" do
         | 
| 9 | 
            -
                new_relic =  | 
| 10 | 
            -
                new_relic. | 
| 9 | 
            +
                new_relic = double
         | 
| 10 | 
            +
                allow(new_relic).to receive(:update_interval).and_return(5)
         | 
| 11 11 | 
             
                Dboard::Collector.register_source :new_relic, new_relic
         | 
| 12 | 
            -
                Dboard::Collector.instance.sources. | 
| 12 | 
            +
                expect(Dboard::Collector.instance.sources).to eq({ new_relic: new_relic })
         | 
| 13 13 | 
             
              end
         | 
| 14 14 |  | 
| 15 15 | 
             
              it "can register an after update callback" do
         | 
| 16 | 
            -
                new_relic =  | 
| 17 | 
            -
                new_relic. | 
| 18 | 
            -
                callback =  | 
| 16 | 
            +
                new_relic = double
         | 
| 17 | 
            +
                allow(new_relic).to receive(:fetch).and_return({ db: "100%" })
         | 
| 18 | 
            +
                callback = double
         | 
| 19 19 | 
             
                Dboard::Collector.register_after_update_callback callback
         | 
| 20 20 |  | 
| 21 | 
            -
                callback. | 
| 22 | 
            -
                Dboard::Publisher. | 
| 21 | 
            +
                expect(callback).to receive(:call)
         | 
| 22 | 
            +
                allow(Dboard::Publisher).to receive(:publish)
         | 
| 23 23 | 
             
                Dboard::Collector.instance.update_source(:new_relic, new_relic)
         | 
| 24 24 |  | 
| 25 25 | 
             
                # since it is a singleton, and this callbacks leaks into the other tests
         | 
| @@ -27,14 +27,15 @@ describe Dboard::Collector, "register_source" do | |
| 27 27 | 
             
              end
         | 
| 28 28 |  | 
| 29 29 | 
             
              it "can register an error callback" do
         | 
| 30 | 
            -
                new_relic =  | 
| 30 | 
            +
                new_relic = double
         | 
| 31 31 | 
             
                error = RuntimeError.new("error")
         | 
| 32 | 
            -
                new_relic. | 
| 33 | 
            -
                callback =  | 
| 32 | 
            +
                allow(new_relic).to receive(:fetch).and_raise(error)
         | 
| 33 | 
            +
                callback = double
         | 
| 34 34 | 
             
                Dboard::Collector.register_error_callback callback
         | 
| 35 35 |  | 
| 36 | 
            -
                callback. | 
| 37 | 
            -
                Dboard::Publisher. | 
| 36 | 
            +
                expect(callback).to receive(:call).with(error)
         | 
| 37 | 
            +
                allow(Dboard::Publisher).to receive(:publish)
         | 
| 38 | 
            +
                allow_any_instance_of(Dboard::Collector).to receive(:puts)
         | 
| 38 39 | 
             
                Dboard::Collector.instance.update_source(:new_relic, new_relic)
         | 
| 39 40 |  | 
| 40 41 | 
             
                # since it is a singleton, and this callbacks leaks into the other tests
         | 
| @@ -48,16 +49,16 @@ describe Dboard::Collector, "update_source" do | |
| 48 49 | 
             
              end
         | 
| 49 50 |  | 
| 50 51 | 
             
              it "should collect and publish data from sources" do
         | 
| 51 | 
            -
                new_relic =  | 
| 52 | 
            -
                new_relic. | 
| 53 | 
            -
                Dboard::Publisher. | 
| 52 | 
            +
                new_relic = double
         | 
| 53 | 
            +
                allow(new_relic).to receive(:fetch).and_return({ db: "100%" })
         | 
| 54 | 
            +
                expect(Dboard::Publisher).to receive(:publish).with(:new_relic, { db: "100%" })
         | 
| 54 55 | 
             
                Dboard::Collector.instance.update_source(:new_relic, new_relic)
         | 
| 55 56 | 
             
              end
         | 
| 56 57 |  | 
| 57 58 | 
             
              it "should print out debugging info" do
         | 
| 58 | 
            -
                new_relic =  | 
| 59 | 
            -
                new_relic. | 
| 60 | 
            -
                Dboard::Collector.instance. | 
| 59 | 
            +
                new_relic = double
         | 
| 60 | 
            +
                allow(new_relic).to receive(:fetch).and_raise(Exception.new("some error"))
         | 
| 61 | 
            +
                expect(Dboard::Collector.instance).to receive(:puts).twice
         | 
| 61 62 | 
             
                Dboard::Collector.instance.update_source(:new_relic, new_relic)
         | 
| 62 63 | 
             
              end
         | 
| 63 64 | 
             
            end
         | 
    
        data/spec/publisher_spec.rb
    CHANGED
    
    | @@ -1,16 +1,14 @@ | |
| 1 | 
            -
            require File.expand_path(File.join(File.dirname(__FILE__),  | 
| 1 | 
            +
            require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe "Publisher", "publish" do
         | 
| 4 | 
            -
              
         | 
| 5 4 | 
             
              it "should send data to the dashboard server" do
         | 
| 6 | 
            -
                Dboard::Api::Client. | 
| 7 | 
            -
                Dboard::Publisher.publish(:new_relic, { : | 
| 5 | 
            +
                expect(Dboard::Api::Client).to receive(:post).with("/sources/new_relic", body: { data: { db: "80%" }.to_json }, timeout: 10000)
         | 
| 6 | 
            +
                Dboard::Publisher.publish(:new_relic, { db: "80%" })
         | 
| 8 7 | 
             
              end
         | 
| 9 8 |  | 
| 10 9 | 
             
              it "should handle and log socket errors" do
         | 
| 11 | 
            -
                Dboard::Api::Client. | 
| 12 | 
            -
                Dboard::Publisher. | 
| 10 | 
            +
                expect(Dboard::Api::Client).to receive(:post).and_raise(SocketError.new("failed to connect"))
         | 
| 11 | 
            +
                expect(Dboard::Publisher).to receive(:puts).with("SocketError: failed to connect")
         | 
| 13 12 | 
             
                Dboard::Publisher.publish(:new_relic, {})
         | 
| 14 13 | 
             
              end
         | 
| 15 | 
            -
             | 
| 16 14 | 
             
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -1,11 +1,11 @@ | |
| 1 1 | 
             
            require "rspec"
         | 
| 2 2 |  | 
| 3 | 
            -
            ENV["RACK_ENV"] ||=  | 
| 4 | 
            -
            ENV[ | 
| 5 | 
            -
            ENV[ | 
| 6 | 
            -
            ENV[ | 
| 3 | 
            +
            ENV["RACK_ENV"] ||= "test"
         | 
| 4 | 
            +
            ENV["API_URL"] = "http://localhost:20843"
         | 
| 5 | 
            +
            ENV["API_USER"] = "test"
         | 
| 6 | 
            +
            ENV["API_PASSWORD"] = "test"
         | 
| 7 7 |  | 
| 8 | 
            -
            require File.expand_path(File.join(File.dirname(__FILE__),  | 
| 8 | 
            +
            require File.expand_path(File.join(File.dirname(__FILE__), "../lib/dboard"))
         | 
| 9 9 |  | 
| 10 | 
            -
            Dboard::Api::Client.basic_auth(ENV[ | 
| 11 | 
            -
            Dboard::Api::Client.base_uri(ENV[ | 
| 10 | 
            +
            Dboard::Api::Client.basic_auth(ENV["API_USER"], ENV["API_PASSWORD"])
         | 
| 11 | 
            +
            Dboard::Api::Client.base_uri(ENV["API_URL"])
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: dboard
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.1. | 
| 4 | 
            +
              version: 1.1.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Joakim Kolsjö
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2021-11-19 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: httparty
         | 
| @@ -84,16 +84,16 @@ dependencies: | |
| 84 84 | 
             
              name: rspec
         | 
| 85 85 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 86 | 
             
                requirements:
         | 
| 87 | 
            -
                - -  | 
| 87 | 
            +
                - - "~>"
         | 
| 88 88 | 
             
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            -
                    version:  | 
| 89 | 
            +
                    version: '3.9'
         | 
| 90 90 | 
             
              type: :development
         | 
| 91 91 | 
             
              prerelease: false
         | 
| 92 92 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 93 | 
             
                requirements:
         | 
| 94 | 
            -
                - -  | 
| 94 | 
            +
                - - "~>"
         | 
| 95 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            -
                    version:  | 
| 96 | 
            +
                    version: '3.9'
         | 
| 97 97 | 
             
            description: Dashboard framework
         | 
| 98 98 | 
             
            email:
         | 
| 99 99 | 
             
            - joakim.kolsjo@gmail.com
         | 
| @@ -101,8 +101,9 @@ executables: [] | |
| 101 101 | 
             
            extensions: []
         | 
| 102 102 | 
             
            extra_rdoc_files: []
         | 
| 103 103 | 
             
            files:
         | 
| 104 | 
            +
            - ".github/workflows/ci.yml"
         | 
| 104 105 | 
             
            - ".gitignore"
         | 
| 105 | 
            -
            - ". | 
| 106 | 
            +
            - ".rubocop.yml"
         | 
| 106 107 | 
             
            - Gemfile
         | 
| 107 108 | 
             
            - LICENCE
         | 
| 108 109 | 
             
            - README.md
         | 
| @@ -116,13 +117,13 @@ files: | |
| 116 117 | 
             
            - lib/publisher.rb
         | 
| 117 118 | 
             
            - lib/version.rb
         | 
| 118 119 | 
             
            - spec/collector_spec.rb
         | 
| 119 | 
            -
            - spec/integration_spec.rb
         | 
| 120 120 | 
             
            - spec/publisher_spec.rb
         | 
| 121 121 | 
             
            - spec/spec_helper.rb
         | 
| 122 122 | 
             
            homepage: ''
         | 
| 123 123 | 
             
            licenses:
         | 
| 124 124 | 
             
            - MIT
         | 
| 125 | 
            -
            metadata: | 
| 125 | 
            +
            metadata:
         | 
| 126 | 
            +
              rubygems_mfa_required: 'true'
         | 
| 126 127 | 
             
            post_install_message: 
         | 
| 127 128 | 
             
            rdoc_options: []
         | 
| 128 129 | 
             
            require_paths:
         | 
| @@ -138,8 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 138 139 | 
             
                - !ruby/object:Gem::Version
         | 
| 139 140 | 
             
                  version: '0'
         | 
| 140 141 | 
             
            requirements: []
         | 
| 141 | 
            -
             | 
| 142 | 
            -
            rubygems_version: 2.2.1
         | 
| 142 | 
            +
            rubygems_version: 3.2.28
         | 
| 143 143 | 
             
            signing_key: 
         | 
| 144 144 | 
             
            specification_version: 4
         | 
| 145 145 | 
             
            summary: Dashboard framework
         | 
    
        data/.rvmrc
    DELETED
    
    | @@ -1 +0,0 @@ | |
| 1 | 
            -
            rvm ruby-2.1.0@dboard --create
         | 
    
        data/spec/integration_spec.rb
    DELETED
    
    | @@ -1,54 +0,0 @@ | |
| 1 | 
            -
            require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            # Test app
         | 
| 4 | 
            -
            require 'sinatra'
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            get "/sources" do
         | 
| 7 | 
            -
              Dboard::Api.get(params)
         | 
| 8 | 
            -
            end
         | 
| 9 | 
            -
             | 
| 10 | 
            -
            post "/sources/:type" do
         | 
| 11 | 
            -
              Dboard::Api.update(params)
         | 
| 12 | 
            -
            end
         | 
| 13 | 
            -
             | 
| 14 | 
            -
            describe "Dashboard" do
         | 
| 15 | 
            -
             | 
| 16 | 
            -
              def app
         | 
| 17 | 
            -
                Sinatra::Application
         | 
| 18 | 
            -
              end  
         | 
| 19 | 
            -
             | 
| 20 | 
            -
              def start_app
         | 
| 21 | 
            -
                app.port = 20843
         | 
| 22 | 
            -
                app.environment = 'test'
         | 
| 23 | 
            -
                @app_thread = Thread.new { app.run! }
         | 
| 24 | 
            -
                sleep 1
         | 
| 25 | 
            -
              end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
              def stop_app
         | 
| 28 | 
            -
                @app_thread && @app_thread.kill
         | 
| 29 | 
            -
              end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
              before do
         | 
| 32 | 
            -
                ENV['API_URL'] = "http://localhost:20843"
         | 
| 33 | 
            -
                ENV['API_USER'] = 'test'
         | 
| 34 | 
            -
                ENV['API_PASSWORD'] = 'test'
         | 
| 35 | 
            -
                @new_relic = mock
         | 
| 36 | 
            -
                @new_relic.stub!(:fetch).and_return({ :db => "33.3%", :memory => "33333 MB" })
         | 
| 37 | 
            -
                Dboard::CACHE.delete "dashboard::source::new_relic"
         | 
| 38 | 
            -
              end
         | 
| 39 | 
            -
              
         | 
| 40 | 
            -
              it "should collect stats and post them to the server" do
         | 
| 41 | 
            -
                start_app
         | 
| 42 | 
            -
                body = Dboard::Api::Client.get("/sources?types=new_relic")
         | 
| 43 | 
            -
                JSON.parse(body)["sources"]["new_relic"]["data"].should == {}
         | 
| 44 | 
            -
                Dboard::Collector.instance.update_source(:new_relic, @new_relic)
         | 
| 45 | 
            -
                body = Dboard::Api::Client.get("/sources?types=new_relic")
         | 
| 46 | 
            -
                JSON.parse(body)["sources"]["new_relic"]["data"].should == { "db" => "33.3%", "memory" => "33333 MB" }
         | 
| 47 | 
            -
              end
         | 
| 48 | 
            -
             | 
| 49 | 
            -
              after do
         | 
| 50 | 
            -
                stop_app
         | 
| 51 | 
            -
              end
         | 
| 52 | 
            -
             | 
| 53 | 
            -
            end
         | 
| 54 | 
            -
             |