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
|
# File 'lib/api_test_gem.rb', line 1
def api_test(*args)
unless (args[0]!=nil && args[1]!=nil)
puts "richtiger Aufruf via: 'api_test [controller] [action]'"
else
route_yml=File.expand_path("#{Dir.pwd}/api_test_config.yml")
arg_con=args[0].split('/')
if File.exist?(route_yml)
parsed = begin
config=YAML.load(File.open("#{route_yml}"))
rescue ArgumentError => e
puts "Could not parse YAML: #{e.message}"
end
else
puts "please create 'api_test_config.yml'"
exit
end
[arg_con[0], arg_con[1], args[1]].each do |arg|
if arg!=nil
config=config[arg]
end
if config==nil
puts "argument '#{arg}' doesn't exist"
exit
end
end
route_sh=File.expand_path(File.join(File.dirname(__FILE__), '/api_test.sh'))
for_exec = "sh #{route_sh} #{config['method']} #{config['url']}"
params=config['param']
params_json=''
unless params==nil
params_json= JSON.generate(params)
end
for_exec<< " '#{params_json}'"
@result={:result=>`#{for_exec}`, :curl=>"#{for_exec}"}
result=@result[:result]
if result.include?("No route matches")
puts "#{args[0]} #{args[1]} no route for given parameter"
elsif result.include?("HTTP STATUS: 500") || result.include?("HTTP STATUS: 200")
puts "#{args[0]} #{args[1]} : ok"
else
puts "#{for_exec}: something is unclear, please check"
end
end
end
|