Sha256: c8b8ea762f49319b71370be8a37928229ec9e0a3d41fb96b79430ab98da76381

Contents?: true

Size: 1.77 KB

Versions: 43

Compression:

Stored size: 1.77 KB

Contents

require_relative "../../../../spec_helper"
require "kontena/cli/grid_options"
require "kontena/cli/services/secrets/link_command"

describe Kontena::Cli::Services::Secrets::LinkCommand do

  include ClientHelpers

  describe '#execute' do
    it 'requires api url' do
      expect(subject).to receive(:require_api_url).once
      subject.run(['service', 'secret:name:env'])
    end

    it 'requires token' do
      expect(subject).to receive(:require_token).and_return(token)
      subject.run(['service', 'secret:name:env'])
    end

    it 'requires service as param' do
      expect {
        subject.run([])
      }.to raise_error(Clamp::UsageError)
    end

    it 'requires secret as param' do
      expect {
        subject.run(['service'])
      }.to raise_error(Clamp::UsageError)
    end

    it 'sends secrets to master' do
      data = {
        secrets: [
          {secret: 'MY_PASSWORD', name: 'PASSWORD', type: 'env'}
        ]
      }
      allow(client).to receive(:get).with("services/test-grid/null/foo").and_return({
        'secrets' => []
      })
      expect(client).to receive(:put).with("services/test-grid/null/foo", data)
      subject.run(['foo', 'MY_PASSWORD:PASSWORD:env'])
    end

    it 'appends secret to existing list' do
      original = {
        'secrets' => [
          {'secret' => 'FOO', 'name' => 'BAR', 'type' => 'env'}
        ]
      }
      data = {
        secrets: [
          {'secret' => 'FOO', 'name' => 'BAR', 'type' => 'env'},
          {secret: 'MY_PASSWORD', name: 'PASSWORD', type: 'env'}
        ]
      }
      allow(client).to receive(:get).with("services/test-grid/null/foo").and_return(original)
      expect(client).to receive(:put).with("services/test-grid/null/foo", data)
      subject.run(['foo', 'MY_PASSWORD:PASSWORD:env'])
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
kontena-cli-1.1.6 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.1.5 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.1.5.rc3 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.1.5.rc2 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.1.5.rc1 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.1.4 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.1.3 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.1.2 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.1.2.rc2 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.1.2.rc1 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.1.1 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.1.1.rc1 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.1.0 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.1.0.rc2 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.1.0.rc1 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.1.0.pre1 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.0.6 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.0.6.rc1 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.0.5 spec/kontena/cli/services/secrets/link_command_spec.rb
kontena-cli-1.0.5.rc1 spec/kontena/cli/services/secrets/link_command_spec.rb