File: table_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 (99 lines) | stat: -rw-r--r-- 3,432 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
87
88
89
90
91
92
93
94
95
96
97
98
99
Shindo.tests('Fog::AWS[:dynamodb] | table requests', ['aws']) do

  @table_format = {
    'CreationDateTime'  => Float,
    'KeySchema'             => {
      'HashKeyElement' => {
        'AttributeName' => String,
        'AttributeType' => String
      }
    },
    'ProvisionedThroughput' => {
      'ReadCapacityUnits'   => Integer,
      'WriteCapacityUnits'  => Integer
    },
    'TableName'             => String,
    'TableStatus'           => String
  }

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

  tests('success') do

    tests("#create_table(#{@table_name}, {'HashKeyElement' => {'AttributeName' => 'id', 'AttributeType' => 'S'}, {'ReadCapacityUnits' => 5, 'WriteCapacityUnits' => 5})").formats('TableDescription' => @table_format) do
      pending if Fog.mocking?
      Fog::AWS[:dynamodb].create_table(@table_name, {'HashKeyElement' => {'AttributeName' => 'id', 'AttributeType' => 'S'}}, {'ReadCapacityUnits' => 5, 'WriteCapacityUnits' => 5}).body
    end

    tests("#describe_table(#{@table_name})").formats('Table' => @table_format) do
      pending if Fog.mocking?
      Fog::AWS[:dynamodb].describe_table(@table_name).body
    end

    tests("#list_tables").formats({'LastEvaluatedTableName' => Fog::Nullable::String, 'TableNames' => [String]}) do
      pending if Fog.mocking?
      Fog::AWS[:dynamodb].list_tables.body
    end

    unless Fog.mocking?
      Fog.wait_for { Fog::AWS[:dynamodb].describe_table(@table_name).body['Table']['TableStatus'] == 'ACTIVE' }
    end

    @update_table_format = {
      'TableDescription' => @table_format.merge({
        'ItemCount'             => Integer,
        'ProvisionedThroughput' => {
          'LastIncreaseDateTime'  => Float,
          'ReadCapacityUnits'     => Integer,
          'WriteCapacityUnits'    => Integer
        },
        'TableSizeBytes'        => Integer
      })
    }

    tests("#update_table(#{@table_name}, {'ReadCapacityUnits' => 10, 'WriteCapacityUnits' => 10})").formats(@update_table_format) do
      pending if Fog.mocking?
      Fog::AWS[:dynamodb].update_table(@table_name, {'ReadCapacityUnits' => 10, 'WriteCapacityUnits' => 10}).body
    end

    unless Fog.mocking?
      Fog.wait_for { Fog::AWS[:dynamodb].describe_table(@table_name).body['Table']['TableStatus'] == 'ACTIVE' }
    end

    @delete_table_format = {
      'TableDescription' => {
        'ProvisionedThroughput' => {
          'ReadCapacityUnits'   => Integer,
          'WriteCapacityUnits'  => Integer
        },
        'TableName'      => String,
        'TableStatus'    => String
      }
    }

    tests("#delete_table(#{@table_name}").formats(@delete_table_format) do
      pending if Fog.mocking?
      Fog::AWS[:dynamodb].delete_table(@table_name).body
    end

  end

  tests('failure') do

    tests("#delete_table('notatable')").raises(Excon::Errors::BadRequest) do
      pending if Fog.mocking?
      Fog::AWS[:dynamodb].delete_table('notatable')
    end

    tests("#describe_table('notatable')").raises(Excon::Errors::BadRequest) do
      pending if Fog.mocking?
      Fog::AWS[:dynamodb].describe_table('notatable')
    end

    tests("#update_table('notatable', {'ReadCapacityUnits' => 10, 'WriteCapacityUnits' => 10})").raises(Excon::Errors::BadRequest) do
      pending if Fog.mocking?
      Fog::AWS[:dynamodb].update_table('notatable', {'ReadCapacityUnits' => 10, 'WriteCapacityUnits' => 10}).body
    end

  end
end