/
integration.rb
executable file
·69 lines (55 loc) · 1.77 KB
/
integration.rb
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
#! /usr/bin/env ruby
require 'e3db'
@config = E3DB::Config.default
@client = E3DB::Client.new(@config)
@record = { 'test' => 'Supercalifragilisticexpialidocious' }
def write(type)
record = @client.write(type, @record)
puts "Wrote #{record.meta.record_id} (#{record.meta.type})."
end
def read(*types)
did_read = {}
types = types[0].split(",")
@client.query(type: types).each do |record|
puts "Confirming #{record.meta.record_id} (#{record.meta.type})"
raise "(actual) #{record.data[:test]}, (expected) #{@record['test']}; (#{record.meta.type})" if @record['test'] != record.data[:test]
raise "(actual) #{record.meta.plain}, (expected) {}; (#{record.meta.type})" if record.meta.plain != {}
did_read[record.meta.type.to_s] = true
end
raise "Failed to read any records." unless did_read.length
raise "Did not read records for all types. (actual) #{did_read.keys}, (expected) #{types}" unless types.all? do |type|
did_read.has_key? type.to_s
end
end
def usage(err)
if err
puts err
puts ""
end
puts <<-USAGE
integration.rb <command>
Read, write and delete integration test records. This script uses
the default credentials found at ~/.tozny/e3db.json.
where <command> is one of:
read [type[, type, ...]]
Read records of the given type(s). Multiple types should be
provided in a comma separated list. An error will be raised if no
record exists for a given type.
write
Write a test record with the type 'ruby'.
USAGE
exit(1)
end
if $0 == __FILE__
usage("Please provide a command.") if ARGV.length == 0
case ARGV[0]
when "read"
usage("Please provide types to read.") if ARGV.length == 1
read(*ARGV.drop(1))
when "write"
write("ruby")
else
usage("Unrecognized command: #{ARGV[0]}")
end
exit(0)
end