Skip to content

Commit 6c2b118

Browse files
Merge branch 'chris.thuyen/test/pod_cache_validator' into 'master'
test(*): PodCacheValidator (p1) See merge request mobile/dax-ios/cocoapods-binary-cache!15
2 parents efe9b71 + 83b3cd4 commit 6c2b118

File tree

11 files changed

+122
-13
lines changed

11 files changed

+122
-13
lines changed

.bundle/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
BUNDLE_WITHOUT: "debug"

.rspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--require ./spec/spec_helper.rb
2+
--color
3+
--format documentation

.rubocop.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
inherit_from:
2+
- ~/rubocop/default.yml # Embedded inside Docker
3+
4+
AllCops:
5+
Exclude:
6+
- 'lib/cocoapods-binary-cache/pod-binary/**/*'
7+
- 'lib/cocoapods-binary-cache/pod-rome/**/*'

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ group :development do
1010
gem 'mocha-on-bacon'
1111
gem 'prettybacon'
1212
end
13+
14+
group :test do
15+
gem 'rspec'
16+
end

Gemfile.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ GEM
5959
cocoapods-try (1.1.0)
6060
colored2 (3.1.2)
6161
concurrent-ruby (1.1.5)
62+
diff-lcs (1.3)
6263
escape (0.0.4)
6364
fourflusher (2.3.1)
6465
fuzzy_match (2.0.4)
@@ -83,6 +84,19 @@ GEM
8384
lazy_priority_queue (~> 0.1.0)
8485
stream (~> 0.5.2)
8586
rouge (2.0.7)
87+
rspec (3.9.0)
88+
rspec-core (~> 3.9.0)
89+
rspec-expectations (~> 3.9.0)
90+
rspec-mocks (~> 3.9.0)
91+
rspec-core (3.9.1)
92+
rspec-support (~> 3.9.1)
93+
rspec-expectations (3.9.1)
94+
diff-lcs (>= 1.2.0, < 2.0)
95+
rspec-support (~> 3.9.0)
96+
rspec-mocks (3.9.1)
97+
diff-lcs (>= 1.2.0, < 2.0)
98+
rspec-support (~> 3.9.0)
99+
rspec-support (3.9.2)
86100
ruby-macho (1.4.0)
87101
stream (0.5.2)
88102
thread_safe (0.3.6)
@@ -109,6 +123,7 @@ DEPENDENCIES
109123
mocha-on-bacon
110124
prettybacon
111125
rake (~> 10.0)
126+
rspec
112127

113128
BUNDLED WITH
114129
1.17.3

lib/cocoapods-binary-cache/Main.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
require_relative 'pod-binary/prebuild_dsl'
66

77
# Hook cocoapods pre-install and post-install to do prebuild, caching stuffs
8-
require_relative 'pod-binary/prebuild_hook'
8+
require_relative 'pod-binary/prebuild_hook'

lib/cocoapods-binary-cache/main.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright 2019 Grabtaxi Holdings PTE LTE (GRAB), All rights reserved.
2+
# Use of this source code is governed by an MIT-style license that can be found in the LICENSE file
3+
4+
# Provide DSL options to set from Podfile
5+
require_relative 'pod-binary/prebuild_dsl'
6+
7+
# Hook cocoapods pre-install and post-install to do prebuild, caching stuffs
8+
require_relative 'pod-binary/prebuild_hook'

lib/cocoapods-binary-cache/prebuild_cache.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class PodCacheValidator
1212
def self.verify_devpod_checksum(sandbox, lock_file)
1313
devpod_path = "#{sandbox.root}/devpod/"
1414
target_path = sandbox.generate_framework_path
15-
puts "verify_devpod_checksum: #{devpod_path}"
15+
Pod::UI.puts "verify_devpod_checksum: #{devpod_path}"
1616
external_sources = lock_file.to_hash["EXTERNAL SOURCES"]
1717
unless File.directory?(target_path)
1818
FileUtils.mkdir_p(target_path)
@@ -21,7 +21,7 @@ def self.verify_devpod_checksum(sandbox, lock_file)
2121
dev_pods_count = 0
2222
cachehit_pods_dic = Hash[]
2323
if !external_sources
24-
puts 'No development pods!'
24+
Pod::UI.puts 'No development pods!'
2525
return missing_pods_dic, cachehit_pods
2626
end
2727
external_sources.each do |name, attribs|
@@ -33,7 +33,7 @@ def self.verify_devpod_checksum(sandbox, lock_file)
3333
cached_path = "#{devpod_path}#{name}_#{hash}"
3434
if !Dir.exists?(cached_path)
3535
missing_pods_dic[name] = hash
36-
puts "Missing devpod: #{name}_#{hash}"
36+
Pod::UI.puts "Missing devpod: #{name}_#{hash}"
3737
else
3838
cachehit_pods_dic[name] = hash
3939
target_dir = "#{target_path}/#{name}"
@@ -42,10 +42,10 @@ def self.verify_devpod_checksum(sandbox, lock_file)
4242
end
4343
end
4444
else
45-
puts "Error, wrong type: #{attribs}"
45+
Pod::UI.puts "Error, wrong type: #{attribs}"
4646
end
4747
end
48-
puts "Local pod cache miss: #{missing_pods_dic.keys.count} / #{dev_pods_count}"
48+
Pod::UI.puts "Local pod cache miss: #{missing_pods_dic.keys.count} / #{dev_pods_count}"
4949
return missing_pods_dic, cachehit_pods_dic
5050
end
5151

@@ -55,24 +55,24 @@ def self.verify_prebuilt_vendor_pods(pod_lockfile, pod_bin_lockfile)
5555
outdated_libs = Set.new()
5656
cachehit_libs = Set.new()
5757
if not pod_lockfile
58-
puts 'No pod lock file.'
58+
Pod::UI.puts 'No pod lock file.'
5959
return outdated_libs, cachehit_libs
6060
end
6161
pod_lock_libs = get_libs_dic(pod_lockfile)
6262
if not pod_bin_lockfile
63-
puts 'No pod binary lock file.'
63+
Pod::UI.puts 'No pod binary lock file.'
6464
return get_vendor_pods(pod_lockfile), cachehit_libs
6565
end
6666
pod_bin_libs = get_libs_dic(pod_bin_lockfile)
6767

68-
dev_pods = get_dev_pods(pod_lockfile)
68+
dev_pods = get_dev_pods(pod_lockfile) # TODO (thuyen): Review: Why dev_pods inside vendor_pods?
6969
pod_bin_libs.each do |name, prebuilt_ver|
7070
next if dev_pods.include?(name)
7171
lock_ver = pod_lock_libs[name]
7272
if lock_ver
7373
if lock_ver != prebuilt_ver
7474
outdated_libs.add(name)
75-
puts("Warning: prebuilt lib was outdated: #{name} #{prebuilt_ver} vs #{lock_ver}".yellow)
75+
Pod::UI.puts "Warning: prebuilt lib was outdated: #{name} #{prebuilt_ver} vs #{lock_ver}".yellow
7676
next
7777
end
7878
cachehit_libs.add(name)
@@ -85,7 +85,7 @@ def self.verify_prebuilt_vendor_pods(pod_lockfile, pod_bin_lockfile)
8585

8686
def self.get_dev_pods(lockfile)
8787
dev_pods = Set[]
88-
external_sources = lockfile.to_hash["EXTERNAL SOURCES"]
88+
external_sources = lockfile.to_hash['EXTERNAL SOURCES'] || []
8989
external_sources.each do |name, attribs|
9090
if attribs.class == Hash
9191
path = attribs[:path]
@@ -99,7 +99,7 @@ def self.get_dev_pods(lockfile)
9999

100100
def self.get_vendor_pods(lockfile)
101101
libs_dic = get_libs_dic(lockfile)
102-
dev_pods = get_dev_pods(lockfile)
102+
dev_pods = get_dev_pods(lockfile) # TODO (thuyen): Review: Why dev_pods inside vendor_pods?
103103
vendor_libs = Set.new()
104104
libs_dic.each do |name, _|
105105
next if dev_pods.include?(name)
@@ -118,7 +118,7 @@ def self.get_libs_dic(lockfile)
118118
pods = lockfile.to_hash["PODS"]
119119
libs_hash = {}
120120
if !pods
121-
puts "No pod libs"
121+
Pod::UI.puts 'No pod libs'
122122
return libs_hash
123123
end
124124
pods.each do |item|

spec/helper/lockfile.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def gen_lockfile(options = {})
2+
hash = {}
3+
if options[:pods].class == Hash
4+
hash['PODS'] = options[:pods].map { |k, v| "#{k} (#{v})" }
5+
hash['DEPENDENCIES'] = options[:pods].keys
6+
else
7+
hash['PODS'] = options[:pods] || []
8+
hash['DEPENDENCIES'] = options[:dependencies] || []
9+
end
10+
hash['EXTERNAL SOURCES'] = options[:external_sources] || {}
11+
hash['SPEC CHECKSUMS'] = options[:spec_checksums] || {}
12+
hash['COCOAPODS'] = options[:cocoapods] || '1.7.5'
13+
Pod::Lockfile.new(hash)
14+
end

spec/pod_cache_validator_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
describe 'PodCacheValidator' do
2+
describe 'verify prebuilt vendor pods' do
3+
let(:pods) { {'A' => '0.0.5', 'B' => '0.0.5', 'C' => '0.0.5'} }
4+
let(:pod_lockfile) { gen_lockfile(pods: pods) }
5+
let(:pod_bin_lockfile) { gen_lockfile(pods: pods) }
6+
before do
7+
@missed, @hit = PodCacheValidator.verify_prebuilt_vendor_pods(pod_lockfile, pod_bin_lockfile)
8+
end
9+
10+
context 'all cache hits' do
11+
it 'returns non missed, all hit' do
12+
expect(@missed).to be_empty
13+
expect(@hit).to eq(pods.keys.to_set)
14+
end
15+
end
16+
17+
context 'some cache miss due to outdated' do
18+
let(:pod_lockfile) { gen_lockfile(pods: pods.merge('A' => '0.0.1')) }
19+
it 'returns some missed, some hit' do
20+
expect(@missed).to eq(['A'].to_set)
21+
expect(@hit).to eq(pods.keys.to_set - ['A'])
22+
end
23+
end
24+
25+
context 'some cache miss due to not present' do
26+
let(:pod_lockfile) { gen_lockfile(pods: pods.merge('D' => '0.0.5')) }
27+
it 'returns some missed, some hit', :skip do
28+
skip 'code does not pass this test' # TODO (thuyen): Fix code
29+
30+
expect(@missed).to eq(['D'].to_set)
31+
expect(@hit).to eq(pods.keys.to_set)
32+
end
33+
end
34+
end
35+
end

0 commit comments

Comments
 (0)