Skip to content

Commit 515832d

Browse files
author
Rynaard Burger
committed
Rename and update spec
1 parent 805abfd commit 515832d

File tree

2 files changed

+87
-24
lines changed

2 files changed

+87
-24
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
require 'spec_helper'
2+
3+
describe Fastlane::Actions::AndroidGenerateApkFromAabAction do
4+
before do
5+
allow(File).to receive(:file?).with(aab_file_path).and_return('mocked file data')
6+
allow(File).to receive(:file?).with(apk_output_file_path).and_return('mocked file data')
7+
allow(File).to receive(:file?).with(keystore_path).and_return('mocked file data')
8+
end
9+
10+
let(:aab_file_path) { 'path/to/app.aab' }
11+
let(:apk_output_file_path) { 'path/to/app.apk' }
12+
let(:keystore_path) { 'path/to/keystore' }
13+
let(:keystore_password) { 'keystore_password' }
14+
let(:keystore_key_alias) { 'keystore_key_alias' }
15+
let(:signing_key_password) { 'signing_key_password' }
16+
17+
def generate_command(apk_output_file_path:, aab_file_path: nil, keystore_path: nil, keystore_password: nil, keystore_key_alias: nil, signing_key_password: nil)
18+
command = "bundletool build-apks --mode universal --bundle #{aab_file_path} --output-format DIRECTORY --output #{apk_output_file_path} "
19+
code_sign_arguments = "--ks #{keystore_path} --ks-pass #{keystore_password} --ks-key-alias #{keystore_key_alias} --key-pass #{signing_key_password} "
20+
move_and_cleanup_command = "&& mv #{apk_output_file_path}/universal.apk #{apk_output_file_path}_tmp && rm -rf #{apk_output_file_path} && mv #{apk_output_file_path}_tmp #{apk_output_file_path}"
21+
22+
# Append the code signing arguments
23+
command += code_sign_arguments unless keystore_path.nil?
24+
25+
# Append the move and cleanup command
26+
command += move_and_cleanup_command
27+
return command
28+
end
29+
30+
describe 'android_generate_apk_from_aab' do
31+
it 'calls the `bundletool` command with the correct arguments when generating a signed APK' do
32+
cmd = run_described_fastlane_action(
33+
aab_file_path: aab_file_path,
34+
apk_output_file_path: apk_output_file_path,
35+
keystore_path: keystore_path,
36+
keystore_password: keystore_password,
37+
keystore_key_alias: keystore_key_alias,
38+
signing_key_password: signing_key_password
39+
)
40+
expected_command = generate_command(aab_file_path: aab_file_path,
41+
apk_output_file_path: apk_output_file_path,
42+
keystore_path: keystore_path,
43+
keystore_password: keystore_password,
44+
keystore_key_alias: keystore_key_alias,
45+
signing_key_password: signing_key_password)
46+
expect(cmd).to eq(expected_command)
47+
end
48+
49+
it 'calls the `bundletool` command with the correct arguments when generating an unsigned APK' do
50+
cmd = run_described_fastlane_action(
51+
aab_file_path: aab_file_path,
52+
apk_output_file_path: apk_output_file_path
53+
)
54+
expected_command = generate_command(aab_file_path: aab_file_path,
55+
apk_output_file_path: apk_output_file_path)
56+
expect(cmd).to eq(expected_command)
57+
end
58+
59+
it 'calls the `bundletool` command with the correct arguments and use the path to the AAB from the lane context if the SharedValues::GRADLE_AAB_OUTPUT_PATH key is set' do
60+
aab_path_from_context = 'path/from/context/app.aab'
61+
62+
Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::GRADLE_AAB_OUTPUT_PATH] = aab_path_from_context
63+
64+
cmd = run_described_fastlane_action(
65+
apk_output_file_path: apk_output_file_path
66+
)
67+
68+
expected_command = generate_command(aab_file_path: aab_path_from_context,
69+
apk_output_file_path: apk_output_file_path)
70+
expect(cmd).to eq(expected_command)
71+
end
72+
73+
it 'calls the `bundletool` command with the correct arguments and use the path to the AAB from the lane context if the SharedValues::GRADLE_ALL_AAB_OUTPUT_PATHS key is set' do
74+
all_aab_paths_from_context = ['first/path/from/context/app.aab']
75+
76+
Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::GRADLE_ALL_AAB_OUTPUT_PATHS] = all_aab_paths_from_context
77+
78+
cmd = run_described_fastlane_action(
79+
apk_output_file_path: apk_output_file_path
80+
)
81+
82+
expected_command = generate_command(aab_file_path: all_aab_paths_from_context.first,
83+
apk_output_file_path: apk_output_file_path)
84+
expect(cmd).to eq(expected_command)
85+
end
86+
end
87+
end

spec/bundletool_generate_universal_signed_apk_spec.rb

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)