-
Notifications
You must be signed in to change notification settings - Fork 1
/
api_test.rb
executable file
·61 lines (50 loc) · 1.92 KB
/
api_test.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
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'benchmark'
require 'bundler/setup'
require 'globus_client'
Benchmark.bm(20) do |benchmark| # rubocop:disable Metrics/BlockLength
user_id, path = *ARGV
benchmark.report('Configure:') do
GlobusClient.configure(
client_id: ENV.fetch('GLOBUS_CLIENT_ID', nil),
client_secret: ENV.fetch('GLOBUS_CLIENT_SECRET', nil),
uploads_directory: ENV.fetch('GLOBUS_UPLOADS_DIRECTORY', nil),
transfer_endpoint_id: ENV.fetch('GLOBUS_ENDPOINT', nil)
)
end
benchmark.report('mkdir:') do
GlobusClient.mkdir(user_id:, path:)
end
benchmark.report('user_valid?:') do
@user_exists = GlobusClient.user_valid?(user_id)
end
benchmark.report('before_perms:') do
# Not part of the public API but this allows us to test access changes
@before_permissions = GlobusClient::Endpoint.new(user_id:, path:).send(:access_rule)['permissions']
end
benchmark.report('has_files?:') do
@has_files = GlobusClient.has_files?(user_id:, path:)
end
benchmark.report('list_files:') do
GlobusClient.list_files(user_id:, path:) do |files|
@files_count = files.count
@total_size = files.sum(&:size)
@files_list = files.map(&:name)
end
end
benchmark.report('disallow_writes:') do
GlobusClient.disallow_writes(user_id:, path:)
end
benchmark.report('after_perms:') do
# Not part of the public API but this allows us to test access changes
@after_permissions = GlobusClient::Endpoint.new(user_id:, path:).send(:access_rule)['permissions']
end
puts "User #{user_id} exists: #{@user_exists}"
puts "Initial directory permissions: #{@before_permissions}"
puts "Directory has files? #{@has_files}"
puts "Number of files in directory: #{@files_count}"
puts "Total size of files in directory: #{@total_size}"
puts "List of files in directory: #{@files_list}"
puts "Final directory permissions: #{@after_permissions}"
end