Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions google-cloud-storage/samples/acceptance/files_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ def mock_cipher.random_key

before(:each) do
bucket.create_file local_file, remote_file_name
bucket.create_file local_file, remote_file_name+"2"

set_object_contexts bucket_name: bucket.name, file_name: remote_file_name, custom_context_key: custom_context_key1, custom_context_value: custom_context_value1
set_object_contexts bucket_name: bucket.name, file_name: remote_file_name, custom_context_key: custom_context_key2, custom_context_value: custom_context_value2
Expand All @@ -345,29 +344,44 @@ def mock_cipher.random_key
end

describe "list_object_contexts" do
let(:custom_context_key1) { "my-custom-key" }
let(:custom_context_value1) { "my-custom-value" }
let(:custom_context_key2) { "my-custom-key-2" }
let(:custom_context_value2) { "my-custom-value-2" }
let(:custom_context_key1) { "my-custom-key-#{SecureRandom.hex(4)}" }
let(:custom_context_key2) { "my-custom-key2-#{SecureRandom.hex(4)}" }
let(:custom_context_value1) { "my-custom-value-#{SecureRandom.hex(4)}" }
let(:custom_context_value2) { "my-custom-value2-#{SecureRandom.hex(4)}" }
let(:remote_file_name2) { "path/file_name_#{SecureRandom.hex}.txt" }

before(:each) do
bucket.create_file local_file, remote_file_name
bucket.create_file local_file, remote_file_name+"2"
bucket.create_file local_file, remote_file_name2

set_object_contexts bucket_name: bucket.name, file_name: remote_file_name, custom_context_key: custom_context_key1, custom_context_value: custom_context_value1
set_object_contexts bucket_name: bucket.name, file_name: remote_file_name+"2", custom_context_key: custom_context_key2, custom_context_value: custom_context_value2
set_object_contexts bucket_name: bucket.name, file_name: remote_file_name2, custom_context_key: custom_context_key2, custom_context_value: custom_context_value2
end


it "filters out files on the basis of custom context key" do
assert_output "File: #{remote_file_name} has context key: #{custom_context_key1}\n" do
list_object_contexts bucket_name: bucket.name, custom_context_key: custom_context_key1
out = nil
10.times do
out, _err = capture_io do
list_object_contexts bucket_name: bucket.name, custom_context_key: custom_context_key1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are setting the same context key in other tests as well, if its possible that list can return those files then this test could still fail. It would be better to use keys with some random part to reliably run this test.

end
break unless out.empty?
sleep 0.2
end
assert_equal "File: #{remote_file_name} has context key: #{custom_context_key1}\n", out
end


it "filters out files on the basis of custom context key and value" do
assert_output "File: #{remote_file_name+"2"} has context key: #{custom_context_key2}\n" do
list_object_contexts bucket_name: bucket.name, custom_context_key: custom_context_key2, custom_context_value: custom_context_value2
out = nil
10.times do
out, _err = capture_io do
list_object_contexts bucket_name: bucket.name, custom_context_key: custom_context_key2, custom_context_value: custom_context_value2
end
break unless out.empty?
sleep 0.2
end
assert_equal "File: #{remote_file_name2} has context key: #{custom_context_key2}\n", out
end
end

Expand Down
Loading