Sha256: a079cf4ba7d84438b9e1e9f9252763c9322ecc26d44fac1e36999028f2bf05cd

Contents?: true

Size: 1.5 KB

Versions: 69

Compression:

Stored size: 1.5 KB

Contents

require "kontena/cli/helpers/log_helper"

describe Kontena::Cli::Helpers::LogHelper do

  let(:described_class) do
    Class.new do
      include Kontena::Cli::Helpers::LogHelper

      def buffer
        @buffer
      end
    end
  end

  describe '#buffered_log_json' do
    it 'returns has on valid json' do
      chunk = {"foo" => "bar"}
      log = subject.buffered_log_json(chunk.to_json)
      expect(log).to eq(chunk)
    end

    it 'combines multi part json chunks to valid json' do
      chunk1 = '{"foo": "'
      chunk2 = 'bar'
      chunk3 = '"}'
      log = subject.buffered_log_json(chunk1)
      expect(log).to be_nil
      log = subject.buffered_log_json(chunk2)
      expect(log).to be_nil
      log = subject.buffered_log_json(chunk3)
      expect(log).to eq({"foo" => "bar"})
    end

    it 'handles big log messages' do
      chunk1 = '{"foo": "' << "lol" * 10000
      chunk2 = 'lol'
      chunk3 = 'lol"}'
      log = subject.buffered_log_json(chunk1)
      expect(log).to be_nil
      log = subject.buffered_log_json(chunk2)
      expect(log).to be_nil
      log = subject.buffered_log_json(chunk3)
      expect(log).to eq(JSON.parse(chunk1 + chunk2 + chunk3))
    end

    it 'does not append to buffer if buffer is empty and chunk has just whitespace' do
      log = subject.buffered_log_json(' ')
      expect(log).to be_nil
      expect(subject.buffer).to eq('')
    end

    it 'returns nil on invalid json' do
      log = subject.buffered_log_json('{"foo": "')
      expect(log).to be_nil
    end
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
kontena-cli-1.5.4 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.5.4.rc1 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.5.3 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.5.2 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.5.1 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.5.0 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.5.0.rc1 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.5.0.pre5 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.5.0.pre4 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.5.0.pre3 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.5.0.pre2 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.5.0.pre1 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.4.3 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.4.3.rc1 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.4.2 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.4.2.rc1 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.4.2.pre1 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.4.1 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.4.1.rc1 spec/kontena/cli/helpers/log_helper_spec.rb
kontena-cli-1.4.1.pre1 spec/kontena/cli/helpers/log_helper_spec.rb