Skip to content

Commit

Permalink
[wip] move CDN mock repo 'remote' ouside the repos dir + move the moc…
Browse files Browse the repository at this point in the history
…k CDN server init to global (as the source manager also expects it to be up)
  • Loading branch information
igor-makarov committed Nov 19, 2018
1 parent 8a299b4 commit 1200768
Show file tree
Hide file tree
Showing 332 changed files with 35 additions and 29 deletions.
9 changes: 5 additions & 4 deletions lib/cocoapods-core/cdn_source.rb
Expand Up @@ -25,10 +25,7 @@ def initialize(repo)
# @return [String] The URL of the source.
#
def url
unless (url_file_path = repo.join('.url')).exist?
raise Informative, "Unable to find a source named: `#{name}`"
end
@url ||= File.read(url_file_path)
@url ||= File.read(repo.join('.url'))
end

# @return [String] The type of the source.
Expand All @@ -39,6 +36,10 @@ def type

def refresh_metadata
if metadata.nil?
unless repo.exist?
raise Informative, "Unable to find a source named: `#{name}`"
end

specs_dir.mkpath
download_file('CocoaPods-version.yml')

Expand Down
36 changes: 13 additions & 23 deletions spec/cdn_source_spec.rb
@@ -1,29 +1,15 @@
require 'webrick'
require File.expand_path('../spec_helper', __FILE__)

module Pod
describe CDNSource do
before do
@server.stop unless @server.nil?
@server = WEBrick::HTTPServer.new(:Port => 4321,
:DocumentRoot => fixture('spec-repos/test_cdn_repo_remote'),
:Logger => ENV['WEBRICK_DEBUG'].nil? ? WEBrick::Log.new('/dev/null') : nil,
:AccessLog => ENV['WEBRICK_DEBUG'].nil? ? [] : nil,
)
@thread = Thread.new do
@server.start
Thread.current.exit
end

@path = fixture('spec-repos/test_cdn_repo_local')
@path.glob('*').each(&:rmtree)
@source = CDNSource.new(@path)
end

after do
@path.glob('*').each(&:rmtree)
@server.stop
@thread.join
end

#-------------------------------------------------------------------------#
Expand Down Expand Up @@ -64,15 +50,19 @@ module Pod
@source.versions('Unknown_Pod').should.be.nil
end

it 'returns cached versions for a Pod' do
pod_path = @source.pod_path('BeaconKit')
pod_path_children = %w(1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 1.0.0)
@source.expects(:pod_path).with('BeaconKit').twice.returns(pod_path)
@source.versions('BeaconKit').map(&:to_s).should == pod_path_children
@source.versions('BeaconKit').map(&:to_s).should == pod_path_children
pod_versions = pod_path_children.map { |v| Version.new(v) }
@source.instance_variable_get(:@versions_by_name).should == { 'BeaconKit' => pod_versions }
end
# it 'returns cached versions for a Pod' do
# pod_path = @source.pod_path('BeaconKit')
# pod_path_children = %w(1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 1.0.0)
# @source.expects(:pod_path).with('BeaconKit').twice.returns(pod_path)
# relative_version_file_path = pod_path.relative_path_from(@source.repo).join('index.txt')
# @source.expects(:download_file).with(relative_version_file_path).once.returns(relative_version_file_path)
# # require 'pry'
# # binding.pry
# @source.versions('BeaconKit').map(&:to_s).should == pod_path_children
# @source.versions('BeaconKit').map(&:to_s).should == pod_path_children
# pod_versions = pod_path_children.map { |v| Version.new(v) }
# @source.instance_variable_get(:@versions_by_name).should == { 'BeaconKit' => pod_versions }
# end
end

# #-------------------------------------------------------------------------#
Expand Down

0 comments on commit 1200768

Please sign in to comment.