-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move emulator commands to new module (#25)
* Move docker_exec to DockerCommander * Move emulator commands to new module * Add unit tests * add a comment * Add emulator commander tests * fix typo * Fix some PR comments * Fix tests to do not rely on DockerCommander * Refactor wait_for_healthy_container * refactor for exit 2 also in emulator unhealthy case
- Loading branch information
Showing
3 changed files
with
124 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require_relative 'docker_commander' | ||
|
||
module Fastlane | ||
module Helper | ||
module EmulatorCommander | ||
|
||
def self.disable_animations(container_name:) | ||
DockerCommander.docker_exec(command: 'adb shell settings put global window_animation_scale 0.0', container_name: container_name) | ||
DockerCommander.docker_exec(command: 'adb shell settings put global transition_animation_scale 0.0', container_name: container_name) | ||
DockerCommander.docker_exec(command: 'adb shell settings put global animator_duration_scale 0.0', container_name: container_name) | ||
end | ||
|
||
def self.increase_logcat_storage(container_name:) | ||
DockerCommander.docker_exec(command: 'adb logcat -G 16m', container_name: container_name) | ||
end | ||
|
||
# Checks if created emulator is connected | ||
def self.check_connection(container_name:) | ||
UI.success('Checking if emulator is connected to ADB.') | ||
|
||
if emulator_is_healthy?(container_name: container_name) | ||
UI.success('Emulator connected successfully') | ||
true | ||
else | ||
UI.important("Something went wrong. Newly created device couldn't connect to the adb") | ||
false | ||
end | ||
end | ||
|
||
def self.emulator_is_healthy?(container_name: container_name) | ||
list_devices = DockerCommander.docker_exec(command: 'adb devices', container_name: container_name) | ||
list_devices.include? "\tdevice" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require 'spec_helper' | ||
|
||
describe Fastlane::Helper::EmulatorCommander do | ||
|
||
describe '#disable_animations' do | ||
it 'disables emulator animation' do | ||
expect(Fastlane::Helper::DockerCommander).to receive(:docker_exec).with(command: "adb shell settings put global window_animation_scale 0.0", container_name:'a_name') | ||
expect(Fastlane::Helper::DockerCommander).to receive(:docker_exec).with(command: "adb shell settings put global transition_animation_scale 0.0", container_name:'a_name') | ||
expect(Fastlane::Helper::DockerCommander).to receive(:docker_exec).with(command: "adb shell settings put global animator_duration_scale 0.0", container_name:'a_name') | ||
|
||
described_class.disable_animations(container_name: 'a_name') | ||
end | ||
end | ||
|
||
describe '#increase_logcat_storage' do | ||
it 'increases_logcat_storage' do | ||
expect(Fastlane::Actions).to receive(:sh).with("docker exec -i a_name bash -l -c \"adb logcat -G 16m\"") | ||
described_class.increase_logcat_storage(container_name: 'a_name') | ||
end | ||
end | ||
|
||
describe '#emulator_is_healthy?' do | ||
it 'returns true if emulator is healthy' do | ||
expect(Fastlane::Actions).to receive(:sh).with("docker exec -i a_name bash -l -c \"adb devices\"").and_return("emulator_5554 \tdevice") | ||
expect(described_class.emulator_is_healthy?(container_name: 'a_name')).to be true | ||
end | ||
|
||
it 'returns false if emulator is unhealthy' do | ||
expect(Fastlane::Actions).to receive(:sh).with("docker exec -i a_name bash -l -c \"adb devices\"").and_return("emulator_5554 \tunauthorized") | ||
expect(described_class.emulator_is_healthy?(container_name: 'a_name')).to be false | ||
end | ||
end | ||
|
||
describe '#check_emulator_connection' do | ||
it 'returns false if simulator is unhealthy' do | ||
expect(Fastlane::Actions).to receive(:sh).with("docker exec -i some_name bash -l -c \"adb devices\"").and_return("emulator_5554 \tunauthorized") | ||
expect(described_class.check_connection(container_name: 'some_name')).to be false | ||
end | ||
|
||
it 'returns true if simulator is healthy' do | ||
expect(Fastlane::Actions).to receive(:sh).with("docker exec -i some_name bash -l -c \"adb devices\"").and_return("emulator_5554 \tdevice") | ||
expect(described_class.check_connection(container_name: 'some_name')).to be true | ||
end | ||
|
||
it 'prints a success message if simulator is healthy' do | ||
expect(Fastlane::Actions).to receive(:sh).with("docker exec -i some_name bash -l -c \"adb devices\"").and_return("emulator_5554 \tdevice") | ||
expect(Fastlane::UI).to receive(:success).with('Checking if emulator is connected to ADB.') | ||
expect(Fastlane::UI).to receive(:success).with('Emulator connected successfully') | ||
described_class.check_connection(container_name: 'some_name') | ||
end | ||
end | ||
end |