Sha256: 472fb3cb462ecb0e2e0b34b47a560383e659e3f533be33344e1bb542b8001119

Contents?: true

Size: 1.99 KB

Versions: 17

Compression:

Stored size: 1.99 KB

Contents

require 'kontena/cli/nodes/remove_command'

describe Kontena::Cli::Nodes::RemoveCommand do
  include ClientHelpers
  include OutputHelpers

  context 'for an offline node without a node token' do
    let :node do
      {
        "id" => 'test-grid/node-1',
        "name" => 'node-1',
        "has_token" => false,
        "connected" => false,
      }
    end

    before do
      expect(client).to receive(:get).with('nodes/test-grid/node-1').and_return(node)
    end

    it 'removes the node' do
      expect(subject).to receive(:confirm_command).with('node-1')
      expect(client).to receive(:delete).with('nodes/test-grid/node-1')

      subject.run(['node-1'])
    end

    it 'removes the node with --force' do
      expect(client).to receive(:delete).with('nodes/test-grid/node-1')

      subject.run(['--force', 'node-1'])
    end
  end

  context 'for an online node without a node token' do
    let :node do
      {
        "id" => 'test-grid/node-1',
        "name" => 'node-1',
        "has_token" => false,
        "connected" => true,
      }
    end

    before do
      expect(client).to receive(:get).with('nodes/test-grid/node-1').and_return(node)
    end

    it 'does not remove the node' do
      expect(client).not_to receive(:delete)

      expect{subject.run(['node-1'])}.to output(" [error] Node node-1 is still online. You must terminate the node before removing it.\n").to_stderr
    end
  end

  context 'for an online node with a node token' do
    let :node do
      {
        "id" => 'test-grid/node-1',
        "name" => 'node-1',
        "has_token" => true,
        "connected" => true,
      }
    end

    before do
      expect(client).to receive(:get).with('nodes/test-grid/node-1').and_return(node)
    end

    it 'removes the node' do
      expect(client).to receive(:delete).with('nodes/test-grid/node-1')

      expect{subject.run(['--force', 'node-1'])}.to output(/\[warn\] Node node-1 is still connected using a node token, but will be force-disconnected/).to_stderr
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
kontena-cli-1.4.0 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.rc2 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.rc1 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.pre14 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.pre13 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.pre12 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.pre11 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.pre10 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.pre9 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.pre8 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.pre7 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.pre6 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.pre5 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.pre4 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.pre3 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.pre2 spec/kontena/cli/nodes/remove_command_spec.rb
kontena-cli-1.4.0.pre1 spec/kontena/cli/nodes/remove_command_spec.rb