File: attributes_tests.rb

package info (click to toggle)
ruby-fog-aws 3.33.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,180 kB
  • sloc: ruby: 75,405; javascript: 14; makefile: 9; sh: 4
file content (86 lines) | stat: -rw-r--r-- 4,375 bytes parent folder | download | duplicates (8)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Shindo.tests('AWS::SimpleDB | attributes requests', ['aws']) do

  @domain_name = "fog_domain_#{Time.now.to_f.to_s.gsub('.','')}"

  Fog::AWS[:simpledb].create_domain(@domain_name)

  tests('success') do

    tests("#batch_put_attributes('#{@domain_name}', { 'a' => { 'b' => 'c', 'd' => 'e' }, 'x' => { 'y' => 'z' } }).body").formats(AWS::SimpleDB::Formats::BASIC) do
      Fog::AWS[:simpledb].batch_put_attributes(@domain_name, { 'a' => { 'b' => 'c', 'd' => 'e' }, 'x' => { 'y' => 'z' } }).body
    end

    tests("#get_attributes('#{@domain_name}', 'a', {'ConsistentRead' => true}).body['Attributes']").returns({'b' => ['c'], 'd' => ['e']}) do
      Fog::AWS[:simpledb].get_attributes(@domain_name, 'a', {'ConsistentRead' => true}).body['Attributes']
    end

    tests("#get_attributes('#{@domain_name}', 'AttributeName' => 'notanattribute')").succeeds do
      Fog::AWS[:simpledb].get_attributes(@domain_name, 'AttributeName' => 'notanattribute')
    end

    tests("#select('select * from #{@domain_name}', {'ConsistentRead' => true}).body['Items']").returns({'a' => { 'b' => ['c'], 'd' => ['e']}, 'x' => { 'y' => ['z'] } }) do
      pending if Fog.mocking?
      Fog::AWS[:simpledb].select("select * from #{@domain_name}", {'ConsistentRead' => true}).body['Items']
    end

    tests("#put_attributes('#{@domain_name}', 'conditional', { 'version' => '1' }).body").formats(AWS::SimpleDB::Formats::BASIC) do
      Fog::AWS[:simpledb].put_attributes(@domain_name, 'conditional', { 'version' => '1' }).body
    end

    tests("#put_attributes('#{@domain_name}', 'conditional', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version']).body").formats(AWS::SimpleDB::Formats::BASIC) do
      Fog::AWS[:simpledb].put_attributes(@domain_name, 'conditional', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version']).body
    end

    # Verify that we can delete individual attributes.
    tests("#delete_attributes('#{@domain_name}', 'a', {'d' => []})").succeeds do
      Fog::AWS[:simpledb].delete_attributes(@domain_name, 'a', {'d' => []}).body
    end

    # Verify that individually deleted attributes are actually removed.
    tests("#get_attributes('#{@domain_name}', 'a', {'AttributeName' => ['d'], 'ConsistentRead' => true}).body['Attributes']").returns({}) do
      Fog::AWS[:simpledb].get_attributes(@domain_name, 'a', {'AttributeName' => ['d'], 'ConsistentRead' => true}).body['Attributes']
    end

    tests("#delete_attributes('#{@domain_name}', 'a').body").formats(AWS::SimpleDB::Formats::BASIC) do
      Fog::AWS[:simpledb].delete_attributes(@domain_name, 'a').body
    end

    # Verify that we can delete entire domain, item combinations.
    tests("#delete_attributes('#{@domain_name}', 'a').body").succeeds do
      Fog::AWS[:simpledb].delete_attributes(@domain_name, 'a').body
    end

    # Verify that deleting a domain, item combination removes all related attributes.
    tests("#get_attributes('#{@domain_name}', 'a', {'ConsistentRead' => true}).body['Attributes']").returns({}) do
      Fog::AWS[:simpledb].get_attributes(@domain_name, 'a', {'ConsistentRead' => true}).body['Attributes']
    end

  end

  tests('failure') do

    tests("#batch_put_attributes('notadomain', { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } })").raises(Excon::Errors::BadRequest) do
      Fog::AWS[:simpledb].batch_put_attributes('notadomain', { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } })
    end

    tests("#get_attributes('notadomain', 'a')").raises(Excon::Errors::BadRequest) do
      Fog::AWS[:simpledb].get_attributes('notadomain', 'a')
    end

    tests("#put_attributes('notadomain', 'conditional', { 'version' => '1' })").raises(Excon::Errors::BadRequest) do
      Fog::AWS[:simpledb].put_attributes('notadomain', 'foo', { 'version' => '1' })
    end

    tests("#put_attributes('#{@domain_name}', 'conditional', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version'])").raises(Excon::Errors::Conflict) do
      Fog::AWS[:simpledb].put_attributes(@domain_name, 'conditional', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version'])
    end

    tests("#delete_attributes('notadomain', 'a')").raises(Excon::Errors::BadRequest) do
      Fog::AWS[:simpledb].delete_attributes('notadomain', 'a')
    end

  end

  Fog::AWS[:simpledb].delete_domain(@domain_name)

end