File: to_array_of_json_strings_spec.rb

package info (click to toggle)
puppet-module-nova 25.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,100 kB
  • sloc: ruby: 11,433; python: 38; sh: 10; makefile: 10
file content (51 lines) | stat: -rw-r--r-- 1,588 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'spec_helper'

describe 'to_array_of_json_strings' do
  it 'exists' do
    is_expected.not_to eq(nil)
  end

  it 'fails with no arguments' do
    is_expected.to run.with_params.and_raise_error(Puppet::ParseError)
  end

  it 'fails with too many arguments' do
    is_expected.to run.with_params('arg1', 'arg2').and_raise_error(Puppet::ParseError)
  end

  it 'fails with invalid json string' do
    data = 'invalid json'
    is_expected.to run.with_params(data).and_raise_error(Puppet::ParseError)
  end

  it 'fails with array of json string' do
    data = ['{"valid": "json", "syntax": "here"}', '{"some": "data"}']
    is_expected.to run.with_params(data).and_raise_error(Puppet::ParseError)
  end

  it 'works with valid json string' do
    data = '{"valid": "json", "syntax": "here"}'
    retval = ['{"valid":"json","syntax":"here"}']
    is_expected.to run.with_params(data).and_return(retval)
  end

  it 'fails unless its an array or string' do
    is_expected.to run.with_params(1234).and_raise_error(Puppet::ParseError)
  end

  it 'fails unless array doesnt have hashes' do
    data = [12, 23]
    is_expected.to run.with_params(data).and_raise_error(Puppet::ParseError)
  end

  it 'fails if array but only some entries are valid' do
    data = [{:some => "entry"}, 23]
    is_expected.to run.with_params(data).and_raise_error(Puppet::ParseError)
  end

  it 'works with an array of hashes' do
    data = [{:some => "entry"}, {:with => "data"}]
    retval = ['{"some":"entry"}','{"with":"data"}']
    is_expected.to run.with_params(data).and_return(retval)
  end
end