-
Notifications
You must be signed in to change notification settings - Fork 135
优化代码,增加 Ruby4 CI #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
优化代码,增加 Ruby4 CI #245
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,41 +13,25 @@ def initialize(config) | |
| end | ||
|
|
||
| def up_host(bucket, opts = {}) | ||
| if !multi_region_support? | ||
| "#{extract_protocol(opts)}://up.qiniup.com" | ||
| elsif bucket | ||
| host = hosts(bucket) | ||
| "#{extract_protocol(opts)}://" + host.dig('up', 'acc', 'main', 0) rescue "#{extract_protocol(opts)}://" + host.dig('up', 'src', 'main', 0) | ||
| end | ||
| host = hosts(bucket) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| "#{extract_protocol(opts)}://" + host.dig('up', 'acc', 'main', 0) rescue "#{extract_protocol(opts)}://" + host.dig('up', 'src', 'main', 0) | ||
| end | ||
|
Comment on lines
15
to
18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 移除
def up_host(bucket, opts = {})
return nil if bucket.nil?
host = hosts(bucket)
up_host = host.dig('up', 'acc', 'main', 0) || host.dig('up', 'src', 'main', 0)
"#{extract_protocol(opts)}://#{up_host}" if up_host
end |
||
|
|
||
| def fetch_host(bucket, opts = {}) | ||
| if !multi_region_support? | ||
| "#{extract_protocol(opts)}://iovip.qbox.me" | ||
| elsif bucket | ||
| host = hosts(bucket) | ||
| "#{extract_protocol(opts)}://" + host.dig('io', 'acc', 'main', 0) rescue "#{extract_protocol(opts)}://" + host.dig('io', 'src', 'main', 0) | ||
| end | ||
| host = hosts(bucket) | ||
| "#{extract_protocol(opts)}://" + host.dig('io', 'acc', 'main', 0) rescue "#{extract_protocol(opts)}://" + host.dig('io', 'src', 'main', 0) | ||
| end | ||
|
Comment on lines
20
to
23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 与 def fetch_host(bucket, opts = {})
return nil if bucket.nil?
host = hosts(bucket)
fetch_host = host.dig('io', 'acc', 'main', 0) || host.dig('io', 'src', 'main', 0)
"#{extract_protocol(opts)}://#{fetch_host}" if fetch_host
end |
||
|
|
||
| def up_hosts(bucket, opts = {}) | ||
| if multi_region_support? | ||
| host = hosts(bucket)['up'] | ||
| multi_region_hosts = [] | ||
| multi_region_hosts |= host.dig('acc', 'main') || [] | ||
| multi_region_hosts |= host.dig('src', 'main') || [] | ||
| return multi_region_hosts | ||
| else | ||
| raise 'HostManager#up_hosts: multi_region must be enabled' | ||
| end | ||
| host = hosts(bucket)['up'] | ||
| up_hosts = [] | ||
| up_hosts |= host.dig('acc', 'main') || [] | ||
| up_hosts |= host.dig('src', 'main') || [] | ||
| up_hosts | ||
| end | ||
|
Comment on lines
25
to
31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果 def up_hosts(bucket, opts = {})
return [] if bucket.nil?
host = hosts(bucket)['up'] || {}
up_hosts = []
up_hosts |= host.dig('acc', 'main') || []
up_hosts |= host.dig('src', 'main') || []
up_hosts
end |
||
|
|
||
| def global(bucket, opts = {}) | ||
| if multi_region_support? | ||
| !!hosts(bucket)['global'] | ||
| else | ||
| raise 'HostManager#global: multi_region must be enabled' | ||
| end | ||
| !!hosts(bucket)['global'] | ||
| end | ||
|
Comment on lines
33
to
35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| private | ||
|
|
@@ -56,10 +40,6 @@ def extract_protocol(opts) | |
| (opts[:protocol] || @config[:protocol]).to_s | ||
| end | ||
|
|
||
| def multi_region_support? | ||
| @config[:multi_region] | ||
| end | ||
|
|
||
| def hosts(bucket) | ||
| host = read_host(bucket) | ||
| if host | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ module Auth | |
| describe Auth do | ||
|
|
||
| before :all do | ||
| @bucket = 'rubysdk' | ||
| @bucket = BUCKET | ||
| end | ||
| after :all do | ||
| end | ||
|
|
@@ -68,22 +68,21 @@ module Auth | |
| expect(code).to eq(200) | ||
| end | ||
|
|
||
| it "should generate uphosts and global for multi_region" do | ||
| origin_multi_region = Config.settings[:multi_region] | ||
| begin | ||
| Config.settings[:multi_region] = true | ||
| ### 生成Key | ||
| key = 'a_private_file' | ||
| key = make_unique_key_in_bucket(key) | ||
| puts "key=#{key}" | ||
|
|
||
| ### 生成 PutPolicy | ||
| pp = Auth::PutPolicy.new(@bucket, key) | ||
| expect(pp.instance_variable_get(:@uphosts)).to eq ["upload.qiniup.com", "up.qiniup.com"] | ||
| expect(pp.instance_variable_get(:@global)).to be false | ||
| ensure | ||
| Config.settings[:multi_region] = origin_multi_region | ||
| end | ||
| it "should generate uphosts and global" do | ||
| ### 生成Key | ||
| key = 'a_private_file' | ||
| key = make_unique_key_in_bucket(key) | ||
| puts "key=#{key}" | ||
|
|
||
| ### 生成 PutPolicy | ||
| pp = Auth::PutPolicy.new(@bucket, key) | ||
| expect(pp.instance_variable_get(:@global)).to be false | ||
| uphosts = pp.instance_variable_get(:@uphosts) | ||
| expect(uphosts.size).to eq 2 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion hard-codes the host list size to exactly 2 even though the API contract here is really “contains at least one |
||
| patterns = [/^upload-.*\.qiniup\.com$/, /^up-.*\.qiniup\.com$/] | ||
| expect(uphosts).to satisfy { |hosts| | ||
| patterns.all? { |pat| hosts.any? { |host| host.match?(pat) } } | ||
| } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ module Misc | |
| describe Misc do | ||
|
|
||
| before :all do | ||
| @bucket = 'rubysdk' | ||
| @bucket = BUCKET | ||
| end | ||
|
|
||
| after :all do | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR switches the test stack from
codecovtosimplecov-cobertura, but CI still runsbash <(curl -s https://codecov.io/bash). That means the workflow still depends on the deprecated Codecov uploader, and the newly generated Cobertura report is not actually consumed anywhere. If the intent is to stop relying on Codecov, this step needs to be updated or removed as part of the same change.