Sha256: 7b21febb5bdb66ab8473130bef63dd6ee5652fd2ceca3553938850af1916d428

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'

describe MB::API::V1::ServerControlEndpoint do
  include Rack::Test::Methods

  before(:all) { MB::RestGateway.start(port: 26101) }
  after(:all) { MB::RestGateway.stop }
  after(:each) { MB::Application.resume }
  let(:app) { MB::RestGateway.instance.app }

  describe "PUT /pause" do
    it "pauses the server" do
      put '/pause'
      last_response.status.should == 200
      JSON.parse(last_response.body).should eq("server_status" => "paused")
    end

    it "prevents actions while the server is paused" do
      put '/pause'
      json_post "/environments/environmentname/upgrade",
        MultiJson.dump(plugin: { name: 'pluginname', version: '1.0.0' })
      last_response.status.should == 503
      JSON.parse(last_response.body).should eq("code"=>3330, "message"=>"MotherBrain is paused. It will not accept new requests until it is resumed.")
    end
  end

  describe "PUT /resume" do
    before do
      MB::Application.pause
    end
    
    it "resumes the server" do
      put '/resume'
      last_response.status.should == 200
      JSON.parse(last_response.body).should eq("server_status" => "running")
    end

    it "allows actions while the server is resumed" do
      put '/resume'
      json_post "/environments/environmentname/upgrade",
        MultiJson.dump(plugin: { name: 'pluginname', version: '1.0.0' })
      last_response.status.should == 201
    end
  end

  describe "PUT /stop" do
    it "stops the server" do
      MB::Application.instance.should_receive(:async_interrupt).with(3)
      put '/stop'
      last_response.status.should == 202
      JSON.parse(last_response.body).should eq("server_status" => "stopping")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
motherbrain-1.5.0 spec/unit/mb/api/v1/server_control_endpoint_spec.rb
motherbrain-1.4.0 spec/unit/mb/api/v1/server_control_endpoint_spec.rb